Skip to content

Commit

Permalink
Fix: maru-suji could not be input in WindowsTerminal 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Feb 17, 2021
1 parent ece7337 commit 0dcff23
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions internal/github.com/mattn/go-tty/tty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"os"
"syscall"
"unicode"
"unsafe"

"github.com/mattn/go-isatty"
Expand Down Expand Up @@ -131,7 +132,7 @@ type TTY struct {
ws chan WINSIZE
sigwinchCtx context.Context
sigwinchCtxCancel context.CancelFunc
readNextKeyUp bool
pressKey map[wchar]struct{}
}

func readConsoleInput(fd uintptr, record *inputRecord) (err error) {
Expand All @@ -145,6 +146,7 @@ func readConsoleInput(fd uintptr, record *inputRecord) (err error) {

func open(path string) (*TTY, error) {
tty := new(TTY)
tty.pressKey = make(map[wchar]struct{})
if false && isatty.IsTerminal(os.Stdin.Fd()) {
tty.in = os.Stdin
} else {
Expand Down Expand Up @@ -233,11 +235,17 @@ 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
return rune(kr.unicodeChar), nil
if kr.unicodeChar != 0 {
if _, ok := tty.pressKey[kr.unicodeChar]; ok {
delete(tty.pressKey, kr.unicodeChar)
} else if kr.unicodeChar > unicode.MaxASCII {
return rune(kr.unicodeChar), nil
}
}
} else {
if kr.unicodeChar != 0 {
tty.pressKey[kr.unicodeChar] = struct{}{}
}
if kr.controlKeyState&altPressed != 0 && kr.unicodeChar > 0 {
tty.rs = []rune{rune(kr.unicodeChar)}
return rune(0x1b), nil
Expand Down Expand Up @@ -285,11 +293,6 @@ func (tty *TTY) readRune() (rune, error) {
}
}
switch vk {
case 0x12: // menu
if kr.controlKeyState&leftAltPressed != 0 {
tty.readNextKeyUp = true
}
return 0, nil
case 0x21: // page-up
tty.rs = []rune{0x5b, 0x35, 0x7e}
return rune(0x1b), nil
Expand Down

0 comments on commit 0dcff23

Please sign in to comment.