diff --git a/shell/src/main.rs b/shell/src/main.rs index d6a9533..7df39da 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -69,12 +69,29 @@ impl AsciiBox { ascii_box } + + pub fn resize(&mut self, new_extent: Vector2) { + if self.extent != new_extent { + let old_extent = self.extent; + self.extent = new_extent; + self.notify_each(GridWindowIterator::from(Point2::new(0, 0) .. Point2::new(2+std::cmp::max(old_extent.x, new_extent.x), 2+std::cmp::max(old_extent.y, new_extent.y)))); + } + } + + pub fn fit_content(&mut self) { + if let Some(c) = self.content.as_ref() { + let p = c.range().end; + self.resize(Vector2::new(p.x, p.y)); + } else { + self.resize(Vector2::new(0, 0)); + } + } } impl Observer for AsciiBox { fn reset(&mut self, new_content: Option>) { self.content = new_content; - self.notify_each(GridWindowIterator::from(Point2::new(0, 0) ..= Point2::new(self.extent.x, self.extent.y))); + self.notify_each(GridWindowIterator::from(Point2::new(0, 0) .. Point2::new(self.extent.x+2, self.extent.y+2))); } fn notify(&mut self, pt: &Point2) { @@ -90,31 +107,31 @@ impl IndexView> for AsciiBox { type Item = TerminalAtom; fn get(&self, pt: &Point2) -> Option { - if pt.x == 0 || pt.x == self.extent.x { + if pt.x == 0 || pt.x == self.extent.x+1 { // vertical line if pt.y == 0 && pt.x == 0 { Some(TerminalAtom::from('╭')) - } else if pt.y == 0 && pt.x == self.extent.x { + } else if pt.y == 0 && pt.x == self.extent.x+1 { Some(TerminalAtom::from('╮')) - } else if pt.y > 0 && pt.y < self.extent.y { + } else if pt.y > 0 && pt.y < self.extent.y+1 { Some(TerminalAtom::from('│')) - } else if pt.y == self.extent.y && pt.x == 0 { + } else if pt.y == self.extent.y+1 && pt.x == 0 { Some(TerminalAtom::from('╰')) - } else if pt.y == self.extent.y && pt.x == self.extent.x { + } else if pt.y == self.extent.y+1 && pt.x == self.extent.x+1 { Some(TerminalAtom::from('╯')) } else { None } - } else if pt.y == 0 || pt.y == self.extent.y { + } else if pt.y == 0 || pt.y == self.extent.y+1 { // horizontal line - if pt.x > 0 && pt.x < self.extent.x { + if pt.x > 0 && pt.x < self.extent.x+1 { Some(TerminalAtom::from('─')) } else { None } } else if - pt.x < self.extent.x && - pt.y < self.extent.y + pt.x < self.extent.x+1 && + pt.y < self.extent.y+1 { self.content.get(&(pt - Vector2::new(1, 1))) } else { @@ -124,7 +141,7 @@ impl IndexView> for AsciiBox { fn area(&self) -> Option>> { Some(GridWindowIterator::from( - Point2::new(0, 0) ..= Point2::new(self.extent.x, self.extent.y) + Point2::new(0, 0) .. Point2::new(self.extent.x+2, self.extent.y+2) ).collect()) } } @@ -180,13 +197,17 @@ async fn main() { }); let mut pty : Option = None; + let mut ptybox : Option>> = None; loop { term_port.update(); if let Some(p) = pty.as_mut() { if p.get_status() { + if let Some(ptybox) = ptybox.take() { + ptybox.write().unwrap().fit_content(); + } pty = None; - + process_launcher = ProcessLauncher::new(); process_launcher.goto(TreeCursor { leaf_mode: ListCursorMode::Insert, @@ -247,12 +268,14 @@ async fn main() { let box_port = ViewPort::new(); let test_box = AsciiBox::new( - Vector2::new(81, 26), + Vector2::new(80, 25), output_port.outer() .map_item(|_,a| a.add_style_back(TerminalStyle::fg_color((230, 230, 230)))), box_port.inner() ); + ptybox = Some(test_box.clone()); + table_buf.remove(Point2::new(0, y-1)); let mut p = box_port.outer().map_item(|_idx, x| x.add_style_back(TerminalStyle::fg_color((90, 120, 100))))