summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-04-04 21:35:24 -0400
committerMatan Kushner <hello@matchai.me>2019-04-04 21:35:24 -0400
commitc79cbe63b147b3e6e490f662f06d317e441ad2c4 (patch)
tree704418a5cab61f354aeff8c2c1850796267acde9 /src
parent472b66894d10e5be9cfb5a40b79dc61e746c0795 (diff)
Add stringify_segment rustdoc
Diffstat (limited to 'src')
-rw-r--r--src/modules/character.rs (renamed from src/modules/char.rs)2
-rw-r--r--src/modules/directory.rs4
-rw-r--r--src/modules/mod.rs10
-rw-r--r--src/print.rs24
4 files changed, 29 insertions, 11 deletions
diff --git a/src/modules/char.rs b/src/modules/character.rs
index af24ef082..75d15ddc6 100644
--- a/src/modules/char.rs
+++ b/src/modules/character.rs
@@ -3,7 +3,7 @@ use ansi_term::{Color, Style};
use clap::ArgMatches;
/// Creates a segment for the prompt character
-///
+///
/// The char segment prints an arrow character in a color dependant on the exit-
/// code of the last executed command:
/// - If the exit-code was "0", the arrow will be formatted with `COLOR_SUCCESS`
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index 098d0f14e..3e4546e0a 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -1,8 +1,8 @@
use super::Segment;
-use dirs;
-use std::env;
use ansi_term::{Color, Style};
use clap::ArgMatches;
+use dirs;
+use std::env;
/// Creates a segment with the current directory
pub fn segment(_: &ArgMatches) -> Segment {
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index 61447890e..87ce82e2e 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -1,9 +1,9 @@
-mod char;
+mod character;
mod directory;
mod line_break;
-use clap::ArgMatches;
use ansi_term::Style;
+use clap::ArgMatches;
pub struct Segment {
pub style: Style,
@@ -18,21 +18,21 @@ impl Default for Segment {
style: Style::default(),
value: String::from(" "),
prefix: None,
- suffix: None
+ suffix: None,
}));
Segment {
style: Style::default(),
value: String::from(""),
prefix: None,
- suffix: default_suffix
+ suffix: default_suffix,
}
}
}
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
match module {
- "char" | "character" => char::segment(&args),
+ "char" | "character" => character::segment(&args),
"dir" | "directory" => directory::segment(&args),
"line_break" => line_break::segment(&args),
diff --git a/src/print.rs b/src/print.rs
index b4ce7ab75..2aad9019b 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -5,26 +5,44 @@ use clap::ArgMatches;
pub fn prompt(args: ArgMatches) {
let default_prompt = vec!["directory", "line_break", "character"];
- default_prompt.into_iter()
+ default_prompt
+ .into_iter()
.map(|module| modules::handle(module, &args))
.map(|segment| stringify_segment(segment))
.for_each(|segment_string| print!("{}", segment_string));
}
+/// 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;
+ } = 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 {