1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
use libtiny_common::{Event, MsgTarget};
use libtiny_tui::TUI;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;
fn main() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let local = tokio::task::LocalSet::new();
let tab = MsgTarget::Server { serv: "mentions" };
local.block_on(&runtime, async move {
let (tui, rcv_ev) = TUI::run(PathBuf::from("../tiny/config.yml"));
let mut text = String::new();
let mut file = File::open("test/lipsum.txt").unwrap();
file.read_to_string(&mut text).unwrap();
let single_line_text = text.lines().collect::<Vec<&str>>().join("");
tui.add_client_msg(&single_line_text, &tab);
for line in text.lines() {
tui.add_client_msg(&format!(">>> {}", line), &tab);
}
tui.draw();
ui_task(tui, rcv_ev).await;
});
runtime.block_on(local);
}
async fn ui_task(ui: TUI, rcv_ev: mpsc::Receiver<Event>) {
let mut rcv_ev = ReceiverStream::new(rcv_ev);
while (rcv_ev.next().await).is_some() {
ui.draw();
}
}
|