diff --git a/setup.py b/setup.py index 1cb8125a5..3c9d98685 100755 --- a/setup.py +++ b/setup.py @@ -903,9 +903,9 @@ def build_kitty_tool(args: Options, launcher_dir: str, for_freeze: bool = False) if not go: raise SystemExit('The go tool was not found on this system. Install Go') update_go_generated_files(args, os.path.join(launcher_dir, appname)) - cmd = [go, 'build'] + cmd = [go, 'build', '-v'] if args.verbose: - cmd.append('-v') + cmd.append('-x') ld_flags = [f"-X 'kitty.VCSRevision={get_vcs_rev_define()}'"] if for_freeze: ld_flags.append("-X 'kitty.IsFrozenBuild=true") diff --git a/tools/tui/key-encoding.go b/tools/tui/key-encoding.go index 79a06d758..38f1bf188 100644 --- a/tools/tui/key-encoding.go +++ b/tools/tui/key-encoding.go @@ -1,6 +1,7 @@ package tui import ( + "fmt" "strconv" "strings" @@ -40,8 +41,50 @@ const ( NUM_LOCK KeyModifiers = 128 ) -func (self *KeyModifiers) WithoutLocks() KeyModifiers { - return *self & ^(CAPS_LOCK | NUM_LOCK) +func (self KeyModifiers) WithoutLocks() KeyModifiers { + return self & ^(CAPS_LOCK | NUM_LOCK) +} + +func (self KeyEventType) String() string { + switch self { + case PRESS: + return "PRESS" + case REPEAT: + return "REPEAT" + case RELEASE: + return "RELEASE" + default: + return fmt.Sprintf("KeyEventType:%d", int(self)) + } +} + +func (self *KeyModifiers) String() string { + ans := make([]string, 0) + if *self&SHIFT != 0 { + ans = append(ans, "shift") + } + if *self&ALT != 0 { + ans = append(ans, "alt") + } + if *self&CTRL != 0 { + ans = append(ans, "ctrl") + } + if *self&SUPER != 0 { + ans = append(ans, "super") + } + if *self&HYPER != 0 { + ans = append(ans, "hyper") + } + if *self&META != 0 { + ans = append(ans, "meta") + } + if *self&CAPS_LOCK != 0 { + ans = append(ans, "caps_lock") + } + if *self&NUM_LOCK != 0 { + ans = append(ans, "num_lock") + } + return strings.Join(ans, "+") } type KeyEvent struct { @@ -54,6 +97,24 @@ type KeyEvent struct { Handled bool } +func (self *KeyEvent) String() string { + key := self.Key + if self.Mods > 0 { + key = self.Mods.String() + "+" + key + } + ans := fmt.Sprint(self.Type, "{ ", key, " ") + if self.Text != "" { + ans += "Text: " + self.Text + " " + } + if self.ShiftedKey != "" { + ans += "ShiftedKey: " + self.ShiftedKey + " " + } + if self.AlternateKey != "" { + ans += "AlternateKey: " + self.AlternateKey + " " + } + return ans + "}" +} + func KeyEventFromCSI(csi string) *KeyEvent { if len(csi) == 0 { return nil @@ -86,7 +147,7 @@ func KeyEventFromCSI(csi string) *KeyEvent { if len(sections) > 2 { third_section = get_sub_sections(sections[2]) } - var ans KeyEvent + var ans = KeyEvent{Type: PRESS} keynum := first_section[0] if val, ok := letter_trailer_to_csi_number_map[last_char]; ok { keynum = val @@ -148,6 +209,14 @@ type ParsedShortcut struct { KeyName string } +func (self *ParsedShortcut) String() string { + ans := self.KeyName + if self.Mods > 0 { + ans = self.Mods.String() + "+" + ans + } + return ans +} + var parsed_shortcut_cache map[string]ParsedShortcut func ParseShortcut(spec string) *ParsedShortcut { diff --git a/tools/tui/loop.go b/tools/tui/loop.go index f7a930be5..92a027af7 100644 --- a/tools/tui/loop.go +++ b/tools/tui/loop.go @@ -46,8 +46,9 @@ type Loop struct { write_buf []byte // Callbacks - OnKeyEvent func(loop *Loop, event *KeyEvent) error - OnText func(loop *Loop, text string, from_key_event bool, in_bracketed_paste bool) error + OnInitialize func(loop *Loop) string + OnKeyEvent func(loop *Loop, event *KeyEvent) error + OnText func(loop *Loop, text string, from_key_event bool, in_bracketed_paste bool) error } func (self *Loop) handle_csi(raw []byte) error { @@ -60,6 +61,7 @@ func (self *Loop) handle_csi(raw []byte) error { } func (self *Loop) handle_key_event(ev *KeyEvent) error { + // self.controlling_term.DebugPrintln(ev) if self.OnKeyEvent != nil { err := self.OnKeyEvent(self, ev) if err != nil { @@ -163,11 +165,11 @@ func (self *Loop) DeathSignalName() string { func (self *Loop) KillIfSignalled() { switch self.death_signal { case SIGINT: - syscall.Kill(-1, syscall.SIGINT) + syscall.Kill(os.Getpid(), syscall.SIGINT) case SIGTERM: - syscall.Kill(-1, syscall.SIGTERM) + syscall.Kill(os.Getpid(), syscall.SIGTERM) case SIGHUP: - syscall.Kill(-1, syscall.SIGHUP) + syscall.Kill(os.Getpid(), syscall.SIGHUP) } } @@ -216,12 +218,19 @@ func (self *Loop) Run() (err error) { self.keep_going = true self.flush_write_buf = true self.queue_write_to_tty(self.terminal_options.SetStateEscapeCodes()) + finalizer := "" + if self.OnInitialize != nil { + finalizer = self.OnInitialize(self) + } defer func() { if self.flush_write_buf { self.flush() } - self.write_buf = self.write_buf[:] + self.write_buf = self.write_buf[:0] + if finalizer != "" { + self.queue_write_to_tty([]byte(finalizer)) + } self.queue_write_to_tty(self.terminal_options.ResetStateEscapeCodes()) self.flush() }() diff --git a/tools/tui/password.go b/tools/tui/password.go index 4d811da34..bd3f440fe 100644 --- a/tools/tui/password.go +++ b/tools/tui/password.go @@ -22,6 +22,8 @@ func ReadPassword(prompt string, kill_if_signaled bool) (password string, err er return } + 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) password += text