further restructuring
This commit is contained in:
parent
f151f9c5d2
commit
85b614a9bb
41 changed files with 95 additions and 125 deletions
examples/tty-01-hello/src
|
@ -6,65 +6,22 @@ extern crate termion;
|
|||
|
||||
use {
|
||||
cgmath::Vector2,
|
||||
nested::reprTree::Context,
|
||||
nested_tty::{Terminal, TerminalCompositor, TerminalEvent, TerminalStyle, TerminalView},
|
||||
nested::repr_tree::Context,
|
||||
nested_tty::{Terminal, TerminalCompositor, TTYApplication, TerminalEvent, TerminalStyle, TerminalView},
|
||||
r3vi::view::{port::UpdateTask, ViewPort},
|
||||
std::sync::{Arc, RwLock},
|
||||
termion::event::{Event, Key},
|
||||
};
|
||||
|
||||
/* this task handles all terminal events (e.g. key press, resize)
|
||||
*/
|
||||
pub async fn event_loop(
|
||||
mut term: Terminal,
|
||||
term_port: ViewPort<dyn TerminalView>,
|
||||
portmutex: Arc<RwLock<()>>,
|
||||
) {
|
||||
loop {
|
||||
let ev = term.next_event().await;
|
||||
let _l = portmutex.write().unwrap();
|
||||
|
||||
if ev == TerminalEvent::Input(Event::Key(Key::Ctrl('d'))) {
|
||||
break;
|
||||
}
|
||||
term_port.update();
|
||||
}
|
||||
}
|
||||
|
||||
/* this task will continuously pull forward
|
||||
* all notifications which are influencing
|
||||
* the view in `term_port`
|
||||
*/
|
||||
pub async fn update_loop(term_port: ViewPort<dyn TerminalView>, portmutex: Arc<RwLock<()>>) {
|
||||
loop {
|
||||
{
|
||||
let _l = portmutex.write().unwrap();
|
||||
term_port.update();
|
||||
}
|
||||
async_std::task::sleep(std::time::Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
/* initialize our terminal
|
||||
*/
|
||||
let term_port = ViewPort::new();
|
||||
|
||||
let mut term = Terminal::new(term_port.outer());
|
||||
let term_writer = term.get_writer();
|
||||
|
||||
let portmutex = Arc::new(RwLock::new(()));
|
||||
|
||||
/* spawn event-handling & updating tasks
|
||||
*/
|
||||
async_std::task::spawn(update_loop(term_port.clone(), portmutex.clone()));
|
||||
|
||||
async_std::task::spawn(event_loop(term, term_port.clone(), portmutex.clone()));
|
||||
let tty_app = TTYApplication::new(|event| { /* handle event */ });
|
||||
|
||||
/* populate the view in `term_port`
|
||||
*/
|
||||
let compositor = TerminalCompositor::new(term_port.inner());
|
||||
let compositor = TerminalCompositor::new(tty_app.port.inner());
|
||||
|
||||
compositor
|
||||
.write()
|
||||
|
@ -81,5 +38,6 @@ async fn main() {
|
|||
|
||||
/* write the changes in the view of `term_port` to the terminal
|
||||
*/
|
||||
term_writer.show().await.expect("output error!");
|
||||
tty_app.show().await.expect("output error!");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue