Keep the first N columns visible - #2099
Conversation
Closes htop-dev#2098 Assisted-by: OpenCode Zen
📝 WalkthroughWalkthroughAdds configurable sticky columns for process and I/O list screens. Users can set the count through Assessment against linked issues
Poem
Merge Risk: 🔵 Low · up to The PR adds configurable sticky columns across command-line settings and display layout. Malformed or oversized numeric values may still be accepted, the settings UI limits the count to 100, and help/manual text do not fully match the behavior; these bounded issues warrant owner follow-up but do not indicate a security or availability risk. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 165ac4f7-ea30-43ee-bebe-3005e3e3ccdc
📒 Files selected for processing (11)
CommandLine.cDisplayOptionsPanel.cMainPanel.cPanel.cPanel.hRow.cRow.hSettings.cSettings.hTable.chtop.1.in
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Assisted-by: CodeRabbitAI
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2c0ae9ef-e19d-4d77-86d2-8d6f3851cda5
📒 Files selected for processing (9)
CommandLine.cDisplayOptionsPanel.cMainPanel.cRow.cRow.hSettings.cSettings.hTable.chtop.1.in
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Assisted-by: OpenCode Zen
DLange is not convinced...
f1e9775 to
abc8116
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Team
Run ID: 2a1a8f8d-e438-4023-aad6-50efee8176fb
📒 Files selected for processing (2)
CommandLine.cRow.c
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
| if (sscanf(optarg, "%16zd", &parsed) != 1) { | ||
| fprintf(stderr, "Error: invalid value \"%s\" for --keep-visible.\n", optarg); | ||
| return STATUS_ERROR_EXIT; | ||
| } | ||
|
|
||
| if (parsed < 0) { | ||
| fprintf(stderr, "Error: --keep-visible must not be negative.\n"); | ||
| return STATUS_ERROR_EXIT; | ||
| } | ||
|
|
||
| flags->keepColumnsVisible = (size_t) parsed; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- CommandLine.c target and application path ---'
sed -n '330,490p' CommandLine.c
printf '%s\n' '--- keepColumnsVisible declarations and uses ---'
rg -n -C 3 'keepColumnsVisible|keep-visible' --glob '*.{c,h}'Repository: htop-dev/htop
Length of output: 5415
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- tracked files defining the command-line settings type ---'
git ls-files | rg '(^|/)(CommandLine|Settings|Config).*\\.(c|h)$' || true
printf '%s\n' '--- all exact references ---'
rg -n -C 3 'keepColumnsVisible|keep-visible' . || true
printf '%s\n' '--- relevant status definitions ---'
rg -n -C 3 'STATUS_ERROR_EXIT|typedef enum.*CommandLine|CommandLineStatus' CommandLine.c CommandLine.h *.h *.c 2>/dev/null || trueRepository: htop-dev/htop
Length of output: 19508
Reject partial and out-of-range values for --keep-visible.
sscanf accepts numeric prefixes, so --keep-visible=1x succeeds. Values above INT_MAX are accepted and narrowed to int before assignment to settings->keepColumnsVisible. Parse the complete argument and reject values outside 0..INT_MAX.
There was a problem hiding this comment.
@fasterit sscanf is overkill here; strtoull + errno/retval check should do just fine and gives proper error handling.
| printf("-M --no-mouse Disable the mouse\n"); | ||
| #endif | ||
| printf(" --no-meters Hide meters\n" | ||
| " --keep-visible[=N] Keep the first N columns visible when scrolling sideways (default 1)\n" |
There was a problem hiding this comment.
For simplicity, it's better to have the option argument of this mandatory. No need to document the behavior of --keep-visible (without option argument) as it's behavior is less stable than --keep-visible=1.
| } | ||
|
|
||
| if (parsed < 0) { | ||
| fprintf(stderr, "Error: --keep-visible must not be negative.\n"); |
There was a problem hiding this comment.
Error message of this may be merged with the previous one. ("Invalid value") Save at least one line of code.
| case KEY_CTRL('B'): | ||
| if (this->scrollH > 0) { | ||
| this->scrollH -= MAXIMUM(CRT_scrollHAmount, 0); | ||
| this->scrollH = MAXIMUM(this->scrollH, 0); |
There was a problem hiding this comment.
This should be cheery picked into its own commit as this is a bug fix not related to the feature.
| int nColumns = 0; | ||
| while (fields[nColumns]) | ||
| nColumns++; | ||
| if (!nColumns) |
There was a problem hiding this comment.
| if (!nColumns) | |
| if (nColumns <= 0) |
|
|
||
| for (int i = 0; fields[i]; i++) { | ||
| int color; | ||
| bool pinned = (i < pinnedCount); |
There was a problem hiding this comment.
| bool pinned = (i < pinnedCount); | |
| bool isPinned = (i < pinnedCount); |
Closes #2098
Assisted-by: OpenCode Zen