TerminalFitter class
Keeps a terminal correctly sized as the page around it changes.
This is the fiddliest part of hosting xterm.js in a browser, and it is why it lives here rather than inside a screen: any app embedding the terminal needs all of it, and getting a piece of it wrong is what produces a terminal that grows but never shrinks, renders 0×0, or hides its last line behind a soft keyboard.
It handles two modes:
- Fixed (fixedDims set) — the grid is pinned to chosen cols×rows for the session's lifetime, because the backend PTY cannot be resized. Only the font rescales, to the largest size at which that grid still fits.
- Auto-fit (fixedDims null) — the font is fixed and xterm re-derives cols/rows from the container.
Call attach once the terminal is mounted and the accessory bar exists, and dispose when the screen goes away.
Constructors
- TerminalFitter({required TerminalView term, required HTMLElement host, required HTMLElement accessory, required HTMLElement scaleTarget, ({int cols, int rows})? fixedDims, TerminalTextSize textSize()?, bool isFullscreen()?})
-
Creates a fitter for
terminsidehost.
Properties
- accessory → HTMLElement
-
The on-screen key bar below the terminal, whose box is reserved.
final
- fixedDims → ({int cols, int rows})?
-
The pinned grid, or
nullfor auto-fit.final - hashCode → int
-
The hash code for this object.
no setterinherited
- host → HTMLElement
-
The element the terminal is rendered into.
final
- isFullscreen → bool Function()
-
Whether the terminal is currently full-screen (its container then fills the
window and must not be pinned to a measured height).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scaleTarget → HTMLElement
-
The element carrying the
--term-key-scalecustom property (typically the screen root), so the key bar scales with the terminal font.final - term → TerminalView
-
The terminal being fitted. Only an XtermTerminalView can actually be
resized; any other implementation makes every operation a no-op, which is
what keeps tests with a fake terminal working.
final
- textSize → TerminalTextSize Function()
-
The current text-size preference. Defaults to TerminalTextSize.auto.
final
Methods
-
applyFont(
) → void - Applies the resolved font size and scales the key bar to match.
-
attach(
{Stream< TerminalTextSize> ? textSizeChanges}) → void - Starts watching everything that can change the terminal's geometry.
-
dispose(
) → void - Stops watching and releases every listener and timer.
-
fit(
) → void - Refits the terminal to its container.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
scheduleFit(
) → void -
Coalesces refit requests to once per frame, running the fit in a
requestAnimationFramecallback — after style and layout for any pending change (class toggle, keyboard inset, …) have been computed, so xterm measures the settled box. -
scheduleSettle(
) → void - Refits next frame, and once more after the viewport stops changing.
-
settle(
) → void - Refits across several frames and pins the view to the bottom. Use after a fullscreen toggle and once after the initial mount.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited