Skip to content

About

CFFI bindings to the libghostty-vt calls a terminal needs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

cl-libghostty

CFFI bindings to the part of libghostty-vt Nyxt uses to emulate a terminal.

The bindings cover libghostty-vt 1.0. They are the calls that turn program output into a screen, and keystrokes and pastes into bytes for a pseudoterminal:

  • create a terminal, resize it, and write the bytes a program produced
  • install the callback that receives replies the terminal sends back to the pty
  • read the title the program set
  • update a render state and read dirty rows, cell text, colors, and style flags
  • encode a key event with the terminal’s current keyboard modes
  • decide whether pasted text is safe, and encode it

Install the libghostty-vt 1.0 shared library so the loader can find libghostty-vt.so.1. Building it requires Zig 0.17. See Installing. LIBGHOSTTY_VT may name the shared library when it is not on the default search path.

Load

(asdf:load-system :cl-libghostty)
(cl-libghostty:load-library)

Screen

(let ((terminal (cl-libghostty:terminal-new 80 24))
      (state (cl-libghostty:render-state-new)))
  (cl-libghostty:terminal-write terminal #(72 101 108 108 111 13 10))
  (cl-libghostty:render-state-update state terminal)
  (cl-libghostty:render-dirty state))

terminal-write takes a (vector (unsigned-byte 8)). A :full or :partial dirty state means some rows changed. Walk those with row-iterator-load and row-next-dirty, then read each cell with row-cells-load, cell-next, and cell-text.

Replies such as a device-status report are delivered to the function installed with terminal-set-write-pty. The bytes are valid only for that call.

Keys

Create one encoder and one event and reuse them. Call key-encoder-set-from-terminal after writing program output, because a program can change keyboard modes on any write. encode-key returns the bytes to write to the pty. An empty vector means the key produces no sequence.

Paste

paste-safe-p is the conservative check. paste-encode returns the bytes to write to the pty, with newlines handled and, when bracketed is true, bracketed-paste markers added.

About

CFFI bindings to the libghostty-vt calls a terminal needs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages