On this page:
with-kitty
with-kitty-nobuffer
with-kitty-nobuffer-echo
tui-init-kitty
tui-init-kitty-no-buffer
tui-init-kitty-no-buffer-echo
tui-exit-kitty
enable-kitty-keyboard!
disable-kitty-keyboard!
with-synchronized-output
format-kitty-keyboard-enable
format-kitty-keyboard-disable
format-kitty-keyboard-query
kitty-keyboard-flags-max

1 Entry and lifecycle🔗ℹ

(require tui/kitty)
 
(with-kitty
 (lambda ()
   (screen-clear)
   (define ev (read-event))
   ...))

procedure

(with-kitty thunk    
  [#:flags flags    
  #:strict? strict?    
  #:probe-graphics? probe-graphics?]) → any
  thunk : (-> any)
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f
Starts a kitty session, runs thunk, and tears the session down afterwards. Exceptions and multiple values behave exactly as in with-tui: cleanup runs through dynamic-wind, and an exception from thunk is re-raised after cleanup.

procedure

(with-kitty-nobuffer thunk    
  [#:flags flags    
  #:strict? strict?    
  #:probe-graphics? probe-graphics?]) → any
  thunk : (-> any)
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f
Like with-kitty, but stays on the main screen buffer (as tui-init-no-buffer).

procedure

(with-kitty-nobuffer-echo thunk 
  [#:flags flags 
  #:strict? strict? 
  #:probe-graphics? probe-graphics?]) 
 → any
  thunk : (-> any)
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f
Like with-kitty-nobuffer, but keeps terminal echo enabled.

procedure

(tui-init-kitty [#:flags flags    
  #:strict? strict?    
  #:probe-graphics? probe-graphics?]) → void?
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f
Manual entry point, symmetric with tui-init: probes the terminal, enters the base session, pushes the kitty keyboard flags with CSI > flags u, installs the kitty CSI parser, optionally probes kitty graphics, and records the state needed by tui-exit-kitty. Raises if a kitty session is already active. If initialization fails partway, the already-changed state is rolled back before the error is re-raised.

procedure

(tui-init-kitty-no-buffer [#:flags flags 
  #:strict? strict? 
  #:probe-graphics? probe-graphics?]) 
 → void?
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f

procedure

(tui-init-kitty-no-buffer-echo 
  [#:flags flags 
  #:strict? strict? 
  #:probe-graphics? probe-graphics?]) 
 → void?
  flags : exact-nonnegative-integer? = 1
  strict? : boolean? = #f
  probe-graphics? : boolean? = #f
Like tui-init-kitty, but without the alternate screen buffer (tui-init-no-buffer) or with echo enabled (tui-init-no-buffer-echo).

procedure

(tui-exit-kitty) → void?

Deletes the images created in the session (when the image cache is non-empty), pops the keyboard flags with CSI < u before the alternate screen is closed, then calls tui-exit. Finally it restores the previous CSI parser, key protocol, graphics parameters and image cache. Does nothing when no kitty session is active.

  • #:flags defaults to 1 (disambiguate) and must be in 0 to kitty-keyboard-flags-max; use 3 for press/repeat/release.

  • #:strict? defaults to #f: if the terminal does not answer the kitty keyboard probe, print a warning and fall back to ANSI. With #t, raise an error instead.

  • #:probe-graphics? defaults to #f. Enabling it sends the graphics and Unicode-placeholder APC queries.

procedure

(enable-kitty-keyboard! [#:flags flags]) → void?

  flags : exact-nonnegative-integer? = 1
Pushes the given flag set with CSI > flags u and flushes. The flags are stacked, so the matching disable-kitty-keyboard! pops one level.

procedure

(disable-kitty-keyboard!) → void?

Pops the keyboard flags pushed by enable-kitty-keyboard! with CSI < u and flushes.

procedure

(with-synchronized-output thunk) → any

  thunk : (-> any)
Runs thunk between DECSET 2026 / DECRST 2026 (synchronized updates) when features-sync? reports support; otherwise calls thunk directly.

procedure

(format-kitty-keyboard-enable flags) → bytes?

  flags : exact-nonnegative-integer?
Returns the push sequence CSI > flags u as bytes without writing them. Raises if flags is outside 0 to kitty-keyboard-flags-max.

The pop sequence CSI < u.

The flags query CSI ? u; the terminal replies with CSI ? flags u.

value

kitty-keyboard-flags-max : exact-positive-integer?

The largest accepted keyboard flag value (31). Bit 1 disambiguates escape codes, 2 reports event types, 4 reports alternate keys, 8 reports all keys as escape codes, and 16 reports associated text.