Skip to content

Commit e8c2a79

Browse files
committed
Deduplicate code for printing keys
1 parent ea85c1b commit e8c2a79

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

src/watch/state.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,39 +177,25 @@ impl<'a> WatchState<'a> {
177177
stdout.write_all(b" / ")?;
178178
}
179179

180-
if self.manual_run {
180+
let mut show_key = |key, postfix| {
181181
stdout.queue(SetAttribute(Attribute::Bold))?;
182-
stdout.write_all(b"r")?;
182+
stdout.write_all(&[key])?;
183183
stdout.queue(ResetColor)?;
184-
stdout.write_all(b":run / ")?;
184+
stdout.write_all(postfix)
185+
};
186+
187+
if self.manual_run {
188+
show_key(b'r', b":run / ")?;
185189
}
186190

187191
if !self.show_hint {
188-
stdout.queue(SetAttribute(Attribute::Bold))?;
189-
stdout.write_all(b"h")?;
190-
stdout.queue(ResetColor)?;
191-
stdout.write_all(b":hint / ")?;
192+
show_key(b'h', b":hint / ")?;
192193
}
193194

194-
stdout.queue(SetAttribute(Attribute::Bold))?;
195-
stdout.write_all(b"l")?;
196-
stdout.queue(ResetColor)?;
197-
stdout.write_all(b":list / ")?;
198-
199-
stdout.queue(SetAttribute(Attribute::Bold))?;
200-
stdout.write_all(b"c")?;
201-
stdout.queue(ResetColor)?;
202-
stdout.write_all(b":check all / ")?;
203-
204-
stdout.queue(SetAttribute(Attribute::Bold))?;
205-
stdout.write_all(b"x")?;
206-
stdout.queue(ResetColor)?;
207-
stdout.write_all(b":reset / ")?;
208-
209-
stdout.queue(SetAttribute(Attribute::Bold))?;
210-
stdout.write_all(b"q")?;
211-
stdout.queue(ResetColor)?;
212-
stdout.write_all(b":quit ? ")?;
195+
show_key(b'l', b":list / ")?;
196+
show_key(b'c', b":check all / ")?;
197+
show_key(b'x', b":reset / ")?;
198+
show_key(b'q', b":quit ? ")?;
213199

214200
stdout.flush()
215201
}

0 commit comments

Comments
 (0)