summaryrefslogtreecommitdiffstats
path: root/src/print.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-04-12 19:11:40 -0400
committerMatan Kushner <hello@matchai.me>2019-04-12 19:11:40 -0400
commita0e4172602f0b6a666bca7d8568a4f9a181d5438 (patch)
treea414c6a6162770dbd2dc3fd090b33ff25cf6b349 /src/print.rs
parentfec5c4db4ebd35fa004da524df252f13cb86094e (diff)
Use copy to return segment
Diffstat (limited to 'src/print.rs')
-rw-r--r--src/print.rs45
1 files changed, 2 insertions, 43 deletions
diff --git a/src/print.rs b/src/print.rs
index 03e22374e..19b13ec4d 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -2,7 +2,6 @@ use clap::ArgMatches;
use std::io::{self, Write};
use crate::modules;
-use crate::modules::Segment;
pub fn prompt(args: ArgMatches) {
let default_prompt = vec!["directory", "nodejs", "line_break", "character"];
@@ -18,48 +17,8 @@ pub fn prompt(args: ArgMatches) {
writeln!(handle).unwrap();
default_prompt
- .into_iter()
+ .iter()
.map(|module| modules::handle(module, &args))
- .map(stringify_segment)
+ .map(|segment| segment.output())
.for_each(|segment_string| write!(handle, "{}", segment_string).unwrap());
}
-
-/// Create a string with the formatted contents of a segment
-///
-/// Will recursively also format the prefix and suffix of the segment being
-/// stringified.
-///
-/// # Example
-/// ```
-/// use starship::modules::Segment;
-///
-/// let segment = Segment {
-/// value: String::from("->"),
-/// ..Default::default()
-/// };
-///
-/// let result = starship::print::stringify_segment(segment);
-/// assert_eq!(result, "-> ");
-/// ```
-pub fn stringify_segment(segment: Segment) -> String {
- let Segment {
- prefix,
- value,
- style,
- suffix,
- } = segment;
-
- let mut segment_string = String::new();
-
- if let Some(prefix) = prefix {
- segment_string += &stringify_segment(*prefix);
- }
-
- segment_string += &style.paint(value).to_string();
-
- if let Some(suffix) = suffix {
- segment_string += &stringify_segment(*suffix);
- }
-
- segment_string
-}