2 unstable releases
0.2.0 | Sep 28, 2024 |
---|---|
0.1.0 | Jul 12, 2024 |
#2839 in Command line utilities
Used in 2 crates
2MB
42K
SLoC
Yash-prompt
The yash-prompt
crate implements command prompt for yash.
License
This crate is distributed under GPLv3.
lib.rs
:
This library crate provides functionalities to show a command prompt.
Overview
The yash-prompt
crate provides command prompt support for the yash
shell. It includes functionalities to expand prompt strings and display them
interactively.
Prompter
is a decorator struct that wraps an inner input source and
displays a command prompt before reading input from the user. It can be
used to create an interactive shell prompt. The prompter internally uses
the following functions to expand prompt strings:
fetch_posix
: Fetches the value of a variable defined by POSIX for a prompt string.expand_posix
: Expands a prompt string in a POSIX-compliant manner.expand_ex
: Expands a prompt string with yash-specific expansions. (This function is not yet implemented.)
Examples
Construct an input source with a prompter and read input from the user:
use std::cell::RefCell;
use std::num::NonZeroU64;
use std::ops::ControlFlow::Continue;
use yash_env::Env;
use yash_env::input::FdReader;
use yash_env::io::Fd;
use yash_env::semantics::ExitStatus;
use yash_prompt::Prompter;
use yash_semantics::read_eval_loop;
use yash_syntax::parser::lex::Lexer;
use yash_syntax::source::Source;
let mut env = Env::new_virtual();
let reader = FdReader::new(Fd::STDIN, env.system.clone());
let mut ref_env = RefCell::new(&mut env);
let input = Box::new(Prompter::new(reader, &ref_env));
let mut lexer = Lexer::new(input, NonZeroU64::MIN, Source::Stdin.into());
let result = read_eval_loop(&ref_env, &mut lexer).await;
drop(lexer);
assert_eq!(result, Continue(()));
assert_eq!(env.exit_status, ExitStatus::SUCCESS);
Dependencies
~9–19MB
~280K SLoC