5 releases (breaking)

Uses new Rust 2024

new 0.5.0 Apr 26, 2025
0.4.0 Mar 23, 2025
0.3.0 Dec 14, 2024
0.2.0 Sep 28, 2024
0.1.0 Jul 12, 2024

#2868 in Command line utilities

Download history 2/week @ 2025-01-04 2/week @ 2025-01-11 12/week @ 2025-02-08 13/week @ 2025-02-15 120/week @ 2025-03-22 9/week @ 2025-03-29 7/week @ 2025-04-05 3/week @ 2025-04-12

139 downloads per month
Used in 2 crates

GPL-3.0-or-later

2MB
45K SLoC

Yash-prompt

The yash-prompt crate implements command prompt for yash.

yash-prompt at crates.io yash-prompt at docs.rs Build status

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::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 config = Lexer::config();
config.source = Some(Source::Stdin.into());
let mut lexer = config.input(input);
let result = read_eval_loop(&ref_env, &mut lexer).await;
drop(lexer);
assert_eq!(result, Continue(()));
assert_eq!(env.exit_status, ExitStatus::SUCCESS);

Dependencies

~8–18MB
~269K SLoC