Skip to main content

Module interactive_prompt

Module interactive_prompt 

Source
Expand description

Interactive user-confirmation dialogs for auto-fixes.

prompt_user_confirmation asks a yes/no question and reads a single keypress (no Enter required) with a 30 second timeout; the default is used when the user presses Enter or the prompt expires. prompt_fix_selection renders a checkbox list that is navigated with the arrow keys, toggled with space and confirmed with Enter.

Both prompts are written against the KeyReader / PromptWriter abstractions so the same logic is unit-testable with MockKeyReader and CapturingWriter instead of a real terminal.

use limitless_cli::modules::interactive_prompt::{
    prompt_user_confirmation_with, CapturingWriter, Key, MockKeyReader,
    CONFIRM_TIMEOUT,
};

let mut reader = MockKeyReader::new(vec![Key::Enter]);
let mut writer = CapturingWriter::default();
let confirmed = prompt_user_confirmation_with(
    "Copy .env.example to .env?",
    true,
    CONFIRM_TIMEOUT,
    &mut reader,
    &mut writer,
);
assert!(confirmed);
assert!(writer.output.contains("❓ Copy .env.example to .env? (Y/n) [y]"));

Structs§

CapturingWriter
A PromptWriter that records everything written for assertions.
Fix
One auto-fix candidate offered by the selection UI.
MockKeyReader
A KeyReader that replays a canned sequence of keys for tests.
StdoutWriter
Writer backed by the real standard output.
TerminalKeyReader
Key reader backed by a real terminal via the crossterm crate.

Enums§

Key
A normalized key press that the prompts understand.

Constants§

CONFIRM_TIMEOUT
How long a confirmation prompt waits for input before using its default.

Traits§

KeyReader
Abstraction over the terminal so prompts can be driven by mock input.
PromptWriter
Abstraction over the output stream so prompts can capture their text.

Functions§

fixes_from_mentors
Builds a fix list from mentor_messages-style suggestions.
prompt_fix_selection
Renders a checkbox list and returns the user-selected fixes.
prompt_fix_selection_with
Testable core of prompt_fix_selection; see the module docs.
prompt_user_confirmation
Asks message as a yes/no question and returns the user’s decision.
prompt_user_confirmation_with
Testable core of prompt_user_confirmation; see the module docs.