Drop terminal interaction in compositor.size()

This commit is contained in:
Blaž Hrastnik 2022-03-29 09:57:12 +09:00
parent c3f9d3641c
commit 14f987807d
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640

View File

@ -75,6 +75,7 @@ fn id(&self) -> Option<&'static str> {
pub struct Compositor {
layers: Vec<Box<dyn Component>>,
terminal: Terminal,
area: Rect,
pub(crate) last_picker: Option<Box<dyn Component>>,
}
@ -83,21 +84,25 @@ impl Compositor {
pub fn new() -> Result<Self, Error> {
let backend = CrosstermBackend::new(stdout());
let terminal = Terminal::new(backend)?;
let area = terminal.size().expect("couldn't get terminal size");
Ok(Self {
layers: Vec::new(),
area,
terminal,
last_picker: None,
})
}
pub fn size(&self) -> Rect {
self.terminal.size().expect("couldn't get terminal size")
self.area
}
pub fn resize(&mut self, width: u16, height: u16) {
self.terminal
.resize(Rect::new(0, 0, width, height))
.expect("Unable to resize terminal")
.expect("Unable to resize terminal");
self.area = self.terminal.size().expect("couldn't get terminal size");
}
pub fn save_cursor(&mut self) {