Terminal
Class: Terminal
Defined in: packages/workout/src/terminal/terminal.ts:32
Full-featured terminal UI with scrolling history, progress bars, and interactive input Provides a rich terminal interface with automatic screen updates and keyboard navigation Falls back to basic ConsoleLogger when not in a TTY environment
Example
const output = new WorkerOutput();
const terminal = new Terminal(output, "INFO");
output.log("INFO", "Application started");
output.startProgress("task", 100, "Processing");
// Terminal displays logs with progress bars
terminal.close(); // Cleanup when done
Constructors
Constructor
new Terminal(
wo,level?,format?,tty?):Terminal
Defined in: packages/workout/src/terminal/terminal.ts:91
Create a new terminal UI
Parameters
wo
WorkerOutput instance to display
level?
Log level filter (default: process.env.LOG_LEVEL or "INFO")
format?
string
Log format string (optional)
tty?
boolean = process.stdout.isTTY
Whether running in TTY mode (default: process.stdout.isTTY)
Returns
Terminal
Properties
_refresh?
optional_refresh?:Timeout
Defined in: packages/workout/src/terminal/terminal.ts:80
Interval timer for screen refresh
format?
optionalformat?:string
Defined in: packages/workout/src/terminal/terminal.ts:56
Log format string
hasProgress
hasProgress:
boolean=false
Defined in: packages/workout/src/terminal/terminal.ts:50
Whether any progress bars are active
height
height:
number=process.stdout.rows
Defined in: packages/workout/src/terminal/terminal.ts:38
Terminal height in rows
history
history:
string[] =[]
Defined in: packages/workout/src/terminal/terminal.ts:42
Scrollable log history
historySize
historySize:
number=2000
Defined in: packages/workout/src/terminal/terminal.ts:44
Maximum number of history lines to keep
inputs
inputs:
WorkerInput[] =[]
Defined in: packages/workout/src/terminal/terminal.ts:58
Pending input requests
inputValid
inputValid:
boolean=true
Defined in: packages/workout/src/terminal/terminal.ts:66
Whether current input passes validation
inputValue
inputValue:
string=""
Defined in: packages/workout/src/terminal/terminal.ts:60
Current user input value
level
level:
WorkerLogLevel
Defined in: packages/workout/src/terminal/terminal.ts:48
Log level filter
listener
listener: (
msg) =>void
Defined in: packages/workout/src/terminal/terminal.ts:78
WorkerOutput message listener function
Parameters
msg
Returns
void
logo
logo:
string[] =[]
Defined in: packages/workout/src/terminal/terminal.ts:74
Logo lines to display
logoWidth
logoWidth:
number=0
Defined in: packages/workout/src/terminal/terminal.ts:76
Width of the logo in characters
progressChar
progressChar:
number=0
Defined in: packages/workout/src/terminal/terminal.ts:68
Current progress animation frame index
progressChars
progressChars:
string[]
Defined in: packages/workout/src/terminal/terminal.ts:70
Progress animation character frames
progresses
progresses:
object={}
Defined in: packages/workout/src/terminal/terminal.ts:52
Active progress trackers by ID
Index Signature
[key: string]: WorkerProgress
reset
reset:
boolean=false
Defined in: packages/workout/src/terminal/terminal.ts:64
Whether terminal has been reset
rl?
optionalrl?:Interface
Defined in: packages/workout/src/terminal/terminal.ts:62
Readline interface for input
scrollY
scrollY:
number=-1
Defined in: packages/workout/src/terminal/terminal.ts:46
Current scroll position (-1 = bottom/no scroll)
title
title:
string=""
Defined in: packages/workout/src/terminal/terminal.ts:54
Current title displayed at top of terminal
tty
tty:
boolean
Defined in: packages/workout/src/terminal/terminal.ts:34
Whether running in a TTY environment
width
width:
number=process.stdout.columns
Defined in: packages/workout/src/terminal/terminal.ts:40
Terminal width in columns
wo
wo:
WorkerOutput
Defined in: packages/workout/src/terminal/terminal.ts:36
WorkerOutput instance being displayed
refreshSpeed
staticrefreshSpeed:number=300
Defined in: packages/workout/src/terminal/terminal.ts:82
Screen refresh rate in milliseconds
Methods
clearScreen()
clearScreen():
void
Defined in: packages/workout/src/terminal/terminal.ts:614
Clear the entire terminal screen. Used for testing - production code uses displayScreen() instead.
Returns
void
close()
close():
void
Defined in: packages/workout/src/terminal/terminal.ts:250
Close the terminal UI and cleanup resources Stops refresh timer, resets terminal, and removes listeners
Returns
void
displayBar()
displayBar(
ratio,barlen):string
Defined in: packages/workout/src/terminal/terminal.ts:424
Create a visual progress bar string
Parameters
ratio
number
Progress ratio (0.0 to 1.0)
barlen
number
Total bar length in characters
Returns
string
Formatted progress bar string with colors
displayFooter()
displayFooter():
string
Defined in: packages/workout/src/terminal/terminal.ts:490
Generate the complete footer section with progress bars and title
Returns
string
Formatted footer string
displayHistory()
displayHistory(
lines,complete?):string
Defined in: packages/workout/src/terminal/terminal.ts:544
Render the scrollable history area Optionally overlays the logo on the right side
Parameters
lines
number
Number of lines to display
complete?
boolean = true
Whether to fill empty lines (default: true)
Returns
string
Formatted history string
displayProgress()
displayProgress(
p):string
Defined in: packages/workout/src/terminal/terminal.ts:468
Format a progress bar with percentage and count
Parameters
p
WorkerProgress instance to display
Returns
string
Formatted progress string with newline
displayScreen()
displayScreen():
Promise<void>
Defined in: packages/workout/src/terminal/terminal.ts:588
Render the complete terminal screen Updates history, footer, progress bars, and input prompt
Returns
Promise<void>
displayString()
displayString(
str,limit?):string
Defined in: packages/workout/src/terminal/terminal.ts:399
Format a string for display with proper width and padding
Parameters
str
string
String to display (may contain ANSI color codes)
limit?
number = ...
Maximum width (default: terminal width)
Returns
string
Formatted string
displayTitle()
displayTitle():
string
Defined in: packages/workout/src/terminal/terminal.ts:455
Format the title for display with centered padding
Returns
string
Formatted title string with newline
getBar()
getBar(
size,complete):string
Defined in: packages/workout/src/terminal/terminal.ts:443
Generate a portion of a progress bar
Parameters
size
number
Number of characters to generate
complete
boolean
Whether this is the completed portion (true) or remaining portion (false)
Returns
string
Colored bar segment
getFooterSize()
getFooterSize():
number
Defined in: packages/workout/src/terminal/terminal.ts:349
Calculate the height of the footer area (progress bars, title, input)
Returns
number
Number of rows needed for the footer
getLogo()
getLogo():
string[]
Defined in: packages/workout/src/terminal/terminal.ts:533
Retrieve current logo Useful for modifying the logo (e.g., adding version information)
Returns
string[]
Array of logo lines
getTrueLength()
getTrueLength(
str):number
Defined in: packages/workout/src/terminal/terminal.ts:414
Get the visible length of a string excluding ANSI color codes
Parameters
str
string
String that may contain ANSI color codes
Returns
number
Visible character count
handleTitleMessage()
handleTitleMessage(
msg):void
Defined in: packages/workout/src/terminal/terminal.ts:312
Handle title set messages
Parameters
msg
Message containing the title
Returns
void
log()
log(
groups,level, ...args):void
Defined in: packages/workout/src/terminal/terminal.ts:324
Add a log message to history with formatting and colors
Parameters
groups
any[]
Log group hierarchy
level
Log level
args
...any[]
Log message arguments
Returns
void
onData()
onData(
data):void
Defined in: packages/workout/src/terminal/terminal.ts:142
Handle keyboard input from stdin Manages scrolling (Up/Down/PageUp/PageDown), text input, and Ctrl+C
Parameters
data
string | Buffer<ArrayBufferLike>
Input data from stdin
Returns
void
pushHistory()
pushHistory(
line):void
Defined in: packages/workout/src/terminal/terminal.ts:265
Add a line to the scrollable history buffer Maintains history size limit by removing oldest entries
Parameters
line
string
Log line to add to history
Returns
void
resetTerm()
resetTerm():
void
Defined in: packages/workout/src/terminal/terminal.ts:237
Reset terminal to normal mode Restores cursor visibility and alternate screen buffer
Returns
void
resize()
resize():
void
Defined in: packages/workout/src/terminal/terminal.ts:189
Handle terminal resize events Updates height and width and refreshes display if progress is shown
Returns
void
router()
router(
msg):Promise<void>
Defined in: packages/workout/src/terminal/terminal.ts:277
Route WorkerOutput messages to appropriate handlers
Parameters
msg
Message to process
Returns
Promise<void>
resolves when message is handled
scrollDown()
scrollDown(
increment):void
Defined in: packages/workout/src/terminal/terminal.ts:215
Scroll the history view downward
Parameters
increment
number
Number of lines to scroll down
Returns
void
scrollUp()
scrollUp(
increment):void
Defined in: packages/workout/src/terminal/terminal.ts:201
Scroll the history view upward
Parameters
increment
number
Number of lines to scroll up
Returns
void
setLogo()
setLogo(
logo):void
Defined in: packages/workout/src/terminal/terminal.ts:518
Set the logo to display
How to create logo:
Parameters
logo
string[]
to display
Returns
void
setTitle()
setTitle(
title?):void
Defined in: packages/workout/src/terminal/terminal.ts:229
Set the terminal title displayed at the top
Parameters
title?
string = ""
Title text to display
Returns
void
stripColorString()
stripColorString(
str,limit?):string
Defined in: packages/workout/src/terminal/terminal.ts:367
Strip or truncate a string with ANSI color codes Preserves color codes while limiting visible character count
Parameters
str
string
String with ANSI color codes
limit?
number = -1
Maximum visible character length (-1 for no limit)
Returns
string
Processed string with color codes preserved