starship/src/print.rs

27 lines
802 B
Rust
Raw Normal View History

2019-04-08 23:35:38 +02:00
use clap::ArgMatches;
2019-04-12 01:31:30 +02:00
use std::io::{self, Write};
2019-04-08 23:35:38 +02:00
2019-04-04 02:14:26 +02:00
use crate::modules;
2019-04-04 04:57:50 +02:00
pub fn prompt(args: ArgMatches) {
2019-04-12 23:49:20 +02:00
let default_prompt = vec!["directory", "nodejs", "line_break", "character"];
2019-04-04 02:14:26 +02:00
2019-04-12 01:31:30 +02:00
// TODO:
// - List files in directory
// - Index binaries in PATH
2019-04-08 23:35:38 +02:00
let stdout = io::stdout();
let mut handle = stdout.lock();
// Write a new line before the prompt
2019-04-12 19:17:20 +02:00
writeln!(handle).unwrap();
2019-04-12 01:31:30 +02:00
2019-04-05 03:35:24 +02:00
default_prompt
2019-04-13 01:11:40 +02:00
.iter()
2019-04-13 05:06:48 +02:00
.map(|module| modules::handle(module, &args)) // 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
2019-04-08 23:35:38 +02:00
.for_each(|segment_string| write!(handle, "{}", segment_string).unwrap());
2019-04-04 02:14:26 +02:00
}