gitu icon indicating copy to clipboard operation
gitu copied to clipboard

feat: Switch terminal backend from Crossterm to Termwiz

Open altsem opened this issue 8 months ago • 4 comments

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:

  • [x] 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 avatar Apr 18 '25 10:04 altsem

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 :warning:
src/term.rs 4.65% 41 Missing :warning:
src/lib.rs 0.00% 7 Missing :warning:
src/main.rs 0.00% 6 Missing :warning:
src/state.rs 76.92% 3 Missing :warning:
src/error.rs 0.00% 1 Missing :warning:
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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Apr 18 '25 10:04 codecov[bot]

@altsem Working well for me on a mac!

sbillig avatar May 09 '25 20:05 sbillig

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

sbillig avatar May 14 '25 16:05 sbillig

@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 avatar May 16 '25 21:05 altsem

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 avatar May 31 '25 11:05 altsem