summaryrefslogtreecommitdiffstats
path: root/src/segment.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-04-15 11:40:18 -0400
committerMatan Kushner <hello@matchai.me>2019-04-15 11:40:40 -0400
commitbca4a7079f0bd663b8cc4584dc92388ce6799c1f (patch)
tree57891c9b1af75e907300535312bb883ac3185c99 /src/segment.rs
parent71cac5bd1fb09909dde64bbcf3ee4a31fb29be4f (diff)
Fix bug in path truncation
Paths with 3 components would truncate to 2 despite the truncation length begin set to 3.
Diffstat (limited to 'src/segment.rs')
-rw-r--r--src/segment.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/segment.rs b/src/segment.rs
index a9a188f62..a56e1bf82 100644
--- a/src/segment.rs
+++ b/src/segment.rs
@@ -76,8 +76,37 @@ impl Segment {
/// Create a string with the formatted contents of a segment
///
/// Will recursively also format the prefix and suffix of the segment being
- /// stringified. Skips the prefix of the first segment.
- pub fn output(&self, index: usize) -> String {
+ /// stringified.
+ pub fn output(&self) -> String {
+ let Segment {
+ name: _name,
+ prefix,
+ value,
+ style,
+ suffix,
+ } = self;
+
+ let mut segment_string = String::new();
+
+ // Skip the prefix for the first segment
+ if let Some(prefix) = prefix {
+ segment_string += &prefix.output()
+ }
+
+ segment_string += &style.paint(value).to_string();
+
+ if let Some(suffix) = suffix {
+ segment_string += &suffix.output();
+ }
+
+ segment_string
+ }
+
+ /// Create a string with the formatted contents of a segment while skipping the first segment.
+ ///
+ /// Will recursively also format the prefix and suffix of the segment being
+ /// stringified.
+ pub fn output_index(&self, index: usize) -> String {
let Segment {
name: _name,
prefix,
@@ -91,14 +120,14 @@ impl Segment {
// Skip the prefix for the first segment
if index != 0 {
if let Some(prefix) = prefix {
- segment_string += &prefix.output(index)
+ segment_string += &prefix.output_index(index)
}
}
segment_string += &style.paint(value).to_string();
if let Some(suffix) = suffix {
- segment_string += &suffix.output(index);
+ segment_string += &suffix.output();
}
segment_string