2019-04-08 21:35:38 +00:00
|
|
|
use clap::ArgMatches;
|
2019-04-11 23:31:30 +00:00
|
|
|
use std::io::{self, Write};
|
2019-04-08 21:35:38 +00:00
|
|
|
|
2019-04-19 20:57:14 +00:00
|
|
|
use crate::context::Context;
|
2019-04-04 00:14:26 +00:00
|
|
|
use crate::modules;
|
|
|
|
|
2019-04-04 02:57:50 +00:00
|
|
|
pub fn prompt(args: ArgMatches) {
|
2019-04-25 15:06:18 +00:00
|
|
|
let prompt_order = vec![
|
|
|
|
"directory",
|
2019-04-27 02:07:07 +00:00
|
|
|
"git_branch",
|
2019-05-01 14:45:56 +00:00
|
|
|
"package",
|
2019-04-25 15:06:18 +00:00
|
|
|
"nodejs",
|
|
|
|
"rust",
|
|
|
|
"python",
|
|
|
|
"line_break",
|
|
|
|
"character",
|
|
|
|
];
|
2019-04-19 20:57:14 +00:00
|
|
|
let context = Context::new(args);
|
2019-04-16 00:54:52 +00:00
|
|
|
|
2019-04-11 23:31:30 +00:00
|
|
|
// TODO:
|
|
|
|
// - List files in directory
|
|
|
|
// - Index binaries in PATH
|
|
|
|
|
2019-04-08 21:35:38 +00:00
|
|
|
let stdout = io::stdout();
|
|
|
|
let mut handle = stdout.lock();
|
|
|
|
|
|
|
|
// Write a new line before the prompt
|
2019-04-12 17:17:20 +00:00
|
|
|
writeln!(handle).unwrap();
|
2019-04-11 23:31:30 +00:00
|
|
|
|
2019-04-19 20:57:14 +00:00
|
|
|
prompt_order
|
2019-04-12 23:11:40 +00:00
|
|
|
.iter()
|
2019-04-19 20:57:14 +00:00
|
|
|
.map(|module| modules::handle(module, &context)) // Compute segments
|
2019-04-13 03:06:48 +00:00
|
|
|
.flatten() // Remove segments set to `None`
|
|
|
|
.enumerate() // Turn segment into tuple with index
|
2019-04-15 15:40:18 +00:00
|
|
|
.map(|(index, segment)| segment.output_index(index)) // Generate string outputs
|
2019-04-08 21:35:38 +00:00
|
|
|
.for_each(|segment_string| write!(handle, "{}", segment_string).unwrap());
|
2019-04-04 00:14:26 +00:00
|
|
|
}
|