Skip to content

Commit 75e2311

Browse files
authored
Merge pull request #534 from Bluemangoo/feature/top-tui-d
top: tui impl `d`
2 parents a4449a6 + 6af80ef commit 75e2311

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/uu/top/src/tui/input.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) enum InputEvent {
2424
FilterUser,
2525
FilterEUser,
2626
WidthIncrement,
27+
Delay,
2728
}
2829

2930
macro_rules! char {
@@ -75,6 +76,14 @@ pub fn handle_input(
7576
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
7677
should_update.store(true, Ordering::Relaxed);
7778
}
79+
char!('d') => {
80+
let mut stat = tui_stat.write().unwrap();
81+
stat.input_label = format!("Change delay from {:.1} to ", stat.delay.as_secs_f32());
82+
stat.input_value.clear();
83+
stat.input_mode = InputMode::Input(InputEvent::Delay);
84+
85+
should_update.store(true, Ordering::Relaxed);
86+
}
7887
char!('I') => {
7988
{
8089
let mut stat = tui_stat.write().unwrap();
@@ -415,5 +424,23 @@ fn handle_input_value(
415424
stat.reset_input();
416425
should_update.store(true, Ordering::Relaxed);
417426
}
427+
InputEvent::Delay => {
428+
let input_value = { tui_stat.read().unwrap().input_value.parse::<f32>() };
429+
if input_value.is_err() || input_value.as_ref().is_ok_and(|v| *v < 0.0) {
430+
let is_empty = { tui_stat.read().unwrap().input_value.trim().is_empty() };
431+
let mut stat = tui_stat.write().unwrap();
432+
stat.reset_input();
433+
if !is_empty {
434+
stat.input_message = Some(" Unacceptable floating point ".into());
435+
}
436+
should_update.store(true, Ordering::Relaxed);
437+
return;
438+
}
439+
let input_value = input_value.unwrap();
440+
let mut stat = tui_stat.write().unwrap();
441+
stat.delay = std::time::Duration::from_secs_f32(input_value);
442+
stat.reset_input();
443+
should_update.store(true, Ordering::Relaxed);
444+
}
418445
}
419446
}

0 commit comments

Comments
 (0)