Expand description
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::ops::ControlFlow::Continue;
use yash_env::Env;
use yash_env::input::FdReader;
use yash_env::io::Fd;
use yash_env::parser::Config;
use yash_env::semantics::ExitStatus;
use yash_env::source::Source;
use yash_prompt::{ExpandText, Prompter};
use yash_semantics::expansion::expand_text;
use yash_semantics::read_eval_loop;
use yash_syntax::parser::lex::Lexer;
let mut env = Env::new_virtual();
env.any.insert(Box::new(ExpandText(|env, text| {
Box::pin(async move { expand_text(env, text).await.ok() })
})));
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 config = Config::with_input(input);
config.source = Some(Source::Stdin.into());
let mut lexer = Lexer::from(config);
let result = read_eval_loop(&ref_env, &mut lexer).await;
drop(lexer);
assert_eq!(result, Continue(()));
assert_eq!(env.exit_status, ExitStatus::SUCCESS);Structs§
- Expand
Text - Wrapper for a text expansion function
- Prompter
Inputdecorator that shows a command prompt
Functions§
- expand_
posix - Expands the prompt string according to the POSIX standard.
- fetch_
posix - Fetches the command prompt string from the variable set.