threecode/fatprompt/rendering

Search:
Group by:

Fat-prompt state, visual model, and byte templates.

This module owns the policy for prompt chrome: prompt rows, token bar, thinking ticker state, spacing, receipts, and the visual frame model used by tests. It may construct ANSI byte templates for those prompt frames, but it does not write them. terminal.nim is the only module that serializes those bytes to the terminal.

Types

BashViewport = object
  active*: bool
  idx*: int
  lines*: seq[string]
  maxLines*: int
FatPrompt = object
  width*: int
  height*: int
  scrollback*: seq[string]
  editorText*: string
  editorCursor*: int
  tokenBar*: TokenBarState
  ticker*: string
  bash*: BashViewport
FatPromptEvent = object
  case kind*: FatPromptEventKind
  of fpeSetPromptMode:
    promptMode*: PromptMode
  of fpeSetBar:
    barLabel*: string
    barHasGap*: bool
  of fpeSetTicker:
    ticker*: string
  of fpeSetPendingHint:
    usage*: Usage
    window*: int
    elapsed*: int
  of fpeClearBar, fpeClearTicker, fpeClearPendingHint:
    nil
FatPromptEventKind = enum
  fpeSetPromptMode, fpeSetBar, fpeClearBar, fpeSetTicker, fpeClearTicker,
  fpeSetPendingHint, fpeClearPendingHint
FatPromptGeometry = object
  tickerRows*: int
  hasBar*: bool
  barRows*: int
  editorRows*: int
  reservedRows*: int
Width-aware size of the volatile fat-prompt area.
FatPromptState = object
  footer*: FooterState
FooterFrame = object
  kind*: FooterFrameKind
  ticker*: string
  label*: string
  spinner*: string
  elapsed*: int
  clearRows*: int
Semantic footer view. Runtime code constructs this value; the terminal engine is responsible for lowering it to terminal bytes and using the same value for geometry.
FooterFrameKind = enum
  ffNone, ffClear, ffTokenBar, ffSpinner
FooterState = object
  promptMode*: PromptMode
  barLabel*: string
  hasGap*: bool
  ticker*: string
  pendingHint*: PendingHint
PendingHint = object
  active*: bool
  usage*: Usage
  window*: int
  elapsed*: int
PromptMarker = enum
  pmUser, pmAssistant, pmBash, pmRead, pmWrite, pmPatch, pmOther
PromptMode = enum
  pmIdle, pmTurnRunning, pmBufferedInput
TokenBarState = object
  usage*: Usage
  window*: int
  apiActive*: bool
  spinner*: string
  elapsedS*: int

Procs

proc absoluteBarTickFrame(row: int; label: string; activeEditor: bool; termW = 0): string {.
    ...raises: [], tags: [], forbids: [].}
proc addScrollLine(p: var FatPrompt; line: string) {....raises: [], tags: [],
    forbids: [].}
proc addTranscriptItem(p: var FatPrompt; marker: PromptMarker; body: string;
                       receipt = "") {....raises: [], tags: [], forbids: [].}
Append one transcript item using the spacing contract. There is exactly one blank visual row between items, and no blank row between body and token receipt.
proc apply(s: var FatPromptState; ev: FatPromptEvent) {....raises: [], tags: [],
    forbids: [].}
proc barFooterBelowAtColBytes(label: string; col: int; termW = 0): string {.
    ...raises: [], tags: [], forbids: [].}
proc barFooterBelowBytes(label: string; termW = 0): string {....raises: [],
    tags: [], forbids: [].}
proc barFooterBytes(label: string; termW = 0): string {....raises: [], tags: [],
    forbids: [].}
proc barWrapRows(visibleCells, termW: int): int {....raises: [], tags: [],
    forbids: [].}
proc bashVisibleRows(p: FatPrompt): seq[string] {....raises: [], tags: [],
    forbids: [].}
proc beginBash(p: var FatPrompt; idx = 0; maxLines = DefaultBashMaxLines) {.
    ...raises: [], tags: [], forbids: [].}
proc clampToWidth(s: string; width: int): string {....raises: [], tags: [],
    forbids: [].}
Truncate s (which may contain ANSI CSI escapes) so its visible width fits in width cells. Escapes are preserved; once the accumulated visible width reaches width the remainder is dropped.
proc clearBarBelowAtColBytes(col: int): string {....raises: [], tags: [],
    forbids: [].}
proc clearBarEvent(): FatPromptEvent {....raises: [], tags: [], forbids: [].}
proc clearBarRowBytes(): string {....raises: [], tags: [], forbids: [].}
proc clearFooterFrame(rows = 1): FooterFrame {....raises: [], tags: [], forbids: [].}
proc clearPendingHintEvent(): FatPromptEvent {....raises: [], tags: [], forbids: [].}
proc clearPromptAfterPendingReceiptBytes(): string {....raises: [], tags: [],
    forbids: [].}
proc clearSpinnerFooterBytes(hadTicker: bool): string {....raises: [], tags: [],
    forbids: [].}
proc clearTickerEvent(): FatPromptEvent {....raises: [], tags: [], forbids: [].}
proc editorHeight(p: FatPrompt): int {....raises: [], tags: [], forbids: [].}
proc editorRows(p: FatPrompt): seq[string] {....raises: [], tags: [], forbids: [].}
proc endTurnBytes(label: string; repaintPrompt: bool; termW = 0;
                  gapAlready = false): string {....raises: [], tags: [],
    forbids: [].}
proc finishBash(p: var FatPrompt; code = 0; elapsedS = -1) {....raises: [],
    tags: [], forbids: [].}
Commit the final bash tool item exactly once, replacing the live viewport.
proc footerFrame(s: FatPromptState): FooterFrame {....raises: [], tags: [],
    forbids: [].}
proc footerFrameBytes(frame: FooterFrame; termW = 0): string {....raises: [],
    tags: [], forbids: [].}
proc footerFrameBytes(s: FatPromptState; termW = 0): string {....raises: [],
    tags: [], forbids: [].}
Complete token-bar + prompt placeholder frame for the current state.
proc footerGeometry(s: FatPromptState; editorRows: int; termW = 0): FatPromptGeometry {.
    ...raises: [], tags: [], forbids: [].}
Size of the reserved fat-prompt area: ticker, token bar, and editor rows.
proc footerRowsAboveEditor(s: FatPromptState): int {....raises: [], tags: [],
    forbids: [].}
proc formatUserPromptItem(line: string): string {....raises: [],
    tags: [ReadEnvEffect], forbids: [].}
Format a user prompt as a scrollback item body. No trailing separator is included; the controller/transcript emitter owns inter-item spacing.
proc frameRows(p: FatPrompt): seq[string] {....raises: [], tags: [], forbids: [].}
Return the complete visible screen for one render tick.
proc frameText(p: FatPrompt): string {....raises: [], tags: [], forbids: [].}
proc hasElapsedSuffix(label: string): bool {....raises: [], tags: [], forbids: [].}
proc hasNonNewlineBytes(s: string): bool {....raises: [], tags: [], forbids: [].}
proc hideRealCaretBytes(): string {....raises: [], tags: [], forbids: [].}
proc initFatPrompt(width = DefaultWidth; height = DefaultHeight; window = 0): FatPrompt {.
    ...raises: [], tags: [], forbids: [].}
proc initFatPromptState(): FatPromptState {....raises: [], tags: [], forbids: [].}
proc labelCells(label: string): int {....raises: [], tags: [], forbids: [].}
proc liveBarBytes(label: string): string {....raises: [], tags: [], forbids: [].}
proc liveEditorBarTickFrame(label: string): string {....raises: [], tags: [],
    forbids: [].}
proc liveEditorSpinnerBarBytes(frame, label: string; elapsed: int): string {.
    ...raises: [], tags: [], forbids: [].}
proc liveEditorSpinnerFooterBytes(frame, label, ticker: string; elapsed: int;
                                  termW = 0): string {....raises: [], tags: [],
    forbids: [].}
proc moveToBarBelowBytes(): string {....raises: [], tags: [], forbids: [].}
proc noFooterFrame(): FooterFrame {....raises: [], tags: [], forbids: [].}
proc paintBarBytes(label: string): string {....raises: [], tags: [], forbids: [].}
proc promptOnlyBytes(): string {....raises: [], tags: [], forbids: [].}
proc promptOnlyResetBytes(): string {....raises: [], tags: [], forbids: [].}
proc pushBashOutput(p: var FatPrompt; line: string) {....raises: [], tags: [],
    forbids: [].}
proc receiptBarBytes(label: string): string {....raises: [], tags: [], forbids: [].}
proc rowsAboveEditor(frame: FooterFrame; termW = 0): int {....raises: [], tags: [],
    forbids: [].}
proc setBarEvent(label: string; hasGap = false): FatPromptEvent {....raises: [],
    tags: [], forbids: [].}
proc setEditor(p: var FatPrompt; text: string; cursor = -1) {....raises: [],
    tags: [], forbids: [].}
proc setPendingHintEvent(usage: Usage; window, elapsed: int): FatPromptEvent {.
    ...raises: [], tags: [], forbids: [].}
proc setPromptModeEvent(mode: PromptMode): FatPromptEvent {....raises: [],
    tags: [], forbids: [].}
proc setTicker(p: var FatPrompt; ticker: string) {....raises: [], tags: [],
    forbids: [].}
proc setTickerEvent(ticker: string): FatPromptEvent {....raises: [], tags: [],
    forbids: [].}
proc setTokenBar(p: var FatPrompt; usage: Usage; window: int; apiActive = false;
                 spinner = ""; elapsedS = -1) {....raises: [], tags: [],
    forbids: [].}
proc spinnerBarBytes(frame, label: string; elapsed: int): string {....raises: [],
    tags: [], forbids: [].}
proc spinnerCleanupBytes(tickerRows = 1): string {....raises: [], tags: [],
    forbids: [].}
proc spinnerFooterBytes(frame, label, ticker: string; elapsed: int; termW = 0): string {.
    ...raises: [], tags: [], forbids: [].}
proc spinnerFooterFrame(spinner, label, ticker: string; elapsed: int): FooterFrame {.
    ...raises: [], tags: [], forbids: [].}
proc tokenBarFrame(label: string; ticker = ""): FooterFrame {....raises: [],
    tags: [], forbids: [].}
proc tokenBarRows(s: FatPromptState; termW = 0): int {....raises: [], tags: [],
    forbids: [].}
Number of terminal rows occupied by the current token bar.
proc tokenBarText(state: TokenBarState): string {....raises: [], tags: [],
    forbids: [].}