summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-04-12 17:49:20 -0400
committerMatan Kushner <hello@matchai.me>2019-04-12 17:49:20 -0400
commitd82ebc4457adefcd9ad45c4d3d6d611c28d80cc3 (patch)
tree1b110727e2857bb3101ffd60ab8b881eb5c2cdc5 /src/modules
parent7356faaec2cdb99abd662f33d716ab6387d4f48f (diff)
Add builder pattern for segment
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/character.rs4
-rw-r--r--src/modules/mod.rs27
-rw-r--r--src/modules/nodejs.rs2
3 files changed, 5 insertions, 28 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs
index 4c83c5096..98b9b254e 100644
--- a/src/modules/character.rs
+++ b/src/modules/character.rs
@@ -15,8 +15,10 @@ pub fn segment(args: &ArgMatches) -> Segment {
const COLOR_SUCCESS: Color = Color::Green;
const COLOR_FAILURE: Color = Color::Red;
+ let segment = Segment::new("char");
+
let color = if args.value_of("status_code").unwrap() == "0" {
- COLOR_SUCCESS
+ segment.set_style(COLOR_SUCCESS);
} else {
COLOR_FAILURE
};
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index 5fa37593e..42620db9f 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -3,37 +3,12 @@ mod directory;
mod line_break;
mod nodejs;
-use ansi_term::Style;
+use crate::segment::Segment;
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 struct Segment {
- pub style: Style,
- pub value: String,
- pub prefix: Option<Box<Segment>>,
- pub suffix: Option<Box<Segment>>,
-}
-
-impl Default for Segment {
- fn default() -> Segment {
- let default_suffix = Some(Box::new(Segment {
- style: Style::default(),
- value: String::from(" "),
- prefix: None,
- suffix: None,
- }));
-
- Segment {
- style: Style::default(),
- value: String::from(""),
- prefix: None,
- suffix: default_suffix,
- }
- }
-}
-
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
match module {
"dir" | "directory" => directory::segment(&args),
diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs
index 87a1e4a25..a0b4162c0 100644
--- a/src/modules/nodejs.rs
+++ b/src/modules/nodejs.rs
@@ -6,7 +6,7 @@ use std::fs::{self, DirEntry};
use std::process::Command;
/// Creates a segment with the current Node.js version
-///
+///
/// Will display the Node.js version if any of the following criteria are met:
/// - Current directory contains a `.js` file
/// - Current directory contains a `node_modules` directory