Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: some emoji could not be gotten in WindowsTerminal 1.5 #42

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions tty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ var (
procScrollConsoleScreenBuffer = kernel32.NewProc("ScrollConsoleScreenBufferW")
)

const (
bitAltPressed = 1
bitNumPadPressed = 2
bitAltNumPadPressed = bitAltPressed | bitNumPadPressed
)

type wchar uint16
type short int16
type dword uint32
Expand Down Expand Up @@ -131,7 +137,7 @@ type TTY struct {
ws chan WINSIZE
sigwinchCtx context.Context
sigwinchCtxCancel context.CancelFunc
readNextKeyUp bool
withAltNumPad int
}

func readConsoleInput(fd uintptr, record *inputRecord) (err error) {
Expand Down Expand Up @@ -233,11 +239,9 @@ func (tty *TTY) readRune() (rune, error) {
case keyEvent:
kr := (*keyEventRecord)(unsafe.Pointer(&ir.event))
if kr.keyDown == 0 {
if kr.unicodeChar != 0 && tty.readNextKeyUp {
tty.readNextKeyUp = false
if 0x2000 <= kr.unicodeChar && kr.unicodeChar < 0x3000 {
return rune(kr.unicodeChar), nil
}
if kr.unicodeChar != 0 && tty.withAltNumPad == bitAltNumPadPressed {
tty.withAltNumPad = 0
return rune(kr.unicodeChar), nil
}
} else {
if kr.controlKeyState&altPressed != 0 && kr.unicodeChar > 0 {
Expand Down Expand Up @@ -289,7 +293,12 @@ func (tty *TTY) readRune() (rune, error) {
switch vk {
case 0x12: // menu
if kr.controlKeyState&leftAltPressed != 0 {
tty.readNextKeyUp = true
tty.withAltNumPad = bitAltPressed
}
return 0, nil
case 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69: // numpad
if kr.controlKeyState&leftAltPressed != 0 {
tty.withAltNumPad |= bitNumPadPressed
}
return 0, nil
case 0x21: // page-up
Expand Down