on master help sign in
Drop terminal interaction in compositor.size()
b2e7171Blaž Hrastnik
helix-term/src/compositor.rs+7−2
@@ -93,6 +93,7 @@ type Terminal = tui::terminal::Terminal<TestBackend>;
93pub struct Compositor {
93pub struct Compositor {
94 layers: Vec<Box<dyn Component>>,
94 layers: Vec<Box<dyn Component>>,
95 terminal: Terminal,
95 terminal: Terminal,
96+ area: Rect,
96
97
97 pub(crate) last_picker: Option<Box<dyn Component>>,
98 pub(crate) last_picker: Option<Box<dyn Component>>,
98}
99}
@@ -106,21 +107,25 @@ impl Compositor {
106 let backend = TestBackend::new(120, 150);
107 let backend = TestBackend::new(120, 150);
107
108
108 let terminal = Terminal::new(backend).context("build terminal")?;
109 let terminal = Terminal::new(backend).context("build terminal")?;
110+ let area = terminal.size().expect("couldn't get terminal size");
109 Ok(Self {
111 Ok(Self {
110 layers: Vec::new(),
112 layers: Vec::new(),
113+ area,
111 terminal,
114 terminal,
112 last_picker: None,
115 last_picker: None,
113 })
116 })
114 }
117 }
115
118
116 pub fn size(&self) -> Rect {
119 pub fn size(&self) -> Rect {
117− self.terminal.size().expect("couldn't get terminal size")
120+ self.area
118 }
121 }
119
122
120 pub fn resize(&mut self, width: u16, height: u16) {
123 pub fn resize(&mut self, width: u16, height: u16) {
121 self.terminal
124 self.terminal
122 .resize(Rect::new(0, 0, width, height))
125 .resize(Rect::new(0, 0, width, height))
123− .expect("Unable to resize terminal")
126+ .expect("Unable to resize terminal");
127+
128+ self.area = self.terminal.size().expect("couldn't get terminal size");
124 }
129 }
125
130
126 pub fn save_cursor(&mut self) {
131 pub fn save_cursor(&mut self) {