1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-10-03 23:53:07 +00:00
starship/src/print.rs

51 lines
1.3 KiB
Rust
Raw Normal View History

2019-04-08 21:35:38 +00:00
use clap::ArgMatches;
2019-05-10 03:51:50 +00:00
use rayon::prelude::*;
2019-04-11 23:31:30 +00:00
use std::io::{self, Write};
2019-04-08 21:35:38 +00:00
use crate::context::Context;
2019-05-01 20:34:24 +00:00
use crate::module::Module;
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",
"git_branch",
2019-05-14 04:43:11 +00:00
"git_status",
2019-05-01 14:45:56 +00:00
"package",
2019-04-25 15:06:18 +00:00
"nodejs",
"rust",
"python",
2019-05-12 03:58:45 +00:00
"go",
2019-04-25 15:06:18 +00:00
"line_break",
"character",
];
let context = Context::new(args);
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-05-01 20:34:24 +00:00
let modules = prompt_order
2019-05-10 03:51:50 +00:00
.par_iter()
2019-05-01 20:34:24 +00:00
.map(|module| modules::handle(module, &context)) // Compute modules
.flatten()
.collect::<Vec<Module>>(); // Remove segments set to `None`
let mut printable = modules.iter();
// Print the first module without its prefix
if let Some(first_module) = printable.next() {
let module_without_prefix = first_module.to_string_without_prefix();
write!(handle, "{}", module_without_prefix).unwrap()
}
// Print all remaining modules
printable.for_each(|module| write!(handle, "{}", module).unwrap());
2019-04-04 00:14:26 +00:00
}