diff --git a/crates/ferrite-core/src/palette.rs b/crates/ferrite-core/src/palette.rs index d98394b..81cbc4b 100644 --- a/crates/ferrite-core/src/palette.rs +++ b/crates/ferrite-core/src/palette.rs @@ -163,6 +163,14 @@ impl CommandPalette { None } } + + pub fn height(&self) -> usize { + match &self.state { + PaletteState::Message(string) => string.lines().count(), + PaletteState::Error(string) => string.lines().count(), + _ => 1, + } + } } impl CommandPalette { diff --git a/crates/ferrite-tui/src/lib.rs b/crates/ferrite-tui/src/lib.rs index a83c2d2..e30993c 100644 --- a/crates/ferrite-tui/src/lib.rs +++ b/crates/ferrite-tui/src/lib.rs @@ -145,7 +145,13 @@ impl TuiApp { let theme = &self.engine.themes[&self.engine.config.theme]; f.render_widget(BackgroundWidget::new(theme), f.size()); let size = f.size(); - let editor_size = Rect::new(size.x, size.y, size.width, size.height - 1); + let editor_size = Rect::new( + size.x, + size.y, + size.width, + size.height + .saturating_sub(self.engine.palette.height() as u16), + ); self.buffer_area = editor_size; let current_pane = self.engine.workspace.panes.get_current_pane(); @@ -212,7 +218,13 @@ impl TuiApp { ); } - let palette_size = Rect::new(size.left(), size.bottom() - 1, size.width, 1); + let palette_size = Rect::new( + size.left(), + size.bottom() + .saturating_sub(self.engine.palette.height() as u16), + size.width, + (self.engine.palette.height() as u16).min(size.height), + ); f.render_stateful_widget( CmdPaletteWidget::new(theme, self.engine.palette.has_focus(), size), palette_size, diff --git a/crates/ferrite-tui/src/widgets/palette_widget.rs b/crates/ferrite-tui/src/widgets/palette_widget.rs index c676594..5f09183 100644 --- a/crates/ferrite-tui/src/widgets/palette_widget.rs +++ b/crates/ferrite-tui/src/widgets/palette_widget.rs @@ -69,22 +69,32 @@ impl StatefulWidget for CmdPaletteWidget<'_> { } } PaletteState::Message(msg) => { - buf.set_stringn( - area.x, - area.y, - msg, - area.width.into(), - convert_style(&self.theme.text), - ); + for (i, line) in msg.lines().enumerate() { + if i >= area.height.into() { + break; + } + buf.set_stringn( + area.x, + area.y + i as u16, + line, + area.width.into(), + convert_style(&self.theme.text), + ); + } } PaletteState::Error(msg) => { - buf.set_stringn( - area.x, - area.y, - msg, - area.width.into(), - convert_style(&self.theme.error_text), - ); + for (i, line) in msg.lines().enumerate() { + if i >= area.height.into() { + break; + } + buf.set_stringn( + area.x, + area.y + i as u16, + line, + area.width.into(), + convert_style(&self.theme.error_text), + ); + } } PaletteState::Nothing => (), PaletteState::Prompt {