summaryrefslogtreecommitdiffstats
path: root/src/event/event_poller.rs
blob: 25260706a2c55fa6e7636fc8b49100b9eed5d0e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::sync::Arc;

use anyhow::Result;
use tuikit::error::TuikitError;
use tuikit::event::Event;
use tuikit::term::Term;

/// Simple struct to read the events.
pub struct EventReader {
    pub term: Arc<Term>,
}

impl EventReader {
    /// Creates a new instance with an Arc to a terminal.
    pub fn new(term: Arc<Term>) -> Self {
        Self { term }
    }

    /// Returns the events as they're received. Wait indefinitely for a new one.
    /// We should spend most of the application life here, doing nothing :)
    pub fn poll_event(&self) -> Result<Event, TuikitError> {
        self.term.poll_event()
    }
}