aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 18fb6e7..85e3888 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,24 +1,24 @@
use crossterm::event::{self, Event};
use std::io;
-use tui::{backend::Backend, Terminal};
use pfc::{ui, Calculator, Signal};
fn main() -> io::Result<()> {
let mut terminal = ui::init_terminal()?;
- let result = run(Calculator::default(), &mut terminal);
- ui::cleanup_terminal(terminal)?;
- result
-}
+ let mut calculator = Calculator::default();
-fn run<B: Backend>(mut calculator: Calculator, terminal: &mut Terminal<B>) -> io::Result<()> {
- loop {
- terminal.draw(|f| calculator.draw(f))?;
+ let result = || -> io::Result<()> {
+ loop {
+ terminal.draw(|f| calculator.draw(f))?;
- if let Event::Key(key) = event::read()? {
- if let Signal::Exit = calculator.handle_input(key) {
- return Ok(());
+ if let Event::Key(key) = event::read()? {
+ if let Signal::Exit = calculator.handle_input(key) {
+ return Ok(());
+ }
}
}
- }
+ }();
+
+ ui::cleanup_terminal(terminal)?;
+ result
}