Skip to content

Commit 256e034

Browse files
author
Your Name
committed
v0.2.1: priority-based column auto-hiding on narrow terminals
- Columns now auto-hide by priority when terminal is too narrow (like htop), instead of squishing the Command column first - Command, CPU%, MEM%, USER, PID have highest priority and stay visible - IO_W, IO_R, PPID, NI, PRI hide first on narrow terminals - Currently sorted column is never auto-hidden - Minimum 20 chars guaranteed for Command column - Applies to all tabs: Main, I/O, Net - Mouse header click detection updated to match rendered columns - Deduplicated HEADERS constants between mouse.rs and process_table.rs - Bump version to 0.2.1
1 parent 88062d1 commit 256e034

5 files changed

Lines changed: 194 additions & 155 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pstop"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55
description = "htop for Windows — beautiful, fast TUI system monitor with per-core CPU bars, memory/swap/network, tree view, process management, 7 color schemes, mouse support. Drop-in htop replacement for PowerShell & Windows Terminal."
66
license = "MIT"

choco/pstop.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
33
<metadata>
44
<id>pstop</id>
5-
<version>0.2.0</version>
5+
<version>0.2.1</version>
66
<title>pstop - htop for Windows</title>
77
<authors>marlocarlo</authors>
88
<owners>marlocarlo</owners>

src/mouse.rs

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crossterm::event::{MouseEvent, MouseEventKind, MouseButton};
33
use crate::app::{App, AppMode, ProcessTab};
44
use crate::system::process::ProcessSortField;
55
use crate::ui;
6+
use crate::ui::process_table::{HEADERS, IO_HEADERS, NET_HEADERS, compute_display_columns};
67

78
/// Handle a mouse event.
89
/// Requires the terminal size (columns, rows) to compute layout areas.
@@ -68,62 +69,25 @@ fn handle_tab_bar_click(app: &mut App, x: u16) {
6869

6970
// ── Header click (sort by column) ───────────────────────────────────
7071

71-
/// htop's exact default column headers and widths (mirrors process_table.rs)
72-
const HEADERS: &[(&str, u16, ProcessSortField)] = &[
73-
("PID", 7, ProcessSortField::Pid),
74-
("PPID", 7, ProcessSortField::Ppid),
75-
("USER", 9, ProcessSortField::User),
76-
("PRI", 4, ProcessSortField::Priority),
77-
("NI", 4, ProcessSortField::Nice),
78-
("VIRT", 7, ProcessSortField::VirtMem),
79-
("RES", 7, ProcessSortField::ResMem),
80-
("SHR", 7, ProcessSortField::SharedMem),
81-
("S", 2, ProcessSortField::Status),
82-
("CPU%", 6, ProcessSortField::Cpu),
83-
("MEM%", 6, ProcessSortField::Mem),
84-
("TIME+", 10, ProcessSortField::Time),
85-
("THR", 4, ProcessSortField::Threads),
86-
("IO_R", 10, ProcessSortField::IoReadRate),
87-
("IO_W", 10, ProcessSortField::IoWriteRate),
88-
("Command", 0, ProcessSortField::Command),
89-
];
90-
91-
const IO_HEADERS: &[(&str, u16, ProcessSortField)] = &[
92-
("PID", 7, ProcessSortField::Pid),
93-
("USER", 9, ProcessSortField::User),
94-
("IO", 4, ProcessSortField::Priority),
95-
("DISK R/Mv", 10, ProcessSortField::IoRate),
96-
("DISK READ", 10, ProcessSortField::IoReadRate),
97-
("DISK WRITE", 11, ProcessSortField::IoWriteRate),
98-
("SWPD%", 6, ProcessSortField::Mem),
99-
("IOD%", 6, ProcessSortField::Cpu),
100-
("Command", 0, ProcessSortField::Command),
101-
];
102-
103-
const NET_HEADERS: &[(&str, u16, ProcessSortField)] = &[
104-
("PID", 7, ProcessSortField::Pid),
105-
("USER", 9, ProcessSortField::User),
106-
("S", 2, ProcessSortField::Status),
107-
("CPU%", 6, ProcessSortField::Cpu),
108-
("IO READ", 10, ProcessSortField::IoReadRate),
109-
("IO WRITE", 10, ProcessSortField::IoWriteRate),
110-
("TOTAL IO", 10, ProcessSortField::IoRate),
111-
("MEM%", 6, ProcessSortField::Mem),
112-
("Command", 0, ProcessSortField::Command),
113-
];
114-
11572
fn handle_header_click(app: &mut App, x: u16, term_width: u16) {
116-
let headers: &[(&str, u16, ProcessSortField)] = match app.active_tab {
73+
let headers = match app.active_tab {
11774
ProcessTab::Main => HEADERS,
11875
ProcessTab::Io => IO_HEADERS,
11976
ProcessTab::Net => NET_HEADERS,
12077
};
12178

122-
// Compute column boundaries, respecting visibility (Main tab only)
79+
// Compute display columns (same logic as rendering, so clicks match)
80+
let base_visible: std::collections::HashSet<ProcessSortField> = match app.active_tab {
81+
ProcessTab::Main => app.visible_columns.clone(),
82+
_ => headers.iter().map(|(_, _, f, _)| *f).collect(),
83+
};
84+
let display_cols = compute_display_columns(headers, &base_visible, term_width, app.sort_field);
85+
86+
// Compute column boundaries, respecting auto-hidden columns
12387
let mut cursor: u16 = 0;
124-
for &(_, width, field) in headers {
125-
// On Main tab, skip hidden columns
126-
if app.active_tab == ProcessTab::Main && !app.visible_columns.contains(&field) {
88+
for &(_, width, field, _) in headers {
89+
// Skip columns not in the display set
90+
if !display_cols.contains(&field) {
12791
continue;
12892
}
12993

0 commit comments

Comments
 (0)