Skip to content

Commit

Permalink
diff kitten: Abort when run inside a terminal that does not support t…
Browse files Browse the repository at this point in the history
…he kitty keyboard protocol

Fixes #8185
  • Loading branch information
kovidgoyal committed Jan 3, 2025
1 parent fc463aa commit 134271b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Detailed list of changes

- ssh kitten: Fix kitten not being on PATH when SSHing into Debian systems (:iss:`7160`)

- diff kitten: Abort when run inside a terminal that does not support the kitty keyboard protocol (:iss:`8185`)

0.38.1 [2024-12-26]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
7 changes: 7 additions & 0 deletions kittens/diff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,16 @@ func main(_ *cli.Command, opts_ *Options, args []string) (rc int, err error) {
lp.SetCursorShape(loop.BAR_CURSOR, true)
lp.AllowLineWrapping(false)
lp.SetWindowTitle(fmt.Sprintf("%s vs. %s", left, right))
lp.QueryCapabilities()
h.initialize()
return "", nil
}
lp.OnCapabilitiesReceived = func(tc loop.TerminalCapabilities) error {
if !tc.KeyboardProtocol {
return fmt.Errorf("This terminal does not support the kitty keyboard protocol, or you are running inside a terminal multiplexer that is blocking querying for kitty keyboard protocol support. The diff kitten cannot function without it.")
}
return nil
}
lp.OnWakeup = h.on_wakeup
lp.OnFinalize = func() string {
lp.SetCursorVisible(true)
Expand Down
2 changes: 1 addition & 1 deletion tools/tui/loop/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Loop struct {
OnSIGTERM func() (bool, error)

// Called when capabilities response is received
OnCapabilitiesReceived func(TerminalCapabilities)
OnCapabilitiesReceived func(TerminalCapabilities) error
}

func New(options ...func(self *Loop)) (*Loop, error) {
Expand Down
4 changes: 3 additions & 1 deletion tools/tui/loop/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func (self *Loop) handle_csi(raw []byte) (err error) {
if strings.HasPrefix(csi, "?") && strings.HasSuffix(csi, "c") {
self.waiting_for_capabilities_response = false
if self.OnCapabilitiesReceived != nil {
self.OnCapabilitiesReceived(self.TerminalCapabilities)
if err = self.OnCapabilitiesReceived(self.TerminalCapabilities); err != nil {
return err
}
}
} else if strings.HasPrefix(csi, "?997;") && strings.HasSuffix(csi, "n") {
switch csi[len(csi)-2] {
Expand Down

0 comments on commit 134271b

Please sign in to comment.