Lines
100 %
Functions
50 %
Branches
//! Inherent draw + intent handling for `ConsoleState`.
//!
//! The draw logic (scrollback + prompt) lives here; the pure state
//! stays in `tabs::nms`. The console consumes no tab-layer intents (input is
//! routed via `handle_console` while focused), so `handle` always ignores.
use crate::event::Intent;
use crate::hits::{Surface, Target};
use crate::pane::PaneId;
use crate::tabs::nms::ConsoleState;
use crate::view::{DrawCtx, Handled};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Paragraph, Widget, Wrap};
use tvui::{Chrome, Role, Theme, inner};
fn draw_scrollback(state: &ConsoleState, buf: &mut Buffer, area: Rect) {
let visible = usize::from(area.height);
let lines: Vec<Line> = state
.visible_scrollback(visible)
.iter()
.map(|l| Line::from(l.as_str()))
.collect();
Paragraph::new(lines)
.wrap(Wrap { trim: false })
.render(area, buf);
}
fn draw_prompt(state: &ConsoleState, buf: &mut Buffer, area: Rect, focused: bool, theme: &Theme) {
let marker = if state.pending.is_empty() {
"nms> "
} else {
"...> "
};
let content = format!("{marker}{}", state.input.buffer());
let style = theme.style(if focused {
Role::Prompt
Role::PanelDim
});
Paragraph::new(Span::styled(content, style)).render(area, buf);
impl ConsoleState {
pub fn draw(&self, buf: &mut Buffer, area: Rect, ctx: &mut DrawCtx) {
let theme = ctx.theme;
let title = match ctx.is_active && self.panes.is_focused(PaneId::Scrollback) {
true => format!("{} — Scrollback ↕", ctx.title),
false => ctx.title.clone(),
Chrome::new(theme, &title, ctx.frame).render(area, buf);
let inner = inner(area);
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(1), Constraint::Length(1)])
.split(inner);
draw_scrollback(self, buf, chunks[0]);
ctx.hits.push(chunks[0], Target::Body(Surface::Pane));
draw_prompt(
self,
buf,
chunks[1],
ctx.is_active && self.panes.is_focused(PaneId::Prompt),
theme,
);
pub fn handle(&mut self, intent: Intent) -> Handled {
match intent {
Intent::ScrollLineUp => self.scroll_up(1),
Intent::ScrollLineDown => self.scroll_down(1),
_ => return Handled::Ignored,
Handled::Consumed(vec![])