io.worxbend.tui.terminal
Members list
Type members
Classlikes
A terminal a TUI can draw to and read input from.
A terminal a TUI can draw to and read input from.
Implementations own the physical (or simulated) terminal: raw mode, the alternate screen, cursor visibility, and translating Buffer diffs into whatever the device understands. Everything above this trait — runtime, widgets, DSL — is backend-agnostic.
I/O failures are values (Either[BackendError, A]) because callers can meaningfully degrade (log and continue vs. abort); throw is reserved for genuine defects.
draw flushes only the cells that changed since the previous draw call (diff-based updates); the first call after construction, or after the buffer area changes, flushes everything.
'''Threading and ownership.''' A backend belongs to the one loop that drives it, and every member runs on that loop's render thread — the thread that calls readEvent, and is therefore the one reader of the input stream — with three exceptions that exist precisely so other threads can reach it: wake, requestFullRedraw and emergencyRestore are safe from any thread. Nothing else is synchronised: a second thread calling draw tears the frame on the wire, and one calling readEvent interleaves its reads into sequences the terminal never sent. The per-member notes below ("Must run on the render thread", "Safe from any thread") are instances of this rule, not exceptions to it.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class HeadlessBackendclass JLine3Backend
Which part of the screen Backend.clearRegion erases.
Which part of the screen Backend.clearRegion erases.
Everything except All is relative to where the cursor currently is, which is what makes the partial forms useful to a viewport that owns only some of the screen: it positions the cursor at the start of its own region and erases from there, leaving the user's scrollback above it intact.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
How many colors the terminal can actually show; RGB output is downsampled to fit.
How many colors the terminal can actually show; RGB output is downsampled to fit.
The rungs run from most to least capable. Monochrome and NoColor are the two ways of coping with a terminal that cannot show a palette, and they are not the same thing:
- Monochrome still emits color codes, but every color is thresholded to black or white by how bright it is. A selection that is conveyed only by a background color stays visible, which is what a two-tone terminal — or a black-and-white screen capture of a colorful app — needs.
- NoColor is not a device capability but an explicit opt-out: when it is in effect the backend emits text attributes (bold, underline, …) but no foreground/background color at all. It is what honoring the
NO_COLORconvention resolves to.
Nothing in the environment ever resolves to Monochrome; it is opt-in, by overriding the application's colorDepth.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ColorDepth.type
The shape the terminal draws its own hardware cursor in — DECSCUSR, CSI n SP q (XTerm ctlseqs.ms, "Set cursor style").
The shape the terminal draws its own hardware cursor in — DECSCUSR, CSI n SP q (XTerm ctlseqs.ms, "Set cursor style").
What it is for: a modal editor shows a block cursor in its command mode and a bar in its insert mode, and that difference is how the user knows which mode they are in without reading a status line. This is the shape of the hardware caret — the one an input method editor anchors its candidate popup to and a screen reader reports as the insertion point — not of a highlighted cell a widget paints into a Buffer.
Default hands the shape back to whatever the user configured in their terminal. It is what AnsiSequences.RestoreAll emits, so a process killed mid-edit does not leave a bar cursor behind in the shell it came from. A terminal that does not implement DECSCUSR ignores the sequence, so asking for a shape is never an error, merely sometimes without effect.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
CursorShape.type
One desktop notification a HeadlessBackend recorded — see HeadlessBackend.desktopNotifications.
One desktop notification a HeadlessBackend recorded — see HeadlessBackend.desktopNotifications.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Which of the three desktop-notification escape sequences a terminal understands.
Which of the three desktop-notification escape sequences a terminal understands.
There is no query for this, and the three dialects are not interchangeable: a terminal that speaks two of them shows two notifications for one message, and one that speaks none ignores all three. So exactly one is sent, chosen from the environment once per backend by detect, and the choice is a best guess that errs towards the dialect most terminals accept.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
The GLYPHORA_* environment variables that override what the library detects about a terminal, for the user whose terminal misreports itself — "my keys don't work", "the mouse eats my clicks", "Esc takes forever". Each one only narrows or pins behaviour; none switches on something the app did not ask for.
The GLYPHORA_* environment variables that override what the library detects about a terminal, for the user whose terminal misreports itself — "my keys don't work", "the mouse eats my clicks", "Esc takes forever". Each one only narrows or pins behaviour; none switches on something the app did not ask for.
GLYPHORA_COLOR_DEPTH=truecolor|256|16|mono|none— pins ColorDepth.detect's answer.GLYPHORA_KEYBOARD=legacy— never enables the kitty keyboard protocol, even when the terminal offers it.GLYPHORA_MOUSE=off|buttons— ignores an app's mouse capture, or holds it to clicks and drags when the app asks for all-motion tracking.GLYPHORA_ESCAPE_DELAY= milliseconds,1..2000— how long a loneEscwaits for the rest of a sequence before it is reported as the Escape key (50 by default). Raise it over a slow SSH link where arrow keys arrive as Escape plus letters; lower it if Escape feels sluggish.
Values compare case-insensitively under Locale.ROOT; an unrecognised value is ignored, never an error. The others — GLYPHORA_ASCII, GLYPHORA_NO_CAPABILITY_PROBE — are read where they act, and all of them are listed on the troubleshooting page.
Pure functions of the environment map they are given; safe from any thread.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
EnvironmentOverrides.type
The two whole-frame encodings that leave the backend: what print mode and a no-TTY run write to standard output.
The two whole-frame encodings that leave the backend: what print mode and a no-TTY run write to standard output.
The class above is not published API: the diff encoder's contract (previous is what the terminal shows) only holds inside a backend or a recorder that tracks what was written. These two have no such precondition — a buffer in, text out, callable from any thread — so they are the published face of the encoder.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FrameEncoder.type
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
HeadlessBackend.type
An in-memory Backend for headless end-to-end testing: renders into a retained snapshot instead of a TTY and reads synthetic events posted by the test driver.
An in-memory Backend for headless end-to-end testing: renders into a retained snapshot instead of a TTY and reads synthetic events posted by the test driver.
Thread contract: the runner calls readEvent/draw on the render thread while a test thread posts events and inspects lastDrawn — hence the blocking queue and volatile snapshot. wake interrupts a parked readEvent exactly as the JLine backend's does, so a Pilot works with any tickRate.
Every operation succeeds unless a test says otherwise through failNext, which is the seam that makes the Either[BackendError, A] half of Backend reachable from above this module.
Attributes
- Companion
- object
- Supertypes
iTerm2's inline-image protocol (https://iterm2.com/documentation-images.html), which WezTerm and a few others also implement: ESC ] 1337 ; File = : BEL draws the file at the cursor.
iTerm2's inline-image protocol (https://iterm2.com/documentation-images.html), which WezTerm and a few others also implement: ESC ] 1337 ; File = : BEL draws the file at the cursor.
The file is a PNG made by PngEncoder. The arguments glyphora sends:
inline=1display rather than download, andsizethe file's length in bytes;width/heightas bare numbers, which the protocol reads as cells — the box the picture is scaled into;preserveAspectRatio=0, because the widget already chose a box with the right shape and a terminal letterboxing inside it would leave stale cells showing at the edges;doNotMoveCursor=1, so an image on the last rows cannot scroll the screen. Terminals that predate the argument ignore it, which is why GraphicsLayer also brackets every image in a cursor save and restore.
The protocol has no delete. A picture is erased by repainting the cells it covered, which GraphicsLayer does by handing the region back to the frame diff.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ITerm2Images.type
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ImageProtocol.type
The terminal image protocols glyphora can draw a io.worxbend.tui.core.GraphicPlacement with. tag is the name a io.worxbend.tui.core.GraphicPayload encoded for the protocol carries.
The terminal image protocols glyphora can draw a io.worxbend.tui.core.GraphicPlacement with. tag is the name a io.worxbend.tui.core.GraphicPayload encoded for the protocol carries.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Backend implementation over JLine 3's system terminal.
Backend implementation over JLine 3's system terminal.
Owns the JLine Terminal for its whole lifetime: construct via JLine3Backend.create, release with close() (which restores cooked mode, the main screen, and cursor visibility if still active). draw keeps a copy of the last flushed frame and writes only the diff.
Signals are owned here rather than left to JLine's defaults. INT/QUIT become Event.Interrupt so the runner unwinds through its normal teardown; TSTP/CONT hand the terminal back to the shell and take it again on resume; WINCH posts a coalesced resize. See JLine3Backend.create for why the defaults are unusable.
The mechanics live in package-private collaborators — FrameEncoder and FrameBaseline for the frame diff, EventPump for the wake/poll machinery, ReplyQueries for the query/reply round trips, TerminalDressing for the dress/undress choreography, ScrollRegions for hardware scroll regions and TitleStack for the window title. This class wires them to the JLine terminal and carries the public contract.
Attributes
- Companion
- object
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JLine3Backend.type
The kitty graphics protocol (https://sw.kovidgoyal.net/kitty/graphics-protocol/) as far as glyphora speaks it: transmit-and-display one RGBA image into a box of cells, delete it again, and ask whether the terminal implements the protocol at all.
The kitty graphics protocol (https://sw.kovidgoyal.net/kitty/graphics-protocol/) as far as glyphora speaks it: transmit-and-display one RGBA image into a box of cells, delete it again, and ask whether the terminal implements the protocol at all.
Every command is an APC string, ESC _ G ; ESC \. The keys glyphora always sends:
a=Ttransmit and display in one command,f=32raw RGBA,s/vthe pixel size,ithe image id;c/rthe box in cells, which the terminal scales the picture into — so no cell-pixel size is needed here;C=1leave the cursor where it was, so the frame that follows is not shifted;q=2never answer: anOKor an error reply would otherwise arrive on the input stream mid-session.
Payloads longer than ChunkSize base64 bytes are split, as the protocol requires: every chunk but the last carries m=1, the last m=0, and only the first carries the control keys.
Pure string building; nothing here writes to a terminal. GraphicsLayer decides when each string is sent.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
KittyGraphics.type
How much mouse traffic the terminal is asked to send.
How much mouse traffic the terminal is asked to send.
A terminal only reports the mouse activity it has been told to report, and the two capturing settings differ enormously in volume:
Offasks for nothing: the terminal keeps the mouse for itself — its own selection, its own scrollback. The default of a run, and what Backend.enableMouseCapture treats as a request to stop capturing.Buttonsasks for DEC private modes 1000 and 1002 — presses, releases, the wheel, and motion only while a button is held down. That is everything a click, a scroll and a drag need, and it is silent while the user is merely moving the pointer across the window.AllMotionadds mode 1003, under which the terminal reports every single pointer movement over the window. That is what hover highlighting, tooltips and drop-target previews need, and it is also a report per cell crossed — a stream that is free locally and a genuine cost over a slow ssh link. It is opt-in for that reason.
Which one is in force decides whether io.worxbend.tui.core.MouseEventKind.Moved can ever be delivered: motion with no button held is only reported under AllMotion.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
The shape the terminal draws the mouse pointer in while it is over the window — OSC 22 (kitty's pointer-shape protocol, also spoken by foot, WezTerm, Ghostty and recent xterm).
The shape the terminal draws the mouse pointer in while it is over the window — OSC 22 (kitty's pointer-shape protocol, also spoken by foot, WezTerm, Ghostty and recent xterm).
What it is for: the affordances a desktop user already reads without thinking. A hand over a link or a button says "this can be clicked", an I-beam over a text field says "this takes typing", a double-headed arrow over a split divider says "this can be dragged". None of it is load-bearing — a terminal without OSC 22 ignores the request and the app works exactly as before — so a widget may set a shape and must never depend on it.
This is the mouse pointer, not the hardware caret; the caret's shape is CursorShape. Default hands the pointer back to the user's own configuration, and AnsiSequences.RestoreAll emits it so a process killed with a hand pointer up does not leave one behind in the shell.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
PointerShape.type
An inclusive, zero-based band of terminal rows — the unit Backend.scrollRegionUp operates on.
An inclusive, zero-based band of terminal rows — the unit Backend.scrollRegionUp operates on.
Rows only, and deliberately not a io.worxbend.tui.core.Rect: a Rect carries columns, and the terminal's own scroll region has no column margins on the emulators this library targets. Handing one over would promise a horizontal bound that the sequence then quietly ignores, moving the full width of every row inside the band.
bottom is inclusive because that is how DECSTBM reads and how every reference for it is written; an exclusive bound here would put an off-by-one between this type and the specification it exists to express.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ScrollDirection.type
Which way a scroll region moves its rows — see Backend.scrollRegionUp and Backend.scrollRegionDown.
Which way a scroll region moves its rows — see Backend.scrollRegionUp and Backend.scrollRegionDown.
A named pair rather than a boolean argument, because scroll(region, 3, Up) says at the call site what scroll(region, 3, true) does not — and because getting it backwards moves real rows the wrong way on a real screen, which is worth asking the type system for help with.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
What the process's standard output is attached to — the two questions print mode and the no-TTY policies ask before they decide how to write.
What the process's standard output is attached to — the two questions print mode and the no-TTY policies ask before they decide how to write.
Answered through JLine's JNI provider without ever building a terminal: TerminalBuilder.system(true) installs signal handlers and reconfigures the TTY, which is the right thing for an app that is about to take the screen and the wrong thing for a probe that only wants to know whether there is a screen. The provider's isSystemStream and systemStreamWidth are the isatty(3) and TIOCGWINSZ calls, no more.
Every answer is best-effort and conservative: a provider that cannot be loaded (an unsupported platform, a JNI library that failed to load) makes isTerminal fall back to System.console().isTerminal and width to None, so a caller always has a fallback to apply — print mode's is COLUMNS, then 80 columns. Callable from any thread; each call asks the operating system afresh, because a window can be resized between two calls.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
StandardOutput.type
What is known about one terminal feature: it works, it does not, or nobody ever asked.
What is known about one terminal feature: it works, it does not, or nobody ever asked.
Three states and not a Boolean, because "the terminal said no" and "the terminal said nothing" call for opposite behaviour and a boolean can only carry one of them. Almost every terminal ignores a query it does not implement rather than answering it, so silence has to mean "carry on" — see TerminalCapabilities.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
TaskbarState.type
What the terminal's tab or taskbar progress indicator (OSC 9;4) shows: the five states of the ConEmu protocol that Windows Terminal, Ghostty, WezTerm and others implement.
What the terminal's tab or taskbar progress indicator (OSC 9;4) shows: the five states of the ConEmu protocol that Windows Terminal, Ghostty, WezTerm and others implement.
A fraction is clamped to 0.0..1.0 and rounded to the whole percent the protocol takes; NaN reads as empty. How a terminal draws Error and Paused is its own choice — Windows Terminal paints them red and yellow — and one that knows only the determinate bar may show them as one. Immutable; safe to share between threads.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
What the terminal said about itself when it was asked, once, at start-up.
What the terminal said about itself when it was asked, once, at start-up.
Every Support field starts at Support.Unknown, and every caller must read Unknown as "go ahead and use the feature" — with one exception, named on the field: inBandResize is acted on only when the terminal said yes, because the signal-driven resize it would replace already works everywhere. That is the conservative reading even though it looks like the optimistic one: a terminal that ignores the query usually still honours the mode, so switching a feature off on silence would disable synchronised output and bracketed paste on the majority of terminals that answer nothing. Only an explicit Support.No — a mode report that came back saying "not recognised" — turns anything off.
Immutable, and owned by the backend that probed: a Backend hands out the value it established and never mutates one it gave away.
The fields past the first four arrived with the modern OSC and mode set:
backgroundColor— the OSC 11 answer, the colour behind the text;reportedColorScheme— a mode 2031 report's light/dark verdict. colorScheme combines the two.colorSchemeUpdates(mode 2031),inBandResize(mode 2048) andunicodeWidth(mode 2027) — what the DECRQM for each mode said. AYesonunicodeWidthmeans the terminal measures with grapheme-cluster widths, asCharWidthdoes.pointerShapes(OSC 22),desktopNotifications(OSC 9/777/99) andtaskbarProgress(OSC 9;4) cannot be probed; they stayUnknownunless the environment rules them out — a multiplexer that swallows unknown OSC strings — in which case the backend marks themNoand never writes the sequence.kittyGraphics— the answer to the kitty graphics protocol's documented query;inlineImages— iTerm2's inline-image protocol, which cannot be probed and is set toYesby the environment (TERM_PROGRAMnaming iTerm2 or WezTerm, orLC_TERMINAL=iTerm2). These two are the second exception to "silence means go ahead": likeinBandResizethey are acted on only onYes, because a picture sent to a terminal that does not draw it is not a mode quietly left off but a screenful of base64 — see ImageProtocol.select. A multiplexer marks bothNo.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
TerminalCapabilities.type
Reads the environment for how far up io.worxbend.tui.core.GlyphSupport this terminal can be trusted to go.
Reads the environment for how far up io.worxbend.tui.core.GlyphSupport this terminal can be trusted to go.
The terminal-facing half of the glyph floor, deliberately separate from the value itself: GlyphSupport lives in tui-core so widgets can honour it, and nothing in tui-core is allowed to know that terminals exist.
Pure with respect to its argument — it reads only the env map it is handed, which defaults to sys.env — so a test names an environment instead of mutating the process's own.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
TerminalGlyphs.type
The terminal window measured both ways it can be measured: in character cells, and in device pixels.
The terminal window measured both ways it can be measured: in character cells, and in device pixels.
One value rather than two separate calls, because the only useful thing to do with a pixel size is divide it by the cell size — and a caller that read the two from separate calls could straddle a window resize and compute a cell geometry that never existed on anyone's screen.
cells is always known: every terminal can say how many columns and rows it has. pixels is None whenever the terminal did not answer the query, which is the ordinary outcome rather than a failure — a great many terminals, including most of the Windows ones, do not implement it at all. Callers must treat None as "unknown" and fall back to an assumed cell shape; they must never read it as zero.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all