diff --git a/.gitattributes b/.gitattributes index 8d629b242..cd0c95cf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,7 +15,7 @@ kittens/diff/options/parse.py linguist-generated=true glfw/*.c linguist-vendored=true glfw/*.h linguist-vendored=true kittens/unicode_input/names.h linguist-generated=true -tools/tui/wcwidth-std.go linguist-generated=true +tools/wcswidth/std.go linguist-generated=true *.py text diff=python *.m text diff=objc diff --git a/count-lines-of-code b/count-lines-of-code index 55c69b3dd..e85c0b15f 100755 --- a/count-lines-of-code +++ b/count-lines-of-code @@ -21,7 +21,7 @@ kitty/options/parse.py kitty/options/to-c-generated.h kittens/diff/options/types.py kittens/diff/options/parse.py -tools/tui/wcwidth-std.go +tools/wcswidth/std.go ''' ignored = [] diff --git a/gen-wcwidth.py b/gen-wcwidth.py index 60c84c133..b0d9d7594 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -560,10 +560,10 @@ def gen_wcwidth() -> None: else: p('\treturn 1;\n}') - with create_header('kitty/wcwidth-std.h') as p, open('tools/tui/wcwidth-std.go', 'w') as gof: + with create_header('kitty/wcwidth-std.h') as p, open('tools/wcswidth/std.go', 'w') as gof: gop = partial(print, file=gof) - gop('package tui\n\n') - gop('func Wcwidth(code rune) int {') + gop('package wcswidth\n\n') + gop('func Runewidth(code rune) int {') p('static inline int\nwcwidth_std(int32_t code) {') p('\tif (LIKELY(0x20 <= code && code <= 0x7e)) { return 1; }') p('\tswitch(code) {') diff --git a/tools/cli/infrastructure.go b/tools/cli/infrastructure.go index ca4664e7b..532d70d16 100644 --- a/tools/cli/infrastructure.go +++ b/tools/cli/infrastructure.go @@ -16,8 +16,8 @@ import ( "kitty" "kitty/tools/tty" - "kitty/tools/tui" "kitty/tools/utils" + "kitty/tools/wcswidth" ) var RootCmd *cobra.Command @@ -120,7 +120,7 @@ func format_line_with_indent(output io.Writer, text string, indent string, scree var escapes strings.Builder print_word := func(r rune) { - w := tui.Wcswidth(current_word.String()) + w := wcswidth.Stringwidth(current_word.String()) if x+w > screen_width { fmt.Fprintln(output) fmt.Fprint(output, indent) diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index 7894d5e55..3406693d3 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -18,6 +18,7 @@ import ( "kitty/tools/cli" "kitty/tools/crypto" "kitty/tools/tty" + "kitty/tools/tui" "kitty/tools/utils" ) @@ -255,10 +256,9 @@ func get_password(password string, password_file string, password_env string, us if ans == "" && password_file != "" { if password_file == "-" { if tty.IsTerminal(os.Stdin.Fd()) { - var q string - q, err = tty.ReadPassword("Password: ") - if err == nil { - ans = string(q) + ans, err = tui.ReadPassword("Password: ", false) + if err != nil { + return } } else { var q []byte diff --git a/tools/tui/password.go b/tools/tui/password.go index bd3f440fe..719ee8aa5 100644 --- a/tools/tui/password.go +++ b/tools/tui/password.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "strings" + + "kitty/tools/wcswidth" ) type KilledBySignal struct { @@ -25,9 +27,9 @@ func ReadPassword(prompt string, kill_if_signaled bool) (password string, err er loop.OnInitialize = func(loop *Loop) string { return "\r\n" } loop.OnText = func(loop *Loop, text string, from_key_event bool, in_bracketed_paste bool) error { - old_width := Wcswidth(password) + old_width := wcswidth.Stringwidth(password) password += text - new_width := Wcswidth(password) + new_width := wcswidth.Stringwidth(password) if new_width > old_width { extra := strings.Repeat("*", new_width-old_width) loop.QueueWriteString(extra) @@ -40,9 +42,9 @@ func ReadPassword(prompt string, kill_if_signaled bool) (password string, err er if event.MatchesPressOrRepeat("backscape") || event.MatchesPressOrRepeat("delete") { event.Handled = true if len(password) > 0 { - old_width := Wcswidth(password) + old_width := wcswidth.Stringwidth(password) password = password[:len(password)-1] - new_width := Wcswidth(password) + new_width := wcswidth.Stringwidth(password) delta := new_width - old_width if delta > 0 { if delta > len(shadow) { diff --git a/tools/tui/wcwidth-std.go b/tools/wcswidth/std.go similarity index 99% rename from tools/tui/wcwidth-std.go rename to tools/wcswidth/std.go index df6e5b1c2..7900af11e 100644 --- a/tools/tui/wcwidth-std.go +++ b/tools/wcswidth/std.go @@ -1,6 +1,6 @@ -package tui +package wcswidth -func Wcwidth(code rune) int { +func Runewidth(code rune) int { switch code { // Flags (26 codepoints) {{{ case 0x1f1e6, 0x1f1e7, 0x1f1e8, 0x1f1e9, 0x1f1ea, 0x1f1eb, 0x1f1ec, 0x1f1ed, 0x1f1ee, 0x1f1ef, 0x1f1f0, 0x1f1f1, 0x1f1f2, 0x1f1f3, 0x1f1f4, 0x1f1f5, 0x1f1f6, 0x1f1f7, 0x1f1f8, 0x1f1f9, 0x1f1fa, 0x1f1fb, 0x1f1fc, 0x1f1fd, 0x1f1fe, 0x1f1ff: diff --git a/tools/tui/wcswidth.go b/tools/wcswidth/wcswidth.go similarity index 96% rename from tools/tui/wcswidth.go rename to tools/wcswidth/wcswidth.go index ee1e431d6..32c391e61 100644 --- a/tools/tui/wcswidth.go +++ b/tools/wcswidth/wcswidth.go @@ -1,4 +1,4 @@ -package tui +package wcswidth func IsFlagCodepoint(ch rune) bool { return 0x1F1E6 <= ch && ch <= 0x1F1FF @@ -71,7 +71,7 @@ func (self *WCWidthIterator) Step(ch rune) int { if IsFlagCodepoint(ch) { self.state = flag_pair_started } - w := Wcwidth(ch) + w := Runewidth(ch) switch w { case -1: case 0: @@ -102,7 +102,7 @@ func (self *WCWidthIterator) Step(ch rune) int { return ans } -func Wcswidth(text string) int { +func Stringwidth(text string) int { var w WCWidthIterator ans := 0 for _, ch := range []rune(text) { diff --git a/tools/tui/wcswidth_test.go b/tools/wcswidth/wcswidth_test.go similarity index 90% rename from tools/tui/wcswidth_test.go rename to tools/wcswidth/wcswidth_test.go index 187c67e3f..eccb488e5 100644 --- a/tools/tui/wcswidth_test.go +++ b/tools/wcswidth/wcswidth_test.go @@ -1,4 +1,4 @@ -package tui +package wcswidth import ( "testing" @@ -7,13 +7,13 @@ import ( func TestWCSWidth(t *testing.T) { wcswidth := func(text string, expected int) { - if w := Wcswidth(text); w != expected { + if w := Stringwidth(text); w != expected { t.Fatalf("The width for %#v was %d instead of %d", text, w, expected) } } wcwidth := func(text string, widths ...int) { for i, q := range []rune(text) { - if w := Wcwidth(q); w != widths[i] { + if w := Runewidth(q); w != widths[i] { t.Fatalf("The width of the char: U+%x was %d instead of %d", q, w, widths[i]) } }