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

feat(color-eyre): Add color eyre to the default app terminal setup #1181

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

joshka
Copy link
Member

@joshka joshka commented Jun 16, 2024

Apps can now enable color-eyre hooks using the with_color_eyre_hooks
method on CrosstermBackend. This is also added to the default features
in the Cargo.toml file, and the defaults that are applied to terminals
created using CrosstermBackend::into_terminal_with_defaults.

Copy link

codecov bot commented Jun 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 111 lines in your changes missing coverage. Please review.

Project coverage is 93.6%. Comparing base (4bfdc15) to head (458b7b7).
Report is 6 commits behind head on main.

Files Patch % Lines
src/backend/crossterm.rs 0.0% 99 Missing ⚠️
src/backend.rs 0.0% 12 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1181     +/-   ##
=======================================
- Coverage   94.3%   93.6%   -0.7%     
=======================================
  Files         60      60             
  Lines      14679   14784    +105     
=======================================
  Hits       13843   13843             
- Misses       836     941    +105     

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

Adds:
- `CrosstermBackend::stdout` and `CrosstermBackend::stderr` for creating
  backends with `std::io::stdout` and `std::io::stderr` respectively.
- `CrosstermBackend::into_terminal` for converting a backend into a
  terminal.
- `CrosstermBackend::into_terminal_with_options` for converting a
  backend into a terminal with options.
- `CrosstermBackend::into_terminal_with_defaults` for converting a
  backend into a terminal with default settings (raw mode and alternate
  screen).
- `CrosstermBackend::with_raw_mode` for enabling raw mode.
- `CrosstermBackend::with_alternate_screen` for switching to the
  alternate screen.
- `CrosstermBackend::with_mouse_support` for enabling mouse support.
- `CrosstermBackend::reset` for resetting the terminal to its default
  state.
- `Drop` implementation for restoring raw mode, mouse capture, and
  alternate screen on drop.

Most applications can now just use the `into_terminal_with_defaults`
method to set up the terminal with raw mode and the alternate screen,
and now longer need to worry about restoring the terminal to its default
state when the application exits. The reset method can be used to
restore the terminal to its default state if needed (e.g. in a panic
handler).

```rust
use ratatui::backend::CrosstermBackend;

let terminal = CrosstermBackend::stdout()
     .into_terminal_with_defaults()?;
```
@EdJoPaTo
Copy link
Member

When setting up a panic hook with an external crate, there should also be the panic hook with std only methods.

Adds:
- `CrosstermBackend::stdout` and `CrosstermBackend::stderr` for creating
  backends with `std::io::stdout` and `std::io::stderr` respectively.
- `CrosstermBackend::into_terminal` for converting a backend into a
  terminal.
- `CrosstermBackend::into_terminal_with_options` for converting a
  backend into a terminal with options.
- `CrosstermBackend::into_terminal_with_defaults` for converting a
  backend into a terminal with default settings (raw mode and alternate
  screen).
- `CrosstermBackend::with_raw_mode` for enabling raw mode.
- `CrosstermBackend::with_alternate_screen` for switching to the
  alternate screen.
- `CrosstermBackend::with_mouse_support` for enabling mouse support.
- `CrosstermBackend::reset` for resetting the terminal to its default
  state.
- `Drop` implementation for restoring raw mode, mouse capture, and
  alternate screen on drop.

Most applications can now just use the `into_terminal_with_defaults`
method to set up the terminal with raw mode and the alternate screen,
and now longer need to worry about restoring the terminal to its default
state when the application exits. The reset method can be used to
restore the terminal to its default state if needed (e.g. in a panic
handler).

```rust
use ratatui::backend::CrosstermBackend;

let terminal = CrosstermBackend::stdout()
     .into_terminal_with_defaults()?;
```
Apps can now enable color-eyre hooks using the with_color_eyre_hooks
method on CrosstermBackend. This is also added to the default features
in the Cargo.toml file, and the defaults that are applied to terminals
created using CrosstermBackend::into_terminal_with_defaults.
@joshka
Copy link
Member Author

joshka commented Jun 16, 2024

When setting up a panic hook with an external crate, there should also be the panic hook with std only methods.

Added

@kdheepak kdheepak changed the title feat(color-eyre): Add color eyre to the default app terminal setup' feat(color-eyre): Add color eyre to the default app terminal setup Jun 17, 2024
joshka added a commit that referenced this pull request Jun 18, 2024
In <#1180> and
<#1181>, we introduced some
simpler ways to create a backend and terminal, and to setup color_eyre
to handle errors. This PR updates the examples to use these new methods,
and removes a bunch of unnecessary boilerplate code.
@joshka joshka added the Status: Blocked An issue or PR that cannot be completed until some other task is complete label Jun 19, 2024
@joshka
Copy link
Member Author

joshka commented Jun 19, 2024

Blocked on #1180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Blocked An issue or PR that cannot be completed until some other task is complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants