1use crate::re_exports::*;
2
3#[derive(Clone)]
4pub struct State {
5 pub environment: BTreeMap<String, String>,
6 pub prompt: String,
7 pub unicode_supported: bool,
8 pub history: Vec<String>,
9 pub commands: Vec<crate::Command>,
10}
11
12impl State {
13 pub(crate) fn new(commands: &[crate::Command], unicode_supported: bool) -> Self {
14 Self {
15 environment: BTreeMap::new(),
16 unicode_supported,
17 prompt: if unicode_supported { "❯ " } else { "> " }.into(),
18 commands: commands.to_vec(),
19 history: Vec::new(),
20 }
21 }
22
23 pub fn set_environment_variable(&mut self, key: impl AsRef<str>, value: impl AsRef<str>) {
24 self
25 .environment
26 .insert(key.as_ref().into(), value.as_ref().into());
27
28 #[cfg(feature = "std")]
29 std::env::set_var(key.as_ref(), value.as_ref());
30 }
31}