1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
use std::collections::HashMap;
/// Record the shell state
///
/// The [Environment] struct keeps track of various fields, all relating
/// to the shell state. The environment is the first thing setup at the
/// beginning of the shell, and is maintained throughout the lifetime of
/// the process.
///
/// Both [read()][crate::poem::read] and [recite()][crate::poem::recite]
/// rely on this struct for various functions and features.
///
/// # Examples
/// ```
/// fn main() -> Result<(), io::Error> {
/// let mut env = compose::env();
/// let poem = Poem::read("alias", &mut env)?;
/// poem.recite(&mut env)?;
/// Ok(())
/// }
/// ```
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Environment {
/// A table of aliases, set by the user using the built-in 'alias'
/// command
pub aliases: HashMap<String, String>,
/// A lookup table for +x files, constructed from the $PATH (see
/// [spellcheck()][crate::poem::elements::verse::Verse::spellcheck]
/// for more details)
pub bins: Vec<String>,
/// Indication of callstack level, helpful for recursively dealing
/// with aliases (see
/// [add()][crate::poem::elements::verse::Verse::add] for more
/// details)
pub cs: u8,
/// Force the capture of STDOUT (for internal poems)
pub fc: bool,
}
impl Environment {
/// Initialize an [Environment] struct with the default values
pub fn new() -> Self {
Environment {
aliases: HashMap::new(),
bins: Vec::new(),
cs: 0,
fc: false,
}
}
}
|