Repository navigation
Line Editing
std::terminal::readline exposes Reedline to scripts. It edits text; it does not
interpret entered lines as Shelly code. An application supplies its own dispatch.
This defines a function to call from an interactive terminal. The definition itself neither opens an editor nor waits for input.
import std::terminal::{ readline }
fn notes_console(): () | ErrorValue
{
let $editor = readline::Editor(prompt: "notes> ")
try
{
for $line in $editor.lines
{
if $line == "quit" { break }
echo "note: ${line}"
}
}
finally { $editor.close }
}
lines yields Strings, including an empty String for an empty submission.
Ctrl+C discards the draft and reprompts; Ctrl+D on an empty buffer ends the stream.
A break closes the stream's editor lease while leaving the editor reusable.
For explicit interrupt handling, use read_event: its event kind is Line,
Interrupt, or End. read returns a String or () at end and handles interrupts
by continuing. The terminal is restored before application code processes a line.
Editor options include a prompt, history policy, completion, validation, highlighting, Emacs/Vi mode, and limits. Copies share the editor handle. A script editor defaults to isolated in-memory history and does not inherit the shell's prompt, history file, or completion symbol list.
A Prompt supports left, right, and continuation content; these may be text or callbacks. ReadOptions can override a prompt and provide an initial draft/cursor. Text and Style objects express styling without treating every ANSI escape as printable width.
Callbacks receive an Edit snapshot containing text, cursor, revision, before/after text, and word information. Complete returns Strings or Completion records; Validate returns ready/more/reject; Highlight returns styled spans.
Spans and cursors use UTF-8 byte offsets, validated at character boundaries. They are not Unicode character indexes. This differs from language String indexing. Callback results cannot replace or rewrite the input implicitly.
Limits bound input sizes, completions, highlight spans, and callback work.
History can be submitted automatically or recorded manually, with explicit
persistent-storage failure policy. history_status exposes degraded history.
Call close in cleanup even if a callback or application command fails.
Related: REPL and history · Terminal formatting · Errors
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use