Sticky follow#2021
Conversation
📝 WalkthroughSummaryAdds a configurable "sticky follow" mode for Follow behavior. Default is enabled: Follow remains active during cursor navigation and only toggles with Shift+F. When disabled, movement keys (Up/Down/PgUp/PgDn) exit Follow immediately. Changes
Implementation qualityClean, minimal, and well-integrated. The setting threads through the config, UI, and runtime check simply and directly. Behavior change is narrowly scoped and uses existing follow state without introducing extra control flags. Commit structureRepository contains a single commit ("Introduce sticky_follow setting") that implements both the restored unfollow-on-movement behavior and the new setting/UI/docs. The PR description suggested two commits (one to restore old behavior, one to add the setting); those were not split in the current history. A split into two commits would make it easier for maintainers to merge only the restore or both, as the PR text indicates. WalkthroughThis PR introduces a boolean setting Poem
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 |
|
@natoscott Please chime in: A new setting or just revert to the old behavior? |
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: a3d3a512-2075-42e5-9aec-affbd128589d
📒 Files selected for processing (5)
DisplayOptionsPanel.cMainPanel.cSettings.cSettings.hhtop.1.in
|
Just noticing commit 1 is incomplete. The movement keys include PgUp, PgDn etc. as well. Thanks 🐇. Check bbec22d where I deliberately changed the Follow function for where to do this better (MainPanel.c), respect HTOP_KEEP_FOLLOWING. Juuust... if you still can't get used to the new way of doing things™. 😄 |
Reacts to ArrowUp/ArrowDown/PgUp/PgDown Assisted-by: Raptor mini
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: de1b30ca-7bd1-4625-8437-7470f7d96b22
📒 Files selected for processing (5)
DisplayOptionsPanel.cMainPanel.cSettings.cSettings.hhtop.1.in
|
I think its fine to add a setting, as different people may have preferences either way. Another possibility would be to add a hotkey ('f' looks available) rather than a setting for the alternate? I'm not fussed either way though. |
This allows control over how follow mode behaves when moving the cursor: - With sticky_follow, it pans to keep the follow - Without sticky_follow, it exits follow mode and moves The default is the recently introduced new behavior that keeps the follow mode active. Assisted-by: Raptor mini
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: adec21aa-142a-484f-9bad-0ff46406d674
📒 Files selected for processing (5)
DisplayOptionsPanel.cMainPanel.cSettings.cSettings.hhtop.1.in
| When the sticky follow setting is enabled (the default), follow mode remains | ||
| active until Shift+F is pressed again. If sticky follow is disabled, pressing | ||
| movement keys like Up, Down, PgUp, and PgDown will end follow mode immediately, | ||
| while Shift+Up and Shift+Down still pan without disabling follow. |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Identify all keys that clear the following state in MainPanel.c when sticky follow is disabled
# Search for lines that conditionally clear the following state
# Look for patterns where `following` is set to false based on key events
# and find the condition checking `stickyFollow`
rg -n -B 5 -A 5 'following\s*=\s*false|following\s*=\s*0' | head -100
# Also search for key event handlers and HTOP_KEEP_FOLLOWING references
rg -n 'HTOP_KEEP_FOLLOWING|case.*KEY' MainPanel.c | head -50Repository: htop-dev/htop
Length of output: 192
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate follow-state handling and key-triggered clearing logic
rg -n "HTOP_KEEP_FOLLOWING|KEEP_FOLLOW|stickyFollow|follow(ing|Mode|Mode)|FOLLOW" MainPanel.c
# Show definitions/usage neighborhoods for HTOP_KEEP_FOLLOWING
rg -n -B 5 -A 20 "HTOP_KEEP_FOLLOWING" MainPanel.c
# Find where key events are handled; then narrow to follow-related branches
rg -n "case\s+.*KEY|handle.*Key|switch\s*\(.*key|KEY_.*FOLLOW|FOLLOW.*KEY" MainPanel.c
# Search for assignments to follow/following state (common spellings)
rg -n "following\s*[\+\-\*/]?=|following\s*=\s*(false|0)|follow(ing)?\s*=\s*(false|0)" MainPanel.c || trueRepository: htop-dev/htop
Length of output: 3053
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show follow-clearing logic with stickyFollow in MainPanel.c
sed -n '60,110p' MainPanel.c
# Show follow-clearing on ESC and any nearby key handling
sed -n '110,170p' MainPanel.c
# Identify key constants likely mapped to Up/Down/PgUp/PgDown
rg -n "KEY_UP|KEY_DOWN|KEY_PPAGE|KEY_NPAGE|KEY_PGUP|KEY_PGDN|PAGE_UP|PAGE_DOWN" MainPanel.c || true
# Print key handler areas for those constants (context)
rg -n "KEY_UP|KEY_DOWN|KEY_PPAGE|KEY_NPAGE|KEY_PGUP|KEY_PGDN" -n -B 5 -A 15 MainPanel.c || true
# Also search for any other assignments to following = -1 (full context)
rg -n "following\s*=\s*-1" -B 5 -A 20 MainPanel.cRepository: htop-dev/htop
Length of output: 7516
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "following\s*=\s*-1" MainPanel.cRepository: htop-dev/htop
Length of output: 149
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find where stickyFollow is used anywhere
rg -n "stickyFollow" .
# Find all places that clear following state
rg -n "following\s*=\s*-1" .
# Also look for other follow-clear patterns (different sentinel values or helper functions)
rg -n "Keep_Following|KEEP_FOLLOWING|following\s*==\s*-1|FOLLOWING|following\s*!=\s*-1" .Repository: htop-dev/htop
Length of output: 3319
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the follow-clearing sites in Action.c
sed -n '50,110p' Action.c
sed -n '560,640p' Action.c
# Check for HOME/END key handling anywhere in key-logic
rg -n "KEY_HOME|KEY_END" MainPanel.c Action.c Table.c
# Also see if MainPanel.c maps any other movement keys besides up/down/ppage/npage to follow clearing
rg -n "KEY_LEFT|KEY_RIGHT|KEY_HOME|KEY_END|KEY_UP|KEY_DOWN|KEY_PPAGE|KEY_NPAGE" MainPanel.cRepository: htop-dev/htop
Length of output: 4739
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the follow-clearing sites in Action.c
sed -n '60,100p' Action.c
sed -n '560,620p' Action.c
# Find how Shift modifies movement key handling in MainPanel.c (shifted key constants)
rg -n "KEY_S(UP|DOWN|LEFT|RIGHT|PPAGE|NPAGE|HOME|END)|KEY_SR|KEY_SF|SHIFT|shift" MainPanel.c || true
# Check for HOME/END key constants across key handling
rg -n "KEY_HOME|KEY_END" MainPanel.c Action.c Table.c || true
# See which key codes are bound for MainPanel movement/actions
# (look for assignments into this->keys[...])
rg -n "this->keys\[[^\]]+\]\s*=" MainPanel.c | head -200Repository: htop-dev/htop
Length of output: 3458
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "KEY_S(UP|DOWN|PPAGE|NPAGE|LEFT|RIGHT|HOME|END)" . || true
rg -n "shift.*(UP|DOWN|PPAGE|NPAGE)" MainPanel.c Action.c Table.c Settings.h Settings.c || true
rg -n "KEY_HOME|KEY_END" MainPanel.c Action.c Table.c || trueRepository: htop-dev/htop
Length of output: 433
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show all follow-clearing assignments in Action.c with surrounding context
rg -n "following\s*=\s*-1" Action.c
sed -n '1,120p' Action.c
sed -n '540,640p' Action.c
# Search for shifted movement key constants (ncurses-style)
rg -n "KEY_S(U|D|P|N|L|R)(UP|DOWN|PPAGE|NPAGE|LEFT|RIGHT)?" CRT.h MainPanel.c Action.c || true
rg -n "KEY_S(UP|DOWN|PPAGE|NPAGE|HOME|END)" . || true
# See if HOME/END are bound to anything that might affect follow
rg -n "KEY_HOME|KEY_END" MainPanel.c || true
rg -n "KEY_HOME|KEY_END" Action.c || true
rg -n "KEY_HOME|KEY_END" Table.c || trueRepository: htop-dev/htop
Length of output: 7003
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Confirm where Home/End are referenced in the relevant key-handling code
rg -n "KEY_HOME|KEY_END" MainPanel.c Action.c Table.c
# Check if Home/End ever lead to clearing follow (following = -1) in those files
rg -n "KEY_HOME|KEY_END" MainPanel.c Action.c Table.c && rg -n "following\s*=\s*-1" MainPanel.c Action.c Table.c
# Look for ncurses-style Shift key constants for Up/Down/PageUp/PageDown
rg -n "KEY_S(U|D|P|N|L|R)" CRT.h
rg -n "KEY_S(U|D|P|N)(UP|DOWN|PPAGE|NPAGE)" CRT.h
# Also see if KEY_S*UP/DOWN/etc are bound in MainPanel key map
rg -n "KEY_S(U|D|P|N)(UP|DOWN|PPAGE|NPAGE)" MainPanel.cRepository: htop-dev/htop
Length of output: 39
Clarify sticky-follow “movement keys” list in htop.1.in
- In
MainPanel.c, whenstickyFollowis off,followingis cleared (exit follow) only forKEY_UP,KEY_DOWN,KEY_PPAGE(PgUp), andKEY_NPAGE(PgDown);Home/Endare not included in that clear condition. - The man page wording should avoid implying there are other movement keys by removing “like” (optionally, note separately that
Escexits follow regardless ofstickyFollow).
This PR is two parts:
When merging, either merge just the first commit OR merge both commits.