Compare commits
2 commits
081ecdba63
...
ddc04d2d0b
Author | SHA1 | Date | |
---|---|---|---|
ddc04d2d0b | |||
ac069551d8 |
5 changed files with 75 additions and 4 deletions
1
crates/cli/src/tui/actor/handlers/mod.rs
Normal file
1
crates/cli/src/tui/actor/handlers/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
//
|
4
crates/cli/src/tui/actor/messages.rs
Normal file
4
crates/cli/src/tui/actor/messages.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//
|
||||
use git_next_core::message;
|
||||
|
||||
message!(Start, "Start the TUI");
|
61
crates/cli/src/tui/actor/mod.rs
Normal file
61
crates/cli/src/tui/actor/mod.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
mod handlers;
|
||||
pub mod messages;
|
||||
|
||||
use std::io::{stderr, Stderr};
|
||||
|
||||
use actix::{Actor, Context};
|
||||
|
||||
use ratatui::{
|
||||
crossterm::{
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
},
|
||||
prelude::CrosstermBackend,
|
||||
Terminal,
|
||||
};
|
||||
|
||||
pub struct Tui {
|
||||
terminal: Option<Terminal<CrosstermBackend<Stderr>>>,
|
||||
}
|
||||
|
||||
impl Actor for Tui {
|
||||
type Context = Context<Self>;
|
||||
|
||||
fn started(&mut self, _ctx: &mut Self::Context) {
|
||||
match init() {
|
||||
Ok(terminal) => {
|
||||
self.terminal.replace(terminal);
|
||||
}
|
||||
Err(err) => tracing::error!(?err, "Failed to start terminal UI"),
|
||||
}
|
||||
}
|
||||
|
||||
fn stopped(&mut self, _ctx: &mut Self::Context) {
|
||||
if let Err(err) = restore() {
|
||||
match std::env::consts::OS {
|
||||
"linux" | "macos" => {
|
||||
tracing::error!(
|
||||
?err,
|
||||
"Failed to restore terminal: Type `reset` to restore terminal"
|
||||
);
|
||||
}
|
||||
"windows" => {
|
||||
tracing::error!(?err, "Failed to restore terminal: Reopen a new terminal");
|
||||
}
|
||||
_ => tracing::error!(?err, "Failed to restore terminal"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init() -> std::io::Result<Terminal<CrosstermBackend<Stderr>>> {
|
||||
execute!(stderr(), EnterAlternateScreen)?;
|
||||
enable_raw_mode()?;
|
||||
Terminal::new(CrosstermBackend::new(stderr()))
|
||||
}
|
||||
|
||||
fn restore() -> std::io::Result<()> {
|
||||
execute!(stderr(), LeaveAlternateScreen)?;
|
||||
disable_raw_mode()
|
||||
}
|
2
crates/cli/src/tui/mod.rs
Normal file
2
crates/cli/src/tui/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
//
|
||||
mod actor;
|
11
justfile
11
justfile
|
@ -4,10 +4,13 @@ install-hooks:
|
|||
git config core.hooksPath .git-hooks
|
||||
|
||||
validate-dev-branch:
|
||||
git rebase -i origin/main -x 'cargo fmt --check'
|
||||
git rebase -i origin/main -x 'cargo build'
|
||||
git rebase -i origin/main -x 'cargo test'
|
||||
git rebase -i origin/main -x 'cargo clippy'
|
||||
git rebase -i origin/main -x 'just mock-ci'
|
||||
|
||||
mock-ci:
|
||||
cargo fmt --check
|
||||
cargo build
|
||||
cargo test
|
||||
cargo clippy
|
||||
|
||||
start-ngrok:
|
||||
#!/usr/bin/env bash
|
||||
|
|
Loading…
Reference in a new issue