func (term *WindowsTerminal) WriteChars(fd uintptr, w io.Writer, p []byte) (n int, err error) {
	if len(p) == 0 {
		return 0, nil
	}
	return w.Write(p)
}
WriteChars writes the bytes to given writer.
package winconsole
import (
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
	"sync"
	"syscall"
	"unsafe"
	"github.com/Sirupsen/logrus"
)
const (
	ENABLE_PROCESSED_INPUT = 0x0001
	ENABLE_LINE_INPUT      = 0x0002
	ENABLE_ECHO_INPUT      = 0x0004
	ENABLE_WINDOW_INPUT    = 0x0008
	ENABLE_MOUSE_INPUT     = 0x0010
	ENABLE_INSERT_MODE     = 0x0020
	ENABLE_QUICK_EDIT_MODE = 0x0040
	ENABLE_EXTENDED_FLAGS  = 0x0080
	ENABLE_PROCESSED_OUTPUT   = 0x0001
	ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
	FOREGROUND_BLUE       = 1
	FOREGROUND_GREEN      = 2
	FOREGROUND_RED        = 4
	FOREGROUND_INTENSITY  = 8
	FOREGROUND_MASK_SET   = 0x000F
	FOREGROUND_MASK_UNSET = 0xFFF0
	BACKGROUND_BLUE       = 16
	BACKGROUND_GREEN      = 32
	BACKGROUND_RED        = 64
	BACKGROUND_INTENSITY  = 128
	BACKGROUND_MASK_SET   = 0x00F0
	BACKGROUND_MASK_UNSET = 0xFF0F
	COMMON_LVB_REVERSE_VIDEO = 0x4000
	COMMON_LVB_UNDERSCORE    = 0x8000
	ANSI_ATTR_RESET     = 0
	ANSI_ATTR_BOLD      = 1
	ANSI_ATTR_DIM       = 2
	ANSI_ATTR_UNDERLINE = 4
	ANSI_ATTR_BLINK     = 5
	ANSI_ATTR_REVERSE   = 7
	ANSI_ATTR_INVISIBLE = 8
	ANSI_ATTR_UNDERLINE_OFF = 24
	ANSI_ATTR_BLINK_OFF     = 25
	ANSI_ATTR_REVERSE_OFF   = 27
	ANSI_ATTR_INVISIBLE_OFF = 8
	ANSI_FOREGROUND_BLACK   = 30
	ANSI_FOREGROUND_RED     = 31
	ANSI_FOREGROUND_GREEN   = 32
	ANSI_FOREGROUND_YELLOW  = 33
	ANSI_FOREGROUND_BLUE    = 34
	ANSI_FOREGROUND_MAGENTA = 35
	ANSI_FOREGROUND_CYAN    = 36
	ANSI_FOREGROUND_WHITE   = 37
	ANSI_FOREGROUND_DEFAULT = 39
	ANSI_BACKGROUND_BLACK   = 40
	ANSI_BACKGROUND_RED     = 41
	ANSI_BACKGROUND_GREEN   = 42
	ANSI_BACKGROUND_YELLOW  = 43
	ANSI_BACKGROUND_BLUE    = 44
	ANSI_BACKGROUND_MAGENTA = 45
	ANSI_BACKGROUND_CYAN    = 46
	ANSI_BACKGROUND_WHITE   = 47
	ANSI_BACKGROUND_DEFAULT = 49
	ANSI_MAX_CMD_LENGTH = 256
	MAX_INPUT_EVENTS = 128
	MAX_INPUT_BUFFER = 1024
	DEFAULT_WIDTH    = 80
	DEFAULT_HEIGHT   = 24
)
const (
	VK_PRIOR    = 0x21  
	VK_NEXT     = 0x22  
	VK_END      = 0x23  
	VK_HOME     = 0x24  
	VK_LEFT     = 0x25  
	VK_UP       = 0x26  
	VK_RIGHT    = 0x27  
	VK_DOWN     = 0x28  
	VK_SELECT   = 0x29  
	VK_PRINT    = 0x2A  
	VK_EXECUTE  = 0x2B  
	VK_SNAPSHOT = 0x2C  
	VK_INSERT   = 0x2D  
	VK_DELETE   = 0x2E  
	VK_HELP     = 0x2F  
	VK_F1       = 0x70  
	VK_F2       = 0x71  
	VK_F3       = 0x72  
	VK_F4       = 0x73  
	VK_F5       = 0x74  
	VK_F6       = 0x75  
	VK_F7       = 0x76  
	VK_F8       = 0x77  
	VK_F9       = 0x78  
	VK_F10      = 0x79  
	VK_F11      = 0x7A  
	VK_F12      = 0x7B  
)
var kernel32DLL = syscall.NewLazyDLL("kernel32.dll")
var (
	setConsoleModeProc                = kernel32DLL.NewProc("SetConsoleMode")
	getConsoleScreenBufferInfoProc    = kernel32DLL.NewProc("GetConsoleScreenBufferInfo")
	setConsoleCursorPositionProc      = kernel32DLL.NewProc("SetConsoleCursorPosition")
	setConsoleTextAttributeProc       = kernel32DLL.NewProc("SetConsoleTextAttribute")
	fillConsoleOutputCharacterProc    = kernel32DLL.NewProc("FillConsoleOutputCharacterW")
	writeConsoleOutputProc            = kernel32DLL.NewProc("WriteConsoleOutputW")
	readConsoleInputProc              = kernel32DLL.NewProc("ReadConsoleInputW")
	getNumberOfConsoleInputEventsProc = kernel32DLL.NewProc("GetNumberOfConsoleInputEvents")
	getConsoleCursorInfoProc          = kernel32DLL.NewProc("GetConsoleCursorInfo")
	setConsoleCursorInfoProc          = kernel32DLL.NewProc("SetConsoleCursorInfo")
	setConsoleWindowInfoProc          = kernel32DLL.NewProc("SetConsoleWindowInfo")
	setConsoleScreenBufferSizeProc    = kernel32DLL.NewProc("SetConsoleScreenBufferSize")
)
type (
	SHORT int16
	BOOL  int32
	WORD  uint16
	WCHAR uint16
	DWORD uint32
	SMALL_RECT struct {
		Left   SHORT
		Top    SHORT
		Right  SHORT
		Bottom SHORT
	}
	COORD struct {
		X SHORT
		Y SHORT
	}
	CONSOLE_SCREEN_BUFFER_INFO struct {
		Size              COORD
		CursorPosition    COORD
		Attributes        WORD
		Window            SMALL_RECT
		MaximumWindowSize COORD
	}
	CONSOLE_CURSOR_INFO struct {
		Size    DWORD
		Visible BOOL
	}
	KEY_EVENT_RECORD struct {
		KeyDown         BOOL
		RepeatCount     WORD
		VirtualKeyCode  WORD
		VirtualScanCode WORD
		UnicodeChar     WCHAR
		ControlKeyState DWORD
	}
	INPUT_RECORD struct {
		EventType WORD
		KeyEvent  KEY_EVENT_RECORD
	}
	CHAR_INFO struct {
		UnicodeChar WCHAR
		Attributes  WORD
	}
)
type WindowsTerminal struct {
	outMutex            sync.Mutex
	inMutex             sync.Mutex
	inputBuffer         []byte
	inputSize           int
	inputEvents         []INPUT_RECORD
	screenBufferInfo    *CONSOLE_SCREEN_BUFFER_INFO
	inputEscapeSequence []byte
}
func getStdHandle(stdhandle int) uintptr {
	handle, err := syscall.GetStdHandle(stdhandle)
	if err != nil {
		panic(fmt.Errorf("could not get standard io handle %d", stdhandle))
	}
	return uintptr(handle)
}
func WinConsoleStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
	handler := &WindowsTerminal{
		inputBuffer:         make([]byte, MAX_INPUT_BUFFER),
		inputEscapeSequence: []byte(KEY_ESC_CSI),
		inputEvents:         make([]INPUT_RECORD, MAX_INPUT_EVENTS),
	}
	if IsConsole(os.Stdin.Fd()) {
		stdIn = &terminalReader{
			wrappedReader: os.Stdin,
			emulator:      handler,
			command:       make([]byte, 0, ANSI_MAX_CMD_LENGTH),
			fd:            getStdHandle(syscall.STD_INPUT_HANDLE),
		}
	} else {
		stdIn = os.Stdin
	}
	if IsConsole(os.Stdout.Fd()) {
		stdoutHandle := getStdHandle(syscall.STD_OUTPUT_HANDLE)
		screenBufferInfo, err := GetConsoleScreenBufferInfo(stdoutHandle)
		if err != nil {
			panic("could not get console screen buffer info")
		}
		handler.screenBufferInfo = screenBufferInfo
		buffer = make([]CHAR_INFO, screenBufferInfo.MaximumWindowSize.X*screenBufferInfo.MaximumWindowSize.Y)
		stdOut = &terminalWriter{
			wrappedWriter: os.Stdout,
			emulator:      handler,
			command:       make([]byte, 0, ANSI_MAX_CMD_LENGTH),
			fd:            stdoutHandle,
		}
	} else {
		stdOut = os.Stdout
	}
	if IsConsole(os.Stderr.Fd()) {
		stdErr = &terminalWriter{
			wrappedWriter: os.Stderr,
			emulator:      handler,
			command:       make([]byte, 0, ANSI_MAX_CMD_LENGTH),
			fd:            getStdHandle(syscall.STD_ERROR_HANDLE),
		}
	} else {
		stdErr = os.Stderr
	}
	return stdIn, stdOut, stdErr
}
func GetHandleInfo(in interface{}) (uintptr, bool) {
	var inFd uintptr
	var isTerminalIn bool
	switch t := in.(type) {
	case *terminalReader:
		in = t.wrappedReader
	case *terminalWriter:
		in = t.wrappedWriter
	}
	if file, ok := in.(*os.File); ok {
		inFd = file.Fd()
		isTerminalIn = IsConsole(inFd)
	}
	return inFd, isTerminalIn
}
func getError(r1, r2 uintptr, lastErr error) error {
	if r1 == 0 {
		if lastErr != nil {
			return lastErr
		}
		return syscall.EINVAL
	}
	return nil
}
func GetConsoleMode(handle uintptr) (uint32, error) {
	var mode uint32
	err := syscall.GetConsoleMode(syscall.Handle(handle), &mode)
	return mode, err
}
func SetConsoleMode(handle uintptr, mode uint32) error {
	return getError(setConsoleModeProc.Call(handle, uintptr(mode), 0))
}
func SetCursorVisible(handle uintptr, isVisible BOOL) (bool, error) {
	var cursorInfo *CONSOLE_CURSOR_INFO = &CONSOLE_CURSOR_INFO{}
	if err := getError(getConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0)); err != nil {
		return false, err
	}
	cursorInfo.Visible = isVisible
	if err := getError(setConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0)); err != nil {
		return false, err
	}
	return true, nil
}
func SetWindowSize(handle uintptr, width, height, max SHORT) (bool, error) {
	window := SMALL_RECT{Left: 0, Top: 0, Right: width - 1, Bottom: height - 1}
	coord := COORD{X: width - 1, Y: max}
	if err := getError(setConsoleWindowInfoProc.Call(handle, uintptr(1), uintptr(unsafe.Pointer(&window)))); err != nil {
		return false, err
	}
	if err := getError(setConsoleScreenBufferSizeProc.Call(handle, marshal(coord))); err != nil {
		return false, err
	}
	return true, nil
}
func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) {
	var info CONSOLE_SCREEN_BUFFER_INFO
	if err := getError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)); err != nil {
		return nil, err
	}
	return &info, nil
}
func setConsoleTextAttribute(handle uintptr, attribute WORD) error {
	return getError(setConsoleTextAttributeProc.Call(handle, uintptr(attribute), 0))
}
func writeConsoleOutput(handle uintptr, buffer []CHAR_INFO, bufferSize COORD, bufferCoord COORD, writeRegion *SMALL_RECT) (bool, error) {
	if err := getError(writeConsoleOutputProc.Call(handle, uintptr(unsafe.Pointer(&buffer[0])), marshal(bufferSize), marshal(bufferCoord), uintptr(unsafe.Pointer(writeRegion)))); err != nil {
		return false, err
	}
	return true, nil
}
func fillConsoleOutputCharacter(handle uintptr, fillChar byte, length uint32, writeCord COORD) (bool, error) {
	out := int64(0)
	if err := getError(fillConsoleOutputCharacterProc.Call(handle, uintptr(fillChar), uintptr(length), marshal(writeCord), uintptr(unsafe.Pointer(&out)))); err != nil {
		return false, err
	}
	return true, nil
}
func getNumberOfChars(fromCoord COORD, toCoord COORD, screenSize COORD) uint32 {
	if fromCoord.X < 0 || fromCoord.Y < 0 || toCoord.X < 0 || toCoord.Y < 0 {
		return 0
	}
	if fromCoord.X >= screenSize.X || fromCoord.Y >= screenSize.Y || toCoord.X >= screenSize.X || toCoord.Y >= screenSize.Y {
		return 0
	}
	if fromCoord.Y > toCoord.Y {
		return 0
	}
	if fromCoord.Y == toCoord.Y {
		return uint32(toCoord.X-fromCoord.X) + 1
	}
	if fromCoord.Y < toCoord.Y {
		retValue := uint32(screenSize.X-fromCoord.X) + uint32(toCoord.X) + 1
		linesBetween := toCoord.Y - fromCoord.Y - 1
		if linesBetween > 0 {
			retValue = retValue + uint32(linesBetween*screenSize.X)
		}
		return retValue
	}
	return 0
}
var buffer []CHAR_INFO
func clearDisplayRect(handle uintptr, attributes WORD, fromCoord COORD, toCoord COORD) (uint32, error) {
	var writeRegion SMALL_RECT
	writeRegion.Left = fromCoord.X
	writeRegion.Top = fromCoord.Y
	writeRegion.Right = toCoord.X
	writeRegion.Bottom = toCoord.Y
	width := toCoord.X - fromCoord.X + 1
	height := toCoord.Y - fromCoord.Y + 1
	size := uint32(width) * uint32(height)
	if size > 0 {
		buffer := make([]CHAR_INFO, size)
		for i := range buffer {
			buffer[i] = CHAR_INFO{WCHAR(' '), attributes}
		}
		r, err := writeConsoleOutput(handle, buffer, COORD{X: width, Y: height}, COORD{X: 0, Y: 0}, &writeRegion)
		if !r {
			if err != nil {
				return 0, err
			}
			return 0, syscall.EINVAL
		}
	}
	return uint32(size), nil
}
func clearDisplayRange(handle uintptr, attributes WORD, fromCoord COORD, toCoord COORD) (uint32, error) {
	nw := uint32(0)
	if fromCoord.Y == toCoord.Y {
		return clearDisplayRect(handle, attributes, fromCoord, toCoord)
	}
	if fromCoord.Y < toCoord.Y {
		n, err := clearDisplayRect(handle, attributes, fromCoord, COORD{X: toCoord.X, Y: fromCoord.Y})
		if err != nil {
			return nw, err
		}
		nw += n
		linesBetween := toCoord.Y - fromCoord.Y - 1
		if linesBetween > 0 {
			n, err = clearDisplayRect(handle, attributes, COORD{X: 0, Y: fromCoord.Y + 1}, COORD{X: toCoord.X, Y: toCoord.Y - 1})
			if err != nil {
				return nw, err
			}
			nw += n
		}
		n, err = clearDisplayRect(handle, attributes, COORD{X: 0, Y: toCoord.Y}, toCoord)
		if err != nil {
			return nw, err
		}
		nw += n
	}
	return nw, nil
}
func setConsoleCursorPosition(handle uintptr, isRelative bool, column int16, line int16) error {
	screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
	if err != nil {
		return err
	}
	var position COORD
	if isRelative {
		position.X = screenBufferInfo.CursorPosition.X + SHORT(column)
		position.Y = screenBufferInfo.CursorPosition.Y + SHORT(line)
	} else {
		position.X = SHORT(column)
		position.Y = SHORT(line)
	}
	return getError(setConsoleCursorPositionProc.Call(handle, marshal(position), 0))
}
func getNumberOfConsoleInputEvents(handle uintptr) (uint16, error) {
	var n DWORD
	if err := getError(getNumberOfConsoleInputEventsProc.Call(handle, uintptr(unsafe.Pointer(&n)))); err != nil {
		return 0, err
	}
	return uint16(n), nil
}
func readConsoleInputKey(handle uintptr, inputBuffer []INPUT_RECORD) (int, error) {
	var nr DWORD
	if err := getError(readConsoleInputProc.Call(handle, uintptr(unsafe.Pointer(&inputBuffer[0])), uintptr(len(inputBuffer)), uintptr(unsafe.Pointer(&nr)))); err != nil {
		return 0, err
	}
	return int(nr), nil
}
func getWindowsTextAttributeForAnsiValue(originalFlag WORD, defaultValue WORD, ansiValue int16) (WORD, error) {
	flag := WORD(originalFlag)
	if flag == 0 {
		flag = defaultValue
	}
	switch ansiValue {
	case ANSI_ATTR_RESET:
		flag &^= COMMON_LVB_UNDERSCORE
		flag &^= BACKGROUND_INTENSITY
		flag = flag | FOREGROUND_INTENSITY
	case ANSI_ATTR_INVISIBLE:
	case ANSI_ATTR_UNDERLINE:
		flag = flag | COMMON_LVB_UNDERSCORE
	case ANSI_ATTR_BLINK:
		flag = flag | BACKGROUND_INTENSITY
	case ANSI_ATTR_UNDERLINE_OFF:
		flag &^= COMMON_LVB_UNDERSCORE
	case ANSI_ATTR_BLINK_OFF:
		flag &^= BACKGROUND_INTENSITY
	case ANSI_ATTR_BOLD:
		flag = flag | FOREGROUND_INTENSITY
	case ANSI_ATTR_DIM:
		flag &^= FOREGROUND_INTENSITY
	case ANSI_ATTR_REVERSE, ANSI_ATTR_REVERSE_OFF:
		foreground := flag & FOREGROUND_MASK_SET
		background := flag & BACKGROUND_MASK_SET
		flag = (flag & BACKGROUND_MASK_UNSET & FOREGROUND_MASK_UNSET) | (foreground << 4) | (background >> 4)
	case ANSI_FOREGROUND_DEFAULT:
		flag = (flag & FOREGROUND_MASK_UNSET) | (defaultValue & FOREGROUND_MASK_SET)
	case ANSI_FOREGROUND_BLACK:
		flag = flag ^ (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
	case ANSI_FOREGROUND_RED:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED
	case ANSI_FOREGROUND_GREEN:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_GREEN
	case ANSI_FOREGROUND_YELLOW:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_GREEN
	case ANSI_FOREGROUND_BLUE:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_BLUE
	case ANSI_FOREGROUND_MAGENTA:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_BLUE
	case ANSI_FOREGROUND_CYAN:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_GREEN | FOREGROUND_BLUE
	case ANSI_FOREGROUND_WHITE:
		flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
	case ANSI_BACKGROUND_DEFAULT:
		flag = (flag & BACKGROUND_MASK_UNSET) | (defaultValue & BACKGROUND_MASK_SET)
	case ANSI_BACKGROUND_BLACK:
		flag = (flag & BACKGROUND_MASK_UNSET)
	case ANSI_BACKGROUND_RED:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED
	case ANSI_BACKGROUND_GREEN:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_GREEN
	case ANSI_BACKGROUND_YELLOW:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_GREEN
	case ANSI_BACKGROUND_BLUE:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_BLUE
	case ANSI_BACKGROUND_MAGENTA:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_BLUE
	case ANSI_BACKGROUND_CYAN:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_GREEN | BACKGROUND_BLUE
	case ANSI_BACKGROUND_WHITE:
		flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
	}
	return flag, nil
}
func (term *WindowsTerminal) HandleOutputCommand(handle uintptr, command []byte) (n int, err error) {
	n = len(command)
	parsedCommand := parseAnsiCommand(command)
	logrus.Debugf("[windows] HandleOutputCommand: %v", parsedCommand)
	term.outMutex.Lock()
	defer term.outMutex.Unlock()
	switch parsedCommand.Command {
	case "m":
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		flag := screenBufferInfo.Attributes
		for _, e := range parsedCommand.Parameters {
			value, _ := strconv.ParseInt(e, 10, 16)  
			if value == ANSI_ATTR_RESET {
				flag = term.screenBufferInfo.Attributes  
			} else {
				flag, err = getWindowsTextAttributeForAnsiValue(flag, term.screenBufferInfo.Attributes, int16(value))
				if err != nil {
					return n, err
				}
			}
		}
		if err := setConsoleTextAttribute(handle, flag); err != nil {
			return n, err
		}
	case "H", "f":
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		line, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if line > int16(screenBufferInfo.Window.Bottom) {
			line = int16(screenBufferInfo.Window.Bottom) + 1
		}
		column, err := parseInt16OrDefault(parsedCommand.getParam(1), 1)
		if err != nil {
			return n, err
		}
		if column > int16(screenBufferInfo.Window.Right) {
			column = int16(screenBufferInfo.Window.Right) + 1
		}
		logrus.Debugf("[windows] HandleOutputCommmand: Moving cursor to (%v,%v)", column-1, line-1)
		if err := setConsoleCursorPosition(handle, false, column-1, line-1); err != nil {
			return n, err
		}
	case "A":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return len(command), err
		}
		if err := setConsoleCursorPosition(handle, true, 0, -value); err != nil {
			return n, err
		}
	case "B":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, 0, value); err != nil {
			return n, err
		}
	case "C":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, value, 0); err != nil {
			return n, err
		}
	case "D":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, -value, 0); err != nil {
			return n, err
		}
	case "J":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
		if err != nil {
			return n, err
		}
		var start COORD
		var cursor COORD
		var end COORD
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		switch value {
		case 0:
			start = screenBufferInfo.CursorPosition
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.Size.Y - 1
			cursor = screenBufferInfo.CursorPosition
		case 1:
			start.X = 0
			start.Y = 0
			end = screenBufferInfo.CursorPosition
			cursor = screenBufferInfo.CursorPosition
		case 2:
			start.X = 0
			start.Y = 0
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.Size.Y - 1
			cursor.X = 0
			cursor.Y = 0
		}
		if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, false, int16(cursor.X), int16(cursor.Y)); err != nil {
			return n, err
		}
	case "K":
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
		var start COORD
		var cursor COORD
		var end COORD
		screenBufferInfo, err := GetConsoleScreenBufferInfo(uintptr(handle))
		if err != nil {
			return n, err
		}
		switch value {
		case 0:
			start = screenBufferInfo.CursorPosition
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.CursorPosition.Y
			cursor = screenBufferInfo.CursorPosition
		case 1:
			start.X = 0
			start.Y = screenBufferInfo.CursorPosition.Y
			end = screenBufferInfo.CursorPosition
			cursor = screenBufferInfo.CursorPosition
		case 2:
			start.X = 0
			start.Y = screenBufferInfo.CursorPosition.Y - 1
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.CursorPosition.Y - 1
			cursor.X = 0
			cursor.Y = screenBufferInfo.CursorPosition.Y - 1
		}
		if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(uintptr(handle), false, int16(cursor.X), int16(cursor.Y)); err != nil {
			return n, err
		}
	case "l":
		for _, value := range parsedCommand.Parameters {
			switch value {
			case "?25", "25":
				SetCursorVisible(uintptr(handle), BOOL(0))
			case "?1049", "1049":
			case "?1", "1":
				term.inputEscapeSequence = []byte(KEY_ESC_CSI)
			}
		}
	case "h":
		for _, value := range parsedCommand.Parameters {
			switch value {
			case "?25", "25":
				SetCursorVisible(uintptr(handle), BOOL(1))
			case "?1049", "1049":
			case "?1", "1":
				term.inputEscapeSequence = []byte(KEY_ESC_O)
			}
		}
	case "]":
	}
	return n, nil
}