blob: e2f0a066978367fdf45c2a89215728d109abcc7a (
plain)
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
|
use clap::ArgMatches;
use std::io::{self, Write};
use crate::context::Context;
use crate::modules;
pub fn prompt(args: ArgMatches) {
let prompt_order = vec![
"directory",
"git_branch",
"package",
"nodejs",
"rust",
"python",
"line_break",
"character",
];
let context = Context::new(args);
// TODO:
// - List files in directory
// - Index binaries in PATH
let stdout = io::stdout();
let mut handle = stdout.lock();
// Write a new line before the prompt
writeln!(handle).unwrap();
prompt_order
.iter()
.map(|module| modules::handle(module, &context)) // Compute segments
.flatten() // Remove segments set to `None`
.enumerate() // Turn segment into tuple with index
.map(|(index, segment)| segment.output_index(index)) // Generate string outputs
.for_each(|segment_string| write!(handle, "{}", segment_string).unwrap());
}
|