Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@altsem
Copy link
Owner

@altsem altsem commented Apr 18, 2025

The goal is to inevitably switch from Ratatui, and start using Termwiz
with Termwiz widgets.

My hope is that this will clean up the UI code quite a bit,
as well as allow more features like re-interpreting terminal codes,
and perhaps using Termwiz's line editor with autocomplete for prompts.

This merely switches the "backend" of Ratatui from Crossterm to Termwiz.

TODO:

  • Test on Mac
  • Test on Windows
  • Fix: moving mouse over terminal causes a brief freeze (events being logged in gitu.log)
  • Fix: hunks turn black when selected and extending beyond terminal
    image

@altsem altsem requested a review from Copilot April 18, 2025 10:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR switches the terminal backend from Crossterm to Termwiz to simplify UI code and unlock additional terminal features. Key changes include:

  • Replacing Crossterm event and terminal APIs with Termwiz equivalents.
  • Updating tests and key parsing logic to work with Termwiz types.
  • Removing the now-unused crossterm dependency from Cargo.toml.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ui.rs Uses Termwiz for cursor positioning instead of function invocation
src/tests/helpers/ui.rs Updates event mapping to use Termwiz input events
src/term.rs Replaces Crossterm backend with Termwiz backend and related functions
src/state.rs Updates event handling and pending key storage to Termwiz types
src/prompt.rs Refactors prompt state and rendering with updated key handling
src/ops/* Updates prompt state checks to property access instead of method calls
src/main.rs Changes terminal initialization and raw mode handling
src/lib.rs Adjusts event polling and key event construction for Termwiz
src/key_parser.rs Updates parser to emit Termwiz input events and fixes key codes
src/error.rs Adds Termwiz error variant
src/bindings.rs Alters binding key types to use Termwiz modifiers and key codes
Cargo.toml Removes Crossterm and enables Termwiz support in ratatui
Comments suppressed due to low confidence (3)

src/state.rs:175

  • [nitpick] The change from 'key.code' to 'key.key' might be confusing. Consider verifying that 'key.key' clearly represents the intended key value consistent with Termwiz conventions.
self.pending_keys.push((key.modifiers, key.key));

src/key_parser.rs:94

  • [nitpick] Uppercase letters no longer apply a SHIFT modifier during parsing. If this behavior is intended, consider documenting it; otherwise, adjust the parsing logic to automatically add the SHIFT modifier for uppercase characters.
assert_eq!(parse_keys("A"), Ok(("", vec![(Modifiers::NONE, Char('A'))])));

src/ui.rs:78

  • The change from invoking cursor as a function to accessing it as a field requires verification that state.prompt.state.cursor always holds an updated tuple (u16, u16). Please confirm that this change aligns with the new design.
let (cx, cy) = state.prompt.state.cursor;

@codecov
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 49.23547% with 166 lines in your changes missing coverage. Please review.

Project coverage is 85.65%. Comparing base (d11f158) to head (11101dd).

Files with missing lines Patch % Lines
src/prompt.rs 49.29% 108 Missing ⚠️
src/term.rs 4.65% 41 Missing ⚠️
src/lib.rs 0.00% 7 Missing ⚠️
src/main.rs 0.00% 6 Missing ⚠️
src/state.rs 76.92% 3 Missing ⚠️
src/error.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##           refactor/remove-term-dep-in-state     #352      +/-   ##
=====================================================================
- Coverage                              86.67%   85.65%   -1.03%     
=====================================================================
  Files                                     66       66              
  Lines                                   6163     6356     +193     
=====================================================================
+ Hits                                    5342     5444     +102     
- Misses                                   821      912      +91     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@altsem altsem changed the base branch from master to refactor/remove-term-dep-in-state April 20, 2025 08:35
@sbillig
Copy link
Contributor

sbillig commented May 9, 2025

@altsem Working well for me on a mac!

@sbillig
Copy link
Contributor

sbillig commented May 14, 2025

@altsem I've just noticed that when I change the size of my terminal window, a redraw isn't triggered, and gitu doesn't respect the new size (in wezterm and alacritty). Resize events are logged, with correct size values. Is it working for you? If it's mac-specific, I'll try to debug it.

@altsem
Copy link
Owner Author

altsem commented May 16, 2025

@sbillig
I can replicate this resizing bug too. And do recall that it was mentioned in an example I read:
https://github.com/wezterm/wezterm/blob/909573fad98a1cccb802a7e7e1d9f4f44e02a177/termwiz/examples/widgets_basic.rs#L119-L125

I didn't manage to figure out a fix for the rendering bug.
It seems to occur when there's a style set on the bottom-most right cell of the terminal.
Bug in Ratatui?
~/.config/gitu/config.toml

[style]
selection_area.bg = "10"

One alternative is to rewrite the entire rendering code in Termwiz straight away.

@altsem
Copy link
Owner Author

altsem commented May 31, 2025

I think I'm willing to ignore that rendering bug i encountered for now, it only seems to apply if style.selection_area.bg is set.

The terminal resize bug should be fixed, but I still haven't managed to figure it out.

altsem added 5 commits June 9, 2025 21:16
The goal is to inevitably switch from Ratatui, and start using Termwiz
with Termwiz widgets.

My hope is that this will clean up the UI code quite a bit,
as well as allow more features like re-interpreting terminal codes,
and perhaps using Termwiz's line editor with autocomplete for prompts.
@altsem altsem changed the base branch from refactor/remove-term-dep-in-state to master June 9, 2025 20:49
@altsem altsem merged commit 5dbf6ed into master Jun 9, 2025
@altsem altsem deleted the feat/termwiz branch June 9, 2025 21:06
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.

3 participants