summaryrefslogtreecommitdiffstats
path: root/src/modules/directory.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-05-01 16:34:24 -0400
committerGitHub <noreply@github.com>2019-05-01 16:34:24 -0400
commitc6ee5c6ac16d360ab1a44d097c91fe9f98f20f85 (patch)
treee06814175f34e508fbae4de66571e3d0042786e7 /src/modules/directory.rs
parentd945b03093cf130bdc702056650f7e8e8869753b (diff)
Refactor segments into modules (#40)
Diffstat (limited to 'src/modules/directory.rs')
-rw-r--r--src/modules/directory.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index d5fbc88c9..a85287a67 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -1,8 +1,7 @@
use ansi_term::Color;
use std::path::Path;
-use super::Segment;
-use crate::context::Context;
+use super::{Context, Module};
/// Creates a segment with the current directory
///
@@ -13,12 +12,14 @@ use crate::context::Context;
///
/// **Truncation**
/// Paths will be limited in length to `3` path components by default.
-pub fn segment(context: &Context) -> Option<Segment> {
+pub fn segment(context: &Context) -> Option<Module> {
const HOME_SYMBOL: &str = "~";
const DIR_TRUNCATION_LENGTH: usize = 3;
- const SEGMENT_COLOR: Color = Color::Cyan;
+ let module_color = Color::Cyan.bold();
+
+ let mut module = Module::new("directory");
+ module.set_style(module_color);
- let mut segment = Segment::new("dir");
let current_dir = &context.current_dir;
let dir_string;
@@ -37,12 +38,9 @@ pub fn segment(context: &Context) -> Option<Segment> {
// Truncate the dir string to the maximum number of path components
let truncated_dir_string = truncate(dir_string, DIR_TRUNCATION_LENGTH);
+ module.new_segment("path", truncated_dir_string);
- segment
- .set_value(truncated_dir_string)
- .set_style(SEGMENT_COLOR.bold());
-
- Some(segment)
+ Some(module)
}
/// Contract the root component of a path