Skip to content

Commit 30bdaa6

Browse files
authored
feature: add full command to process widget
This PR adds the ability to toggle between the process name and process path. Currently, this uses `P` as the modifier key. Currently, the longer command names are dealt with by forcefully changing the width of the columns, but this can be handled in a more graceful manner IMO.
1 parent d212905 commit 30bdaa6

File tree

14 files changed

+334
-211
lines changed

14 files changed

+334
-211
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
"Nonexhaustive",
99
"Qudsi",
1010
"Tebibytes",
11+
"Ungrouped",
1112
"Wojnarowski",
1213
"andys",
1314
"crossterm",
1415
"curr",
16+
"czvf",
1517
"gotop",
1618
"gtop",
19+
"haase",
1720
"heim",
1821
"hjkl",
1922
"markdownlint",

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ Run using `btm`.
206206

207207
#### Process bindings
208208

209-
| | |
210-
| ------------- | ---------------------------------------------------------- |
211-
| `dd` | Kill the selected process |
212-
| `c` | Sort by CPU usage, press again to reverse sorting order |
213-
| `m` | Sort by memory usage, press again to reverse sorting order |
214-
| `p` | Sort by PID name, press again to reverse sorting order |
215-
| `n` | Sort by process name, press again to reverse sorting order |
216-
| `Tab` | Group/un-group processes with the same name |
217-
| `Ctrl-f`, `/` | Open process search widget |
209+
| | |
210+
| ------------- | ------------------------------------------------------------- |
211+
| `dd` | Kill the selected process |
212+
| `c` | Sort by CPU usage, press again to reverse sorting order |
213+
| `m` | Sort by memory usage, press again to reverse sorting order |
214+
| `p` | Sort by PID name, press again to reverse sorting order |
215+
| `n` | Sort by process name, press again to reverse sorting order |
216+
| `Tab` | Group/un-group processes with the same name |
217+
| `Ctrl-f`, `/` | Open process search widget |
218+
| `P` | Toggle between showing the full path or just the process name |
218219

219220
#### Process search bindings
220221

@@ -551,6 +552,7 @@ Thanks to all contributors ([emoji key](https://allcontributors.org/docs/en/emoj
551552

552553
<!-- markdownlint-enable -->
553554
<!-- prettier-ignore-end -->
555+
554556
<!-- ALL-CONTRIBUTORS-LIST:END -->
555557

556558
## Thanks

src/app.rs

+56-48
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ impl App {
149149
BottomWidgetType::Proc => {
150150
if let Some(current_proc_state) = self
151151
.proc_state
152-
.widget_states
153-
.get_mut(&self.current_widget.widget_id)
152+
.get_mut_widget_state(self.current_widget.widget_id)
154153
{
155154
if current_proc_state.is_search_enabled() {
156155
current_proc_state
@@ -164,8 +163,7 @@ impl App {
164163
BottomWidgetType::ProcSearch => {
165164
if let Some(current_proc_state) = self
166165
.proc_state
167-
.widget_states
168-
.get_mut(&(self.current_widget.widget_id - 1))
166+
.get_mut_widget_state(self.current_widget.widget_id - 1)
169167
{
170168
if current_proc_state.is_search_enabled() {
171169
current_proc_state
@@ -243,8 +241,7 @@ impl App {
243241
BottomWidgetType::Cpu => {
244242
if let Some(cpu_widget_state) = self
245243
.cpu_state
246-
.widget_states
247-
.get_mut(&self.current_widget.widget_id)
244+
.get_mut_widget_state(self.current_widget.widget_id)
248245
{
249246
cpu_widget_state.is_multi_graph_mode =
250247
!cpu_widget_state.is_multi_graph_mode;
@@ -253,8 +250,7 @@ impl App {
253250
BottomWidgetType::Proc => {
254251
if let Some(proc_widget_state) = self
255252
.proc_state
256-
.widget_states
257-
.get_mut(&self.current_widget.widget_id)
253+
.get_mut_widget_state(self.current_widget.widget_id)
258254
{
259255
// Toggles process widget grouping state
260256
proc_widget_state.is_grouped = !(proc_widget_state.is_grouped);
@@ -285,8 +281,7 @@ impl App {
285281
// Toggle on
286282
if let Some(proc_widget_state) = self
287283
.proc_state
288-
.widget_states
289-
.get_mut(&self.current_widget.widget_id)
284+
.get_mut_widget_state(self.current_widget.widget_id)
290285
{
291286
proc_widget_state
292287
.process_search_state
@@ -500,12 +495,20 @@ impl App {
500495
pub fn on_left_key(&mut self) {
501496
if !self.is_in_dialog() {
502497
match self.current_widget.widget_type {
498+
BottomWidgetType::Proc => {
499+
if let Some(proc_widget_state) = self
500+
.proc_state
501+
.get_mut_widget_state(self.current_widget.widget_id)
502+
{
503+
proc_widget_state.current_column_index =
504+
proc_widget_state.current_column_index.saturating_sub(1);
505+
}
506+
}
503507
BottomWidgetType::ProcSearch => {
504508
let is_in_search_widget = self.is_in_search_widget();
505509
if let Some(proc_widget_state) = self
506510
.proc_state
507-
.widget_states
508-
.get_mut(&(self.current_widget.widget_id - 1))
511+
.get_mut_widget_state(self.current_widget.widget_id - 1)
509512
{
510513
if is_in_search_widget {
511514
let prev_cursor = proc_widget_state.get_cursor_position();
@@ -533,8 +536,7 @@ impl App {
533536
if !self.canvas_data.battery_data.is_empty() {
534537
if let Some(battery_widget_state) = self
535538
.battery_state
536-
.widget_states
537-
.get_mut(&self.current_widget.widget_id)
539+
.get_mut_widget_state(self.current_widget.widget_id)
538540
{
539541
if battery_widget_state.currently_selected_battery_index > 0 {
540542
battery_widget_state.currently_selected_battery_index -= 1;
@@ -552,12 +554,21 @@ impl App {
552554
pub fn on_right_key(&mut self) {
553555
if !self.is_in_dialog() {
554556
match self.current_widget.widget_type {
557+
BottomWidgetType::Proc => {
558+
if let Some(proc_widget_state) = self
559+
.proc_state
560+
.get_mut_widget_state(self.current_widget.widget_id)
561+
{
562+
if proc_widget_state.current_column_index < proc_widget_state.num_columns {
563+
proc_widget_state.current_column_index += 1;
564+
}
565+
}
566+
}
555567
BottomWidgetType::ProcSearch => {
556568
let is_in_search_widget = self.is_in_search_widget();
557569
if let Some(proc_widget_state) = self
558570
.proc_state
559-
.widget_states
560-
.get_mut(&(self.current_widget.widget_id - 1))
571+
.get_mut_widget_state(self.current_widget.widget_id - 1)
561572
{
562573
if is_in_search_widget {
563574
let prev_cursor = proc_widget_state.get_cursor_position();
@@ -586,8 +597,7 @@ impl App {
586597
let battery_count = self.canvas_data.battery_data.len();
587598
if let Some(battery_widget_state) = self
588599
.battery_state
589-
.widget_states
590-
.get_mut(&self.current_widget.widget_id)
600+
.get_mut_widget_state(self.current_widget.widget_id)
591601
{
592602
if battery_widget_state.currently_selected_battery_index
593603
< battery_count - 1
@@ -887,8 +897,7 @@ impl App {
887897
if let BottomWidgetType::Proc = self.current_widget.widget_type {
888898
if let Some(proc_widget_state) = self
889899
.proc_state
890-
.widget_states
891-
.get_mut(&self.current_widget.widget_id)
900+
.get_mut_widget_state(self.current_widget.widget_id)
892901
{
893902
match proc_widget_state.process_sorting_type {
894903
processes::ProcessSorting::CPU => {
@@ -911,8 +920,7 @@ impl App {
911920
if let BottomWidgetType::Proc = self.current_widget.widget_type {
912921
if let Some(proc_widget_state) = self
913922
.proc_state
914-
.widget_states
915-
.get_mut(&self.current_widget.widget_id)
923+
.get_mut_widget_state(self.current_widget.widget_id)
916924
{
917925
match proc_widget_state.process_sorting_type {
918926
processes::ProcessSorting::MEM => {
@@ -934,8 +942,7 @@ impl App {
934942
if let BottomWidgetType::Proc = self.current_widget.widget_type {
935943
if let Some(proc_widget_state) = self
936944
.proc_state
937-
.widget_states
938-
.get_mut(&self.current_widget.widget_id)
945+
.get_mut_widget_state(self.current_widget.widget_id)
939946
{
940947
// Skip if grouped
941948
if !proc_widget_state.is_grouped {
@@ -956,21 +963,32 @@ impl App {
956963
}
957964
}
958965
}
966+
'P' => {
967+
if let BottomWidgetType::Proc = self.current_widget.widget_type {
968+
if let Some(proc_widget_state) = self
969+
.proc_state
970+
.get_mut_widget_state(self.current_widget.widget_id)
971+
{
972+
proc_widget_state.is_using_full_path =
973+
!proc_widget_state.is_using_full_path;
974+
self.proc_state.force_update = Some(self.current_widget.widget_id);
975+
}
976+
}
977+
}
959978
'n' => {
960979
if let BottomWidgetType::Proc = self.current_widget.widget_type {
961980
if let Some(proc_widget_state) = self
962981
.proc_state
963-
.widget_states
964-
.get_mut(&self.current_widget.widget_id)
982+
.get_mut_widget_state(self.current_widget.widget_id)
965983
{
966984
match proc_widget_state.process_sorting_type {
967-
processes::ProcessSorting::NAME => {
985+
processes::ProcessSorting::IDENTIFIER => {
968986
proc_widget_state.process_sorting_reverse =
969987
!proc_widget_state.process_sorting_reverse
970988
}
971989
_ => {
972990
proc_widget_state.process_sorting_type =
973-
processes::ProcessSorting::NAME;
991+
processes::ProcessSorting::IDENTIFIER;
974992
proc_widget_state.process_sorting_reverse = false;
975993
}
976994
}
@@ -1371,8 +1389,7 @@ impl App {
13711389
if let Some(new_widget) = self.widget_map.get(&new_widget_id) {
13721390
if let Some(proc_widget_state) = self
13731391
.proc_state
1374-
.widget_states
1375-
.get(&self.current_widget.widget_id)
1392+
.get_widget_state(self.current_widget.widget_id)
13761393
{
13771394
if proc_widget_state.is_search_enabled() {
13781395
self.current_widget = new_widget.clone();
@@ -1393,8 +1410,7 @@ impl App {
13931410
BottomWidgetType::Proc => {
13941411
if let Some(proc_widget_state) = self
13951412
.proc_state
1396-
.widget_states
1397-
.get_mut(&self.current_widget.widget_id)
1413+
.get_mut_widget_state(self.current_widget.widget_id)
13981414
{
13991415
proc_widget_state.scroll_state.current_scroll_position = 0;
14001416
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
@@ -1403,8 +1419,7 @@ impl App {
14031419
BottomWidgetType::Temp => {
14041420
if let Some(temp_widget_state) = self
14051421
.temp_state
1406-
.widget_states
1407-
.get_mut(&self.current_widget.widget_id)
1422+
.get_mut_widget_state(self.current_widget.widget_id)
14081423
{
14091424
temp_widget_state.scroll_state.current_scroll_position = 0;
14101425
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
@@ -1413,8 +1428,7 @@ impl App {
14131428
BottomWidgetType::Disk => {
14141429
if let Some(disk_widget_state) = self
14151430
.disk_state
1416-
.widget_states
1417-
.get_mut(&self.current_widget.widget_id)
1431+
.get_mut_widget_state(self.current_widget.widget_id)
14181432
{
14191433
disk_widget_state.scroll_state.current_scroll_position = 0;
14201434
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
@@ -1423,8 +1437,7 @@ impl App {
14231437
BottomWidgetType::CpuLegend => {
14241438
if let Some(cpu_widget_state) = self
14251439
.cpu_state
1426-
.widget_states
1427-
.get_mut(&(self.current_widget.widget_id - 1))
1440+
.get_mut_widget_state(self.current_widget.widget_id - 1)
14281441
{
14291442
cpu_widget_state.scroll_state.current_scroll_position = 0;
14301443
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
@@ -1445,8 +1458,7 @@ impl App {
14451458
BottomWidgetType::Proc => {
14461459
if let Some(proc_widget_state) = self
14471460
.proc_state
1448-
.widget_states
1449-
.get_mut(&self.current_widget.widget_id)
1461+
.get_mut_widget_state(self.current_widget.widget_id)
14501462
{
14511463
if let Some(finalized_process_data) = self
14521464
.canvas_data
@@ -1465,8 +1477,7 @@ impl App {
14651477
BottomWidgetType::Temp => {
14661478
if let Some(temp_widget_state) = self
14671479
.temp_state
1468-
.widget_states
1469-
.get_mut(&self.current_widget.widget_id)
1480+
.get_mut_widget_state(self.current_widget.widget_id)
14701481
{
14711482
if !self.canvas_data.temp_sensor_data.is_empty() {
14721483
temp_widget_state.scroll_state.current_scroll_position =
@@ -1478,8 +1489,7 @@ impl App {
14781489
BottomWidgetType::Disk => {
14791490
if let Some(disk_widget_state) = self
14801491
.disk_state
1481-
.widget_states
1482-
.get_mut(&self.current_widget.widget_id)
1492+
.get_mut_widget_state(self.current_widget.widget_id)
14831493
{
14841494
if !self.canvas_data.disk_data.is_empty() {
14851495
disk_widget_state.scroll_state.current_scroll_position =
@@ -1491,8 +1501,7 @@ impl App {
14911501
BottomWidgetType::CpuLegend => {
14921502
if let Some(cpu_widget_state) = self
14931503
.cpu_state
1494-
.widget_states
1495-
.get_mut(&(self.current_widget.widget_id - 1))
1504+
.get_mut_widget_state(self.current_widget.widget_id - 1)
14961505
{
14971506
let cap = self.canvas_data.cpu_data.len();
14981507
if cap > 0 {
@@ -1564,8 +1573,7 @@ impl App {
15641573
fn change_process_position(&mut self, num_to_change_by: i64) {
15651574
if let Some(proc_widget_state) = self
15661575
.proc_state
1567-
.widget_states
1568-
.get_mut(&self.current_widget.widget_id)
1576+
.get_mut_widget_state(self.current_widget.widget_id)
15691577
{
15701578
let current_posn = proc_widget_state.scroll_state.current_scroll_position;
15711579

0 commit comments

Comments
 (0)