Skip to content

Conversation

@ovsrobot
Copy link
Owner

@ovsrobot ovsrobot commented Jan 5, 2026

NOTE: This is an auto submission for "cmdline: update clear screen behavior".

See "http://patchwork.dpdk.org/project/dpdk/list/?series=36957" for details.

Summary by Sourcery

Update cmdline line-editing behavior so Ctrl-L clears the screen and redraws the current prompt and input line.

Enhancements:

  • Refactor redisplay logic into an internal helper that supports optional full-screen clearing before redrawing the prompt and buffers.
  • Add a VT100 home-cursor escape sequence used when clearing and repainting the cmdline interface.

Summary by CodeRabbit

  • Refactor
    • Improved command-line screen clearing behavior to properly clear and redisplay the prompt and input buffer.

✏️ Tip: You can customize this high-level summary in your review settings.

Control+L should clear screen and redisplay prompt at the top
line. DPDK rdline library will not change anything on the screen when
fed with Control+L.  When prompt is lost after too many text written
to the terminal, users will press Control+L to clear screen and put
the prompt to the top line. This is expected behavior in bash(1) or
applications that are using readline(3). Updated to behave as users
expected.

Signed-off-by: Kerem Aksu <kerem.aksu@i2i-systems.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's Guide

Refactors the rdline redisplay logic to support a dedicated clear‑screen behavior on Ctrl‑L by introducing a reusable reprint helper that can optionally clear the terminal and by adding a new VT100 home-cursor sequence constant.

Sequence diagram for updated Ctrl_L clear screen behavior

sequenceDiagram
    participant User
    participant rdline as rdline_char_in
    participant reprint as rdline_reprint

    User->>rdline: rdline_char_in(rdl, CMDLINE_KEY_CTRL_L)
    activate rdline
    rdline->>reprint: rdline_clear_screen(rdl) -> rdline_reprint(rdl, 1)
    activate reprint
    reprint->>reprint: rdline_puts(rdl, vt100_clear_screen)
    reprint->>reprint: rdline_puts(rdl, vt100_homecursor)
    reprint->>reprint: write prompt and left buffer
    reprint->>reprint: display_right_buffer(rdl, 1)
    deactivate reprint
    deactivate rdline
Loading

Class diagram for updated rdline redisplay helpers

classDiagram
    class rdline_module {
        +rdline_char_in(rdl, c) int
        +rdline_redisplay(rdl) void
        -rdline_reprint(rdl, clear_screen) void
        -rdline_clear_screen(rdl) void
        +display_right_buffer(rdl, force) void
    }

    class vt100_constants {
        +vt100_home string
        +vt100_clear_screen string
        +vt100_homecursor string
        +vt100_word_left string
        +vt100_word_right string
    }

    rdline_module ..> vt100_constants : uses
Loading

Flow diagram for rdline_reprint clear screen logic

flowchart TD
    A[start rdline_reprint] --> B{rdl is NULL?}
    B -- yes --> C[return]
    B -- no --> D{clear_screen == 1?}
    D -- yes --> E[rdline_puts vt100_clear_screen]
    E --> F[rdline_puts vt100_homecursor]
    D -- no --> G[rdline_puts vt100_home]
    F --> H[write prompt characters]
    G --> H[write prompt characters]
    H --> I[iterate left buffer and write_char]
    I --> J["display_right_buffer(rdl, 1)"]
    J --> K[end rdline_reprint]
Loading

File-Level Changes

Change Details Files
Refactor rdline redisplay into a reusable helper that optionally clears the screen and adjust key handling to use it for Ctrl-L.
  • Replace exported rdline_redisplay implementation with an internal rdline_reprint helper that takes a clear_screen flag and handles optional vt100_clear_screen + vt100_homecursor versus vt100_home behavior.
  • Reintroduce rdline_redisplay as a thin exported wrapper that calls rdline_reprint without clearing the screen to preserve existing redisplay behavior.
  • Add a new static rdline_clear_screen helper that calls rdline_reprint with clear_screen set to clear the entire screen before redrawing the prompt and buffers.
  • Change CMDLINE_KEY_CTRL_L handling to call rdline_clear_screen and update its comment to describe clear-screen semantics instead of simple redisplay.
lib/cmdline/cmdline_rdline.c
Add a new VT100 escape sequence constant for moving the cursor to the home position.
  • Introduce vt100_homecursor macro with the "\033[H" VT100 escape sequence to be used when clearing the screen and resetting the cursor position.
lib/cmdline/cmdline_vt100.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

The changes refactor the line editing redisplay logic by introducing internal helper functions that separate screen-clearing behavior from generic redisplay. A new VT100 home-cursor escape sequence macro is added to support this refactoring.

Changes

Cohort / File(s) Summary
Line editing redisplay refactoring
lib/cmdline/cmdline_rdline.c
Introduces two static helpers: rdline_reprint() (handles reprinting with optional screen clear via parameter) and rdline_clear_screen() (delegates to reprint with clear enabled). Refactors rdline_redisplay() to call rdline_reprint(rdl, 0). Changes CTRL-L handling to invoke rdline_clear_screen() instead, enabling full-screen clear before reprinting prompt and buffer. Separates screen-clearing concern from generic redisplay without altering public API.
VT100 terminal macros
lib/cmdline/cmdline_vt100.h
Adds new macro vt100_homecursor (VT100 escape sequence \033[H] for cursor home) positioned after existing vt100_word_right. Provides terminal control support for the redisplay refactoring.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 hop hop, the prompt now clears,
A fresh screen blooms—no more screen tears!
Home-cursor dances with a leap,
CTRL-L tidies, sweeeeep, sweeeeep! 🌿✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: updating the clear screen behavior in cmdline to make Ctrl+L clear the terminal and redisplay the prompt, matching bash/readline behavior.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd60dcd and c475aef.

📒 Files selected for processing (2)
  • lib/cmdline/cmdline_rdline.c
  • lib/cmdline/cmdline_vt100.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (5)
lib/cmdline/cmdline_vt100.h (1)

41-41: LGTM! Standard VT100 sequence for cursor home positioning.

The vt100_homecursor macro correctly defines the ANSI escape sequence \033[H to move the cursor to the top-left corner (position 1,1). This is properly placed alongside other cursor positioning sequences.

lib/cmdline/cmdline_rdline.c (4)

185-206: Well-refactored consolidation of redisplay logic.

The rdline_reprint function cleanly separates full screen clearing from simple redisplay:

  • clear_screen=1: Uses vt100_clear_screen + vt100_homecursor to clear the entire terminal and move to the top-left
  • clear_screen=0: Uses vt100_home to return to the prompt line

The sequence (clear/position → prompt → left buffer → right buffer) is logically correct, and the null check is appropriately placed.


208-213: LGTM! Public API preserved with clean delegation.

The refactored rdline_redisplay maintains its exported symbol and signature while delegating to rdline_reprint(rdl, 0), which preserves the original behavior of redisplaying without clearing the entire screen.


215-219: LGTM! Clean wrapper for clear-screen behavior.

The rdline_clear_screen function provides a clear, focused interface for full screen clearing by delegating to rdline_reprint(rdl, 1). The null check is appropriately handled in the callee.


402-405: Correct implementation of Ctrl+L clear-screen behavior.

The handler now calls rdline_clear_screen instead of rdline_redisplay, which clears the entire terminal and repositions the prompt at the top. This aligns with standard bash/readline behavior as described in the commit message.

To confirm the implementation matches the expected bash/readline behavior, consider testing the following scenarios:

  • Ctrl+L clears the screen and moves the prompt to the top line
  • The current input buffer content is preserved after clearing
  • The cursor position relative to the input is maintained

You may also want to verify compatibility across common terminal emulators (xterm, VTE-based terminals, Windows Console, etc.).


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.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider using a bool (e.g., bool clear_screen) instead of an int for the clear_screen parameter in rdline_reprint to better reflect its semantics and improve readability.
  • rdline_clear_screen is a static wrapper used only once; you could call rdline_reprint(rdl, 1) directly in the CMDLINE_KEY_CTRL_L case to reduce one layer of indirection unless you expect additional callers in the near future.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider using a bool (e.g., `bool clear_screen`) instead of an `int` for the `clear_screen` parameter in `rdline_reprint` to better reflect its semantics and improve readability.
- `rdline_clear_screen` is a static wrapper used only once; you could call `rdline_reprint(rdl, 1)` directly in the `CMDLINE_KEY_CTRL_L` case to reduce one layer of indirection unless you expect additional callers in the near future.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants