summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-04-12 23:06:48 -0400
committerMatan Kushner <hello@matchai.me>2019-04-12 23:06:48 -0400
commit9d4492c313220ee128a49e01dd3580d22450cd04 (patch)
treeaa5434e10f114c1bde36b3554cace0bde26e3ec0 /src/modules
parentd62bb107f231c3d0ebf47b7c91f26348213d8386 (diff)
Make segments optionals
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/character.rs6
-rw-r--r--src/modules/directory.rs7
-rw-r--r--src/modules/line_break.rs9
-rw-r--r--src/modules/mod.rs2
-rw-r--r--src/modules/nodejs.rs9
5 files changed, 21 insertions, 12 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs
index 681c1af02..53a43e886 100644
--- a/src/modules/character.rs
+++ b/src/modules/character.rs
@@ -10,7 +10,7 @@ use clap::ArgMatches;
/// (green by default)
/// - If the exit-code was anything else, the arrow will be formatted with
/// `COLOR_FAILURE` (red by default)
-pub fn segment(args: &ArgMatches) -> Segment {
+pub fn segment(args: &ArgMatches) -> Option<Segment> {
const PROMPT_CHAR: &str = "➜";
const COLOR_SUCCESS: Color = Color::Green;
const COLOR_FAILURE: Color = Color::Red;
@@ -23,7 +23,9 @@ pub fn segment(args: &ArgMatches) -> Segment {
segment.set_style(COLOR_FAILURE);
};
- segment.set_value(PROMPT_CHAR).clone()
+ segment.set_value(PROMPT_CHAR).set_prefix(None);
+
+ Some(segment)
}
#[cfg(test)]
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index 6ea6f71c3..d62a41f67 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -15,7 +15,7 @@ use std::path::Path;
///
/// **Truncation**
/// Paths will be limited in length to `3` path components by default.
-pub fn segment(_: &ArgMatches) -> Segment {
+pub fn segment(_: &ArgMatches) -> Option<Segment> {
const HOME_SYMBOL: &str = "~";
const DIR_TRUNCATION_LENGTH: usize = 3;
const SECTION_COLOR: Color = Color::Cyan;
@@ -44,8 +44,9 @@ pub fn segment(_: &ArgMatches) -> Segment {
segment
.set_value(truncated_dir_string)
- .set_style(SECTION_COLOR.bold())
- .clone()
+ .set_style(SECTION_COLOR.bold());
+
+ Some(segment)
}
/// Get the root directory of a git repo
diff --git a/src/modules/line_break.rs b/src/modules/line_break.rs
index c0c79ea4c..ed8b5023d 100644
--- a/src/modules/line_break.rs
+++ b/src/modules/line_break.rs
@@ -2,10 +2,15 @@ use super::Segment;
use clap::ArgMatches;
/// Creates a segment for the line break
-pub fn segment(_: &ArgMatches) -> Segment {
+pub fn segment(_: &ArgMatches) -> Option<Segment> {
const LINE_ENDING: &str = "\n";
let mut segment = Segment::new("line_break");
- segment.set_value(LINE_ENDING).clone()
+ segment
+ .set_value(LINE_ENDING)
+ .set_prefix(None)
+ .set_suffix(None);
+
+ Some(segment)
}
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index 42620db9f..6fc14d1bf 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -9,7 +9,7 @@ use clap::ArgMatches;
// pub static current_dir: PathBuf = env::current_dir().expect("Unable to identify current directory");
// TODO: Currently gets the physical directory. Get the logical directory.
-pub fn handle(module: &str, args: &ArgMatches) -> Segment {
+pub fn handle(module: &str, args: &ArgMatches) -> Option<Segment> {
match module {
"dir" | "directory" => directory::segment(&args),
"char" | "character" => character::segment(&args),
diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs
index 67032b407..e7a3e736f 100644
--- a/src/modules/nodejs.rs
+++ b/src/modules/nodejs.rs
@@ -11,7 +11,7 @@ use std::process::Command;
/// - Current directory contains a `.js` file
/// - Current directory contains a `node_modules` directory
/// - Current directory contains a `package.json` file
-pub fn segment(_: &ArgMatches) -> Segment {
+pub fn segment(_: &ArgMatches) -> Option<Segment> {
const NODE_CHAR: &str = "⬢";
const SECTION_COLOR: Color = Color::Green;
@@ -22,7 +22,7 @@ pub fn segment(_: &ArgMatches) -> Segment {
// Early return if there are no JS project files
let is_js_project = files.filter_map(Result::ok).any(has_js_files);
if !is_js_project {
- return segment;
+ return None;
}
match Command::new("node").arg("--version").output() {
@@ -31,11 +31,12 @@ pub fn segment(_: &ArgMatches) -> Segment {
segment.set_value(format!("{} {}", NODE_CHAR, version.trim()))
}
Err(_) => {
- return segment;
+ return None;
}
};
- segment.set_style(SECTION_COLOR).clone()
+ segment.set_style(SECTION_COLOR);
+ Some(segment)
}
fn has_js_files(dir_entry: DirEntry) -> bool {