Skip to content

Commit c057c9d

Browse files
authored
Merge pull request #15 from AndPuQing/agent/pi/cdee7cf3
feat: interactive KB-unit toggle and configurable columns
2 parents 25298f1 + befd761 commit c057c9d

3 files changed

Lines changed: 351 additions & 107 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,24 @@ When running in interactive mode (default), you can use the following keyboard s
157157
| `a` / `A` | Toggle between bandwidth and accumulated I/O |
158158
| `p` / `P` | Toggle between showing processes and threads |
159159
| `r` / `R` | Reverse the current sort order |
160-
| `Space` | Pause/resume display updates |
161-
| `Left` / `Right` | Cycle through sort columns |
160+
| `k` / `K` | Toggle KB units (also enabled by `-k` at startup) |
161+
| `c` / `C` | Enter/exit column-selection mode (see below) |
162+
| `Space` | Pause/resume display updates (toggle column in column mode) |
163+
| `Left` / `Right` | Cycle through sort columns (move cursor in column mode) |
162164
| `Up` / `Down` | Scroll through process list |
163165
| `PageUp` / `PageDown` | Scroll by 10 rows |
164166
| `Home` | Jump to first sort column (or first row with Ctrl) |
165167
| `End` | Jump to last sort column (or last row with Ctrl) |
166168

167169
Mouse wheel scrolling is also supported for navigating the process list.
168170

171+
### Column Selection Mode
172+
173+
Press `c` to enter column-selection mode. The top bar shows every available column;
174+
`Left` / `Right` move the cursor, `Space` toggles the selected column on/off, and
175+
`Esc` or `c` exits. Hidden columns are shown dimmed with `~` markers. The last
176+
remaining visible column cannot be hidden.
177+
169178
## Architecture
170179

171180
This implementation uses:

‎src/main.rs‎

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ async fn run_interactive_mode(process_list: &mut ProcessList, args: &Args) -> Re
179179
state.only_active = args.only;
180180
state.accumulated = args.accumulated;
181181
state.show_processes = args.processes;
182+
state.kilobytes = args.kilobytes;
182183

183184
// Start async data stream
184185
let mut data_cancel_token = CancellationToken::new();
@@ -248,8 +249,33 @@ async fn run_interactive_mode(process_list: &mut ProcessList, args: &Args) -> Re
248249
state.selection_mode = false;
249250
state.selected_row = None;
250251
}
252+
KeyCode::Char('k') | KeyCode::Char('K') => {
253+
state.kilobytes = !state.kilobytes;
254+
}
255+
KeyCode::Char('c') | KeyCode::Char('C') => {
256+
state.column_mode = !state.column_mode;
257+
if state.column_mode {
258+
// Start the cursor on the current sort column.
259+
state.column_cursor = state.sort_column;
260+
}
261+
}
251262
KeyCode::Char(' ') => {
252-
state.paused = !state.paused;
263+
if state.column_mode {
264+
// Toggle the selected column; never hide the last one.
265+
if state.visible_columns.is_visible(state.column_cursor) {
266+
if state.visible_columns.count(has_delay_acct) > 1 {
267+
state
268+
.visible_columns
269+
.set_visible(state.column_cursor, false);
270+
}
271+
} else {
272+
state
273+
.visible_columns
274+
.set_visible(state.column_cursor, true);
275+
}
276+
} else {
277+
state.paused = !state.paused;
278+
}
253279
}
254280
KeyCode::Char('p') | KeyCode::Char('P') => {
255281
state.show_processes = !state.show_processes;
@@ -269,16 +295,28 @@ async fn run_interactive_mode(process_list: &mut ProcessList, args: &Args) -> Re
269295
);
270296
}
271297
KeyCode::Left => {
272-
state.sort_column = state.sort_column.cycle_backward(has_delay_acct);
273-
state.scroll_offset = 0;
274-
state.selection_mode = false;
275-
state.selected_row = None;
298+
if state.column_mode {
299+
state.column_cursor =
300+
state.column_cursor.cycle_backward(has_delay_acct);
301+
} else {
302+
state.sort_column =
303+
state.sort_column.cycle_backward(has_delay_acct);
304+
state.scroll_offset = 0;
305+
state.selection_mode = false;
306+
state.selected_row = None;
307+
}
276308
}
277309
KeyCode::Right => {
278-
state.sort_column = state.sort_column.cycle_forward(has_delay_acct);
279-
state.scroll_offset = 0;
280-
state.selection_mode = false;
281-
state.selected_row = None;
310+
if state.column_mode {
311+
state.column_cursor =
312+
state.column_cursor.cycle_forward(has_delay_acct);
313+
} else {
314+
state.sort_column =
315+
state.sort_column.cycle_forward(has_delay_acct);
316+
state.scroll_offset = 0;
317+
state.selection_mode = false;
318+
state.selected_row = None;
319+
}
282320
}
283321
KeyCode::Up => {
284322
if !state.selection_mode {
@@ -349,6 +387,7 @@ async fn run_interactive_mode(process_list: &mut ProcessList, args: &Args) -> Re
349387
}
350388
}
351389
KeyCode::Esc => {
390+
state.column_mode = false;
352391
state.selection_mode = false;
353392
state.selected_row = None;
354393
}

0 commit comments

Comments
 (0)