Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-ui-template: use crossterm as the key / terminal backend #10

Merged
merged 41 commits into from
Aug 28, 2023

Conversation

amtoine
Copy link
Owner

@amtoine amtoine commented Aug 26, 2023

related to

Warning
very important caveat:

  • this plugin won't work with the latest versions of Nushell => i'll work on that when i upgrade the dependencies
  • use Nushell version 0.84.0 to make sure the plugin launches

📝 changelog

major

  • make everything public for simplicity, i.e. there is no pub (super) or pub (crate) anymore, only nothing or pub
  • use KeyCode from crossterm instead of Key from console (template requirement)
  • use foo<B: Backend>(frame: &mut Frame<'_, B>, ...) instead of foo(frame: &mut Frame<CrosstermBackend<console::Term>>, ...) for rendering
  • add a size method to Tui to change the size of the editor dynamically
  • use the following snippet when there is an error to hold the application loop until there is a key stroke and avoid refreshing as soon as there is a terminal tick, which makes the error disappear immediately
loop {
    if let Event::Key(_) = tui.events.next()? {
        break;
    }
}

minor / refactoring

  • remove out-of-date documentation => this will have to be tackled probably by adding lint warnings for missing documentation
  • move all the rendering from tui.rs to ui.rs (template file / only renaming)
  • replace terminal.rs with tui.rs (template)
  • use event.rs and tui.rs as-is (template)
  • apply minor tweaks to the template, e.g. removing useless comments in the main loop and renaming tui to ratatui

Note
i'll leave the documentation and the pub visibility issues to another time

this is to avoid confusion between `ratatui` and the `tui.rs`
module of the library itself.
otherwise, the app starts in a invalid state and crashes when
trying to navigate the data.
@amtoine
Copy link
Owner Author

amtoine commented Aug 26, 2023

@fdncred
can you try this branch with Nushell 0.84.0 and see if that fixes your issue?
it works with my system almost as before 🤞

@amtoine
Copy link
Owner Author

amtoine commented Aug 26, 2023

also i'm concerned about the last caveat about peeking subdata 🤔
it's quite annoying 😅

@fdncred
Copy link
Contributor

fdncred commented Aug 26, 2023

I don't have 0.84.0 installed anywhere. I try to stay on the latest main. I'd be excited to test it though if it were on 0.84.1.

@amtoine
Copy link
Owner Author

amtoine commented Aug 26, 2023

I don't have 0.84.0 installed anywhere. I try to stay on the latest main. I'd be excited to test it though if it were on 0.84.1.

i wanted to know if using the rust-tui-template could solve the issue you encountered by using crossterm instead of console before moving on to upgrading to 0.84.1 😕

could you just try the following? 😇

  • install and register the plugin from this PR
  • checkout Nushell 0.84.0
  • try explore from inside cargo run

that'd be amazing 😊

@amtoine amtoine changed the title Use ratatui template rust-ui-template: use crossterm as the key / terminal backend Aug 27, 2023
@amtoine amtoine marked this pull request as ready for review August 27, 2023 10:18
this should bring the key handling match-based refactor from the main
branch.
@fdncred
Copy link
Contributor

fdncred commented Aug 28, 2023

This works except for one thing. On Windows 1 keypress = 2 with crossterm because there is a press and release event. You have to do something like this

https://github.com/ratatui-org/ratatui-async-template/blob/f992a061c04ff05dd03a5f0b5d6ade6370d9aae2/src/event.rs#L62C1-L66

Other than that, it works fine.

@amtoine
Copy link
Owner Author

amtoine commented Aug 28, 2023

This works except for one thing.
...
Other than that, it works fine.

ooh i'm happy this fixes the issue 😌

On Windows 1 keypress = 2 with crossterm because there is a press and release event. You have to do something like this

https://github.com/ratatui-org/ratatui-async-template/blob/f992a061c04ff05dd03a5f0b5d6ade6370d9aae2/src/event.rs#L62C1-L66

very good catch, let me fix that right now 😉

@amtoine amtoine linked an issue Aug 28, 2023 that may be closed by this pull request
@amtoine amtoine merged commit a41000a into main Aug 28, 2023
4 checks passed
@amtoine amtoine deleted the use-ratatui-template branch August 28, 2023 17:17
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.

cannot run on windows: main loop fails
2 participants