Expand description
Interactive REPL editor, prompt, history, and completion surface. The REPL module exists to own interactive shell behavior that the ordinary CLI host should not know about.
The layering here is intentional:
engineowns the line editor boundary, prompt rendering, history picker/completion adapters, and debug surfaces.dispatchowns command execution and shell-scope behavior once a line has been accepted.completionshapes the live command catalog into REPL-aware completion trees.presentationowns prompt appearance and intro/help material that is specific to interactive use.
A submitted line travels through the layers like this:
user keystrokes
│
▼ [ engine ] reedline editor, prompt, completion/history menus
│ line accepted
▼ [ dispatch ] execute command, apply shell scope and aliases
│ ReplLineResult
├── Continue → render output, show next prompt
├── ReplaceInput → update input buffer without printing
├── Restart → [ lifecycle ] rebuild REPL state, loop again
└── Exit → return ReplRunResult to the callerEmbedders drive the loop with crate::repl::run_repl, configured through
crate::repl::ReplRunConfig::builder. The engine, dispatch, and
presentation layers are internal; only the config/result types cross the
boundary.
Minimal embedder path:
use anyhow::Result;
use osp_cli::repl::{
HistoryConfig, ReplLineResult, ReplPrompt, ReplRunConfig, run_repl,
};
let config = ReplRunConfig::builder(
ReplPrompt::simple("osp> "),
HistoryConfig::builder().build(),
)
.build();
let _result = run_repl(config, |line, _history| -> Result<ReplLineResult> {
match line.trim() {
"exit" | "quit" => Ok(ReplLineResult::Exit(0)),
_ => Ok(ReplLineResult::Continue(String::new())),
}
})?;Choose crate::app instead when you want the full osp host with config
loading, command dispatch, and rendering already wired together. Choose
this module directly when you already own the execution callback and only
want the interactive editor loop.
When debugging the REPL, first decide whether the issue is editor/runtime state, dispatch semantics, or rendering. That is usually enough to choose the right submodule.
Contract:
- this module may depend on editor/runtime adapters, completion, UI, and dispatch code
- it should not become the owner of generic command execution rules, config resolution, or non-interactive CLI parsing
Public API shape:
- primary host-facing entrypoints are
crate::repl::run_repl,crate::repl::ReplRunConfig,crate::repl::HistoryConfig, andcrate::repl::ReplPrompt - debug snapshots and inspection helpers such as
crate::repl::CompletionDebugandcrate::repl::debug_completionstay available without becoming the default path for ordinary embedders - host-style REPL configuration flows through concrete builders and
factories such as
crate::repl::ReplRunConfig::builder,crate::repl::ReplAppearance::builder, andcrate::repl::HistoryConfig::builder - guided REPL configuration follows the crate-wide naming rule:
new(...)for exact constructors,builder(...)for staged configuration,with_*setters, andbuild()as the terminal step
Structs§
- Completion
Debug - Snapshot of completion/menu state for a given line and cursor position.
- Completion
Debug Frame - One frame from a stepped completion-debug session.
- Completion
Debug Match - One rendered completion entry in the debug surface.
- Completion
Debug Options - Rendering and capture options for completion-debug helpers.
- Highlight
Debug Span - Debug-friendly view of one highlighted span in the REPL line.
- History
Config - Configuration for REPL history persistence, visibility, and shell scoping.
- History
Config Builder - Builder for
HistoryConfig. - History
Entry - Visible history entry returned by listing operations after scope filtering.
- History
Shell Context - Shared shell-prefix state used to scope history to nested shell integrations.
- Line
Projection - Pre-processed editor input used for completion and highlighting.
- Repl
Appearance - Style overrides for REPL-only completion and highlighting chrome.
- Repl
Appearance Builder - Builder for
ReplAppearance. - Repl
Prompt - Static prompt text shown by the interactive editor.
- Repl
RunConfig - Editor-host configuration for one REPL run.
- Repl
RunConfig Builder - Builder for
ReplRunConfig. - Shared
History - Thread-safe facade over the REPL history store.
Enums§
- Debug
Step - Synthetic editor action used by completion-debug stepping.
- Repl
Input Mode - Selects how aggressively the REPL should use the interactive line editor.
- Repl
Line Result - Outcome of executing one submitted REPL line.
- Repl
Reload Kind - Controls how a command-triggered REPL restart should be presented.
- Repl
RunResult - Outcome of one
run_replsession.
Functions§
- color_
from_ style_ spec - Parses a REPL style string and extracts a terminal color.
- debug_
completion - Builds a single completion-debug snapshot for
lineatcursor. - debug_
completion_ steps - Replays a sequence of synthetic editor actions and captures each frame.
- debug_
highlight - Classifies a REPL line and returns serializable highlight spans for debugging tools.
- debug_
history_ menu - Builds a single history-menu debug snapshot for
lineatcursor. - debug_
history_ menu_ steps - Replays synthetic editor actions for the history menu and captures each frame.
- default_
pipe_ verbs - Returns the default DSL verbs exposed after
|in the REPL. - run_
repl - Runs the interactive REPL and delegates submitted lines to
execute.
Type Aliases§
- Line
Projector - Projects a raw editor line into the view used by completion/highlighting.
- Prompt
Right Renderer - Lazily renders the right-hand prompt for a REPL frame.