Skip to content

Commit aa180bb

Browse files
committed
Fix separator algorithm.
Earlier, separator was appended even when no truncation needed to be performed. Fixing this required a complete rewrite of the separator logic.
1 parent f02c8d8 commit aa180bb

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "roller"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
authors = ["Kabir Goel <[email protected]>"]
55

66
[dependencies]

src/main.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ fn open_loop(interval: time::Duration,
7272
loop {
7373
match input() {
7474
Ok(val) => {
75-
let mut val = val.clone();
76-
val.push_str(&separator);
7775
tx.send(val).unwrap();
7876
},
7977
Err(_) => break
@@ -84,13 +82,20 @@ fn open_loop(interval: time::Duration,
8482
let mut string = String::new();
8583
let mut i: f64 = 0f64;
8684
while i < count {
87-
thread::sleep(interval);
88-
89-
if truncate && truncate_len >= string.len() {
90-
string = rx.try_recv().unwrap_or(string);
91-
} else {
92-
string = rx.try_recv().unwrap_or(roll1(string, reverse));
85+
match rx.try_recv() {
86+
Ok(val) => {
87+
string = val;
88+
if (truncate && truncate_len < string.len()) || !truncate {
89+
string.push_str(&separator);
90+
}
91+
},
92+
Err(_) => {
93+
if (truncate && truncate_len < string.len()) || !truncate {
94+
string = roll1(string, reverse);
95+
}
96+
},
9397
}
98+
9499
let mut modified_string = string.clone();
95100

96101
if truncate {
@@ -105,14 +110,15 @@ fn open_loop(interval: time::Duration,
105110
}
106111

107112
i += 1f64;
113+
thread::sleep(interval);
108114
}
109115

110116
inp_thread.join().unwrap();
111117
}
112118

113119
fn main() {
114120
let args = App::new("Roller")
115-
.version("1.0.0")
121+
.version(env!("CARGO_PKG_VERSION"))
116122
.author("Kabir Goel <[email protected]>")
117123
.about("Truncate text by rolling it like a news ticker.")
118124
.arg(Arg::with_name("interval")

0 commit comments

Comments
 (0)