summaryrefslogtreecommitdiff
path: root/src/watch/state.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-10-26 16:53:07 +0200
committermo8it <mo8it@proton.me>2024-10-26 16:55:15 +0200
commite8c2a79516192761283f41acc68744e91a34d6b4 (patch)
treee43fe8258ecea662de3c472bd46b79228bd08cd9 /src/watch/state.rs
parentea85c1b46e4c608f84cfb9d69c7b127c52fdc1a9 (diff)
Deduplicate code for printing keys
Diffstat (limited to 'src/watch/state.rs')
-rw-r--r--src/watch/state.rs38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/watch/state.rs b/src/watch/state.rs
index 0ac758c..47978ab 100644
--- a/src/watch/state.rs
+++ b/src/watch/state.rs
@@ -177,39 +177,25 @@ impl<'a> WatchState<'a> {
stdout.write_all(b" / ")?;
}
- if self.manual_run {
+ let mut show_key = |key, postfix| {
stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"r")?;
+ stdout.write_all(&[key])?;
stdout.queue(ResetColor)?;
- stdout.write_all(b":run / ")?;
+ stdout.write_all(postfix)
+ };
+
+ if self.manual_run {
+ show_key(b'r', b":run / ")?;
}
if !self.show_hint {
- stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"h")?;
- stdout.queue(ResetColor)?;
- stdout.write_all(b":hint / ")?;
+ show_key(b'h', b":hint / ")?;
}
- stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"l")?;
- stdout.queue(ResetColor)?;
- stdout.write_all(b":list / ")?;
-
- stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"c")?;
- stdout.queue(ResetColor)?;
- stdout.write_all(b":check all / ")?;
-
- stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"x")?;
- stdout.queue(ResetColor)?;
- stdout.write_all(b":reset / ")?;
-
- stdout.queue(SetAttribute(Attribute::Bold))?;
- stdout.write_all(b"q")?;
- stdout.queue(ResetColor)?;
- stdout.write_all(b":quit ? ")?;
+ show_key(b'l', b":list / ")?;
+ show_key(b'c', b":check all / ")?;
+ show_key(b'x', b":reset / ")?;
+ show_key(b'q', b":quit ? ")?;
stdout.flush()
}