Test rendering with fork
This commit is contained in:
parent
ee74676da4
commit
9c5f027898
2 changed files with 54 additions and 37 deletions
45
cove-tui/src/ui.rs
Normal file
45
cove-tui/src/ui.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::Stdout;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
use tui::backend::CrosstermBackend;
|
||||
use tui::widgets::Paragraph;
|
||||
use tui::Terminal;
|
||||
|
||||
use crate::room::Room;
|
||||
|
||||
pub enum Overlay {
|
||||
Error(String),
|
||||
ChooseRoom(String),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Ui {
|
||||
rooms: HashMap<String, Arc<Mutex<Room>>>,
|
||||
room: Option<Arc<Mutex<Room>>>,
|
||||
overlay: Option<Overlay>,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub async fn render_to_terminal(
|
||||
&mut self,
|
||||
terminal: &mut Terminal<CrosstermBackend<Stdout>>,
|
||||
) -> anyhow::Result<()> {
|
||||
terminal.autoresize()?;
|
||||
|
||||
let mut frame = terminal.get_frame();
|
||||
frame.render_widget(Paragraph::new("Hello world!"), frame.size());
|
||||
|
||||
// Do a little dance to please the borrow checker
|
||||
let cursor = frame.cursor();
|
||||
drop(frame);
|
||||
terminal.set_cursor_opt(cursor)?;
|
||||
|
||||
terminal.flush()?;
|
||||
terminal.flush_backend()?;
|
||||
terminal.swap_buffers();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue