NAME Term::Ghostty - Headless terminal emulator built on Ghostty's libghostty-vt SYNOPSIS use Term::Ghostty; my $term = Term::Ghostty->new( cols => 80, rows => 24, on_pty_write => sub { my ($term, $bytes) = @_; syswrite $pty, $bytes; # answers to terminal queries }, on_title_changed => sub { my ($term, $title) = @_; print "title: $title\n"; }, ); $term->feed($bytes_read_from_a_pty); $term->feed("Hello \e[31mGhostty\e[0m!\r\n"); my $text = $term->get_text; # visible screen my $all = $term->get_text(scrollback => 1); # with history my $vt = $term->get_vt(cursor => 1, style => 1); my $html = $term->get_html; my ($col, $row) = $term->cursor_pos; my $fullscreen = $term->active_screen eq 'alternate'; $term->resize(100, 30); DESCRIPTION Term::Ghostty feeds a byte stream through the terminal emulation core of the Ghostty terminal, "libghostty-vt", and lets you read back the resulting screen: its text, cursor and modes, or the screen re-encoded as plain text, VT sequences or HTML. There is no display; use it to drive or test programs running in a pseudo-terminal, to scrape their output, or to render captured terminal output. The library comes from Alien::ghostty. When that module builds it, which is the default, it is linked statically. CONSTRUCTOR new my $term = Term::Ghostty->new(%options); Options: cols, rows Size in cells, 1 to 65535. Default 80 x 24. cell_width_px, cell_height_px Size of one cell in pixels, used only to answer pixel-size queries ("CSI 14 t") and in-band resize reports (mode 2048). Default 0. max_scrollback Roughly how many rows of history to keep. The library keeps and frees history in whole pages of a few hundred rows, so the number kept can be off by a page either way, and rows are counted at the current width. 0 disables the scrollback; undef keeps the default of about one page. Setting it also lifts the library's default memory cap, so memory use grows with the content. title, pwd Initial window title and working directory. on_pty_write, on_title_changed, on_bell, on_pwd_changed Callbacks, see "CALLBACKS". It croaks on an unknown option, an odd number of arguments, an out-of-range size, or a callback that is not a code reference. METHODS feed $term->feed($data); Runs $data through the VT parser. A byte string is processed as raw bytes, which is what you read from a pseudo-terminal; a character string (one with the UTF-8 flag) is processed as its UTF-8 encoding. Escape sequences and multi-byte characters may be split across calls. Malformed UTF-8 shows up as U+FFFD. The emulator does not turn "\n" into "\r\n"; a pseudo-terminal's line discipline normally does that. When feeding text from a file or a pipe, convert the line endings yourself or enable linefeed mode with "\e[20h". write Same as "feed". write_until_ground my ($consumed, $at_ground) = $term->write_until_ground($data); my $consumed = $term->write_until_ground($data); Feeds only the shortest prefix of $data that brings the parser back to its ground state, the point between sequences where it is safe to inject your own output. $consumed is the number of bytes processed (of the UTF-8 encoding, for a character string, so split byte strings rather than character strings with it); the rest of $data is not processed, so feed it yourself. If the parser is already at ground, nothing is consumed. $at_ground is false when all of $data was consumed and the parser is still inside a sequence. format my $out = $term->format(%options); Returns the screen as a character string. Rows are joined with "\n" ("\r\n" for VT output); rows below the last one written to are omitted and rows are not padded to the terminal width. format => 'plain' | 'vt' | 'html' Plain text (the default), text with the VT sequences needed to reproduce its colours and attributes, or HTML. See "HTML OUTPUT". scrollback => 0 | 1 Include the scrollback history before the visible screen. Default 0. trim => 0 | 1 Remove trailing spaces from each row of plain output. Default 1. unwrap => 0 | 1 Join rows that were soft-wrapped at the right margin. Default 0. palette => 0 | 1 Include the colour palette: a "