Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: src/commander/files.rs
expression: "test_repo.commander.get_file_diff(&head, \"README\", &DiffFormat::Git)?"
---
"diff --git a/README b/README\nindex 43d88b6586...f6d5afa370 100644\n--- a/README\n+++ b/README\n@@ -1,1 +1,1 @@\n-AAA\n\\ No newline at end of file\n+BBB\n\\ No newline at end of file\n"
"diff --git a/README b/README\nindex 43d88b6586..f6d5afa370 100644\n--- a/README\n+++ b/README\n@@ -1,1 +1,1 @@\n-AAA\n\\ No newline at end of file\n+BBB\n\\ No newline at end of file\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: src/commander/log.rs
expression: log.graph
---
"@ [LINE]\n│ (empty) (no description set)\n [LINE]\n"
"@ [LINE]\n│ (empty) (no description set)\n [LINE]\n"
39 changes: 23 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,12 @@ fn main() -> Result<()> {
// Setup app
let mut app = App::new(env.clone(), &mut commander)?;

// Setup terminal
enable_raw_mode()?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let mut terminal = setup_terminal()?;

// Run app
run_app(&mut terminal, &mut app, &mut commander)?;

// Restore terminal
disable_raw_mode()?;
execute!(
terminal.backend_mut(),
LeaveAlternateScreen,
DisableMouseCapture
)?;
terminal.show_cursor()?;
let res = run_app(&mut terminal, &mut app, &mut commander);
restore_terminal(terminal)?;
res?;

Ok(())
}
Expand All @@ -113,6 +101,25 @@ fn run_app<B: Backend>(
}
}

fn setup_terminal() -> Result<Terminal<CrosstermBackend<io::Stdout>>> {
enable_raw_mode()?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
let backend = CrosstermBackend::new(stdout);
Ok(Terminal::new(backend)?)
}

fn restore_terminal(mut terminal: Terminal<CrosstermBackend<io::Stdout>>) -> Result<()> {
disable_raw_mode()?;
execute!(
terminal.backend_mut(),
LeaveAlternateScreen,
DisableMouseCapture
)?;
terminal.show_cursor()?;
Ok(())
}

enum ComponentInputResult {
Handled,
HandledAction(ComponentAction),
Expand Down