Skip to content

Commit 2ff7073

Browse files
authored
Merge pull request #42 from thaJeztah/fix_windows_conversion_again
windows: keyToString(): fix string conversion (for real)
2 parents 0564e01 + abe3d01 commit 2ff7073

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

windows/ansi_reader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12-
"strconv"
1312
"strings"
1413
"unsafe"
1514

@@ -196,10 +195,10 @@ func keyToString(keyEvent *winterm.KEY_EVENT_RECORD, escapeSequence []byte) stri
196195

197196
// <Alt>+Key generates ESC N Key
198197
if !control && alt {
199-
return ansiterm.KEY_ESC_N + strings.ToLower(strconv.Itoa(int(keyEvent.UnicodeChar)))
198+
return ansiterm.KEY_ESC_N + strings.ToLower(string(rune(keyEvent.UnicodeChar)))
200199
}
201200

202-
return strconv.Itoa(int(keyEvent.UnicodeChar))
201+
return string(rune(keyEvent.UnicodeChar))
203202
}
204203

205204
// formatVirtualKey converts a virtual key (e.g., up arrow) into the appropriate ANSI string.

windows/ansi_reader_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package windowsconsole
5+
6+
import (
7+
"testing"
8+
9+
"github.com/Azure/go-ansiterm"
10+
"github.com/Azure/go-ansiterm/winterm"
11+
)
12+
13+
func TestKeyToString(t *testing.T) {
14+
ke := &winterm.KEY_EVENT_RECORD{
15+
ControlKeyState: winterm.LEFT_ALT_PRESSED,
16+
UnicodeChar: 65, // capital A
17+
}
18+
19+
const expected = ansiterm.KEY_ESC_N + "a"
20+
out := keyToString(ke, nil)
21+
if out != expected {
22+
t.Errorf("expected %s, got %s", expected, out)
23+
}
24+
}

0 commit comments

Comments
 (0)