Skip to content

Commit e2d45e6

Browse files
committed
Switched to an async model
With more complexity this will EVENTUALLY make sense
1 parent ff1aed4 commit e2d45e6

3 files changed

Lines changed: 121 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ clap_complete = "^4.5"
1515
dir_spec = "0.5.0"
1616
rust-embed = "^8.2"
1717
toml = "^0.8"
18-
tuirealm = { version = "3.3.0", features = ["crossterm", "derive"] }
18+
tuirealm = { version = "3.3.0", features = ["crossterm", "derive", "async-ports"] }
19+
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
1920
eyre = "0.6.12"
2021
thiserror = "2.0.18"
2122
ratatui = "0.30"

src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ fn make_test(opt: &Opt) -> eyre::Result<Vec<String>> {
5555
Ok(contents)
5656
}
5757

58-
fn main() -> eyre::Result<()> {
58+
#[tokio::main]
59+
async fn main() -> eyre::Result<()> {
5960
let options = Opt::parse();
6061
let config = options.config();
6162

@@ -93,9 +94,10 @@ fn setup_ttyper(
9394

9495
let mut app: Application<Id, Msg, NoUserEvent> = Application::init(
9596
EventListenerCfg::<NoUserEvent>::default()
96-
.crossterm_input_listener(Duration::from_millis(20), 1)
97-
.poll_timeout(Duration::from_millis(10))
98-
.tick_interval(Duration::from_secs(1)),
97+
.with_handle(tokio::runtime::Handle::current())
98+
.async_crossterm_input_listener(Duration::from_millis(0), 1)
99+
.tick_interval(Duration::from_secs(1))
100+
.async_tick(true),
99101
);
100102

101103
app.mount(
@@ -126,7 +128,7 @@ fn event_loop(mut model: Model) -> eyre::Result<()> {
126128

127129
while !model.quit {
128130
// Tick
129-
match model.app.tick(PollStrategy::Once) {
131+
match model.app.tick(PollStrategy::BlockCollectUpTo(10)) {
130132
Err(err) => {
131133
let _ = model.terminal.restore();
132134
return Err(TtyperError::Application(err.to_string()).into());

0 commit comments

Comments
 (0)