Skip to content

Action/InfoScreen: replace octal character literals with key constants - #2093

Open
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:code-refactor
Open

Action/InfoScreen: replace octal character literals with key constants#2093
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:code-refactor

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

Replace raw octal character escapes '\014' and '\177' with standard KEY_CTRL('L') and KEY_DEL_MAC / KEY_BACKSPACE macros to improve code clarity and avoid static analyzer warnings

Replace raw octal character escapes '\014' and '\177' with standard
KEY_CTRL('L') and KEY_DEL_MAC / KEY_BACKSPACE macros to improve code
clarity and avoid static analyzer warnings
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4be34f71-c1e0-440d-ba3a-e57ec12d253b

📥 Commits

Reviewing files that changed from the base of the PR and between 19fc8c1 and 8e1071c.

📒 Files selected for processing (2)
  • Action.c
  • InfoScreen.c

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The changes replace raw octal key codes with named key macros. Action_setBindings uses KEY_CTRL('L') for redraw and binds both KEY_DEL_MAC and KEY_BACKSPACE to parent collapse. InfoScreen_run uses KEY_CTRL('L') for refresh without changing its behavior.

Suggested reviewers: fasterit

Poem

Named keys guide the way
Ctrl+L redraws the day
Backspace and Delete align
Old octal codes decline
The bindings now speak clear
And refresh paths persevere

Merge Risk: ⚪ Minimal · up to 8e107

The keyboard mappings retain their existing behavior while using clearer named constants, so no actionable merge-blocking risk remains beyond normal checks and review.


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.

Comment thread Action.c
keys['\177'] = actionCollapseIntoParent;
keys[KEY_CTRL('L')] = actionRedraw;
keys[KEY_DEL_MAC] = actionCollapseIntoParent;
keys[KEY_BACKSPACE] = actionCollapseIntoParent;

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.

AI artifact?
you replace two lines and invent one

@GermanAizek GermanAizek Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AI artifact? you replace two lines and invent one

No, this for compability with MacOS.

An additional line was added to ensure compatibility with different terminals and operating systems (cross-platform support).

Different terminal emulators handle the Backspace key press in different ways:

KEY_DEL_MAC (formerly \177): On macOS and some older UNIX terminals, pressing the Backspace key sends the ASCII code 127 (the DEL character).
Previously, the code hard-coded this specific value (the magic number \177), which meant the action might not work on other systems.

KEY_BACKSPACE: In most modern Linux/Windows terminals, the Backspace key sends the standard Backspace code (ASCII 8 or a special code from the ncurses library).

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.

KEY_BACKSPACE was not there before

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.

0dbedf9 is the introducing commit. @hishamhm ... did you mean to use for collapsing a tree segment outside of Mac keyboards as well. Like 8 years ago and nobody noticed? 😄

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.

I definitely did not take Mac keyboards into account back then... but I do remember that different Linux terminals (xterm, rxvt, konsole, the Linux textmode console, etc.) had different default settings wrt handling Backspace, and \177 was the code for Backspace in the terminal I was using back then (which might have been any of the above :) ). I think there is even an stty setting or something to configure what Backspace emits, isn't there?

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.

yes there is, stty erase <char> to set it
thank you for the info @hishamhm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's better to make a separate commit for this change for clarity.

@fasterit fasterit added question ❔ Further information is requested code quality ♻️ Code quality enhancement and removed question ❔ Further information is requested labels Aug 30, 2026
@fasterit

Copy link
Copy Markdown
Member

So backspace (on ancient Linux distros and Mac keyboard) can collapse the tree segment. We have - (Minus) and * (star, toggle all children of PIDs without parents) documented in man htop and the help screen but not the backspace. Shall we drop that binding? Or make it more available as per @GermanAizek's current commit?

@BenBE

BenBE commented Sep 5, 2026

Copy link
Copy Markdown
Member

No hard feelings to drop the backspace binding …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality ♻️ Code quality enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants