Skip to content

Sticky follow#2021

Merged
BenBE merged 2 commits into
htop-dev:mainfrom
BenBE:sticky-follow
Jun 11, 2026
Merged

Sticky follow#2021
BenBE merged 2 commits into
htop-dev:mainfrom
BenBE:sticky-follow

Conversation

@BenBE

@BenBE BenBE commented Jun 3, 2026

Copy link
Copy Markdown
Member

This PR is two parts:

  • The first commit restores the old scroll/pan behavior even while in Follow mode
  • The second commit introduces a setting to toggle between a sticky follow (only exit follow mode with Shift+F) and the old behavior (exit follow mode also when moving the cursor up/down).

When merging, either merge just the first commit OR merge both commits.

@BenBE BenBE added this to the 3.6.0 milestone Jun 3, 2026
@BenBE BenBE requested a review from fasterit June 3, 2026 21:52
@BenBE BenBE added documentation 📖 Improvements or additions to documentation needs-discussion 🤔 Changes need to be discussed and require consent feature request Completely new feature requested labels Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary

Adds 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

  • Settings.h / Settings.c: new bool stickyFollow field; read/write to config; default true.
  • MainPanel.c: movement keys (KEY_UP, KEY_DOWN, KEY_PPAGE, KEY_NPAGE) clear following when table is following and stickyFollow is false.
  • DisplayOptionsPanel.c: new "Sticky follow" checkbox bound to settings->stickyFollow.
  • htop.1.in: manpage updated to document both behaviors.

Implementation quality

Clean, 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 structure

Repository 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.

Walkthrough

This PR introduces a boolean setting stickyFollow (default true), adds it to Settings_ with config read/write support, exposes it as a "Sticky follow" checkbox in the Display options panel, updates MainPanel_eventHandler to clear following and set selection focus when navigation keys are used while sticky follow is off, and documents the behavior in the man page.

Poem

A cursor that lingers, steady and still,
Or freed by a keystroke when you choose the will.
A box to bind the gaze or let it roam,
Up and Down decide if follow stays home.
Toggle once, and guide where the view calls home.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fasterit fasterit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fasterit

fasterit commented Jun 3, 2026

Copy link
Copy Markdown
Member

@natoscott Please chime in: A new setting or just revert to the old behavior?
(see discussion IRC for rationales)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 98be31b and aa97995.

📒 Files selected for processing (5)
  • DisplayOptionsPanel.c
  • MainPanel.c
  • Settings.c
  • Settings.h
  • htop.1.in

@fasterit

fasterit commented Jun 4, 2026

Copy link
Copy Markdown
Member

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa97995 and 92e7f56.

📒 Files selected for processing (5)
  • DisplayOptionsPanel.c
  • MainPanel.c
  • Settings.c
  • Settings.h
  • htop.1.in

Comment thread htop.1.in Outdated
@natoscott

Copy link
Copy Markdown
Member

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c5978c and 87c2f29.

📒 Files selected for processing (5)
  • DisplayOptionsPanel.c
  • MainPanel.c
  • Settings.c
  • Settings.h
  • htop.1.in

Comment thread htop.1.in
Comment on lines +278 to +281
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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 -50

Repository: 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 || true

Repository: 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.c

Repository: htop-dev/htop

Length of output: 7516


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n "following\s*=\s*-1" MainPanel.c

Repository: 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.c

Repository: 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 -200

Repository: 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 || true

Repository: 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 || true

Repository: 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.c

Repository: htop-dev/htop

Length of output: 39


Clarify sticky-follow “movement keys” list in htop.1.in

  • In MainPanel.c, when stickyFollow is off, following is cleared (exit follow) only for KEY_UP, KEY_DOWN, KEY_PPAGE (PgUp), and KEY_NPAGE (PgDown); Home/End are 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 Esc exits follow regardless of stickyFollow).

@BenBE BenBE merged commit 3896cb8 into htop-dev:main Jun 11, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📖 Improvements or additions to documentation feature request Completely new feature requested needs-discussion 🤔 Changes need to be discussed and require consent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants