use ratatui::layout::{Alignment, Constraint, Direction, Layout, Position, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{
Block, Borders, Clear, List, ListItem, ListState, Paragraph, Row, Table, TableState, Wrap,
};
use ratatui::Frame;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::cli::ThemeArg;
use crate::config::{display_origin, EffectiveConfig};
use crate::tui::app::{App, CompanyListItem, Focus, Overlay, Route, DOCUMENT_FIELD_COUNT};
#[derive(Debug, Clone, Copy)]
pub struct Theme {
accent: Color,
good: Color,
warn: Color,
bad: Color,
muted: Color,
selected: Style,
}
impl Theme {
pub fn from_argument(argument: ThemeArg) -> Self {
match argument {
ThemeArg::Dark => Self {
accent: Color::LightBlue,
good: Color::LightGreen,
warn: Color::Yellow,
bad: Color::LightRed,
muted: Color::DarkGray,
selected: Style::default()
.fg(Color::Black)
.bg(Color::LightBlue)
.add_modifier(Modifier::BOLD),
},
ThemeArg::Light => Self {
accent: Color::Blue,
good: Color::Green,
warn: Color::Rgb(160, 100, 0),
bad: Color::Red,
muted: Color::Gray,
selected: Style::default()
.fg(Color::White)
.bg(Color::Blue)
.add_modifier(Modifier::BOLD),
},
ThemeArg::Mono => Self {
accent: Color::Reset,
good: Color::Reset,
warn: Color::Reset,
bad: Color::Reset,
muted: Color::Reset,
selected: Style::default().add_modifier(Modifier::REVERSED | Modifier::BOLD),
},
}
}
}
pub fn render(frame: &mut Frame<'_>, app: &mut App, theme: Theme, config: &EffectiveConfig) {
let area = frame.area();
if area.width < 60 || area.height < 12 {
render_too_small(frame, area, theme);
return;
}
let [header, body, footer] = Layout::vertical([
Constraint::Length(2),
Constraint::Min(6),
Constraint::Length(2),
])
.areas(area);
render_header(frame, header, app, theme, config);
match app.route {
Route::Search => render_search(frame, body, app, theme),
Route::Detail => render_detail(frame, body, app, theme),
Route::Officers => render_officers(frame, body, app, theme),
Route::Document => render_document(frame, body, app, theme),
Route::Auth => render_auth(frame, body, app, theme, config),
}
render_footer(frame, footer, app, theme);
if app.overlay == Some(Overlay::Help) {
render_help(frame, area, theme);
}
}
fn render_header(
frame: &mut Frame<'_>,
area: Rect,
app: &App,
theme: Theme,
config: &EffectiveConfig,
) {
let (indicator, state, state_color) = if app.loading {
(app.spinner(), "running", theme.warn)
} else if app.terminal_focused {
("●", "ready", theme.good)
} else {
("○", "unfocused", theme.muted)
};
let mut spans = vec![
Span::styled(
" CORAGRID ",
Style::default()
.fg(theme.accent)
.add_modifier(Modifier::BOLD),
),
Span::styled(
format!("{} ", app.route.label()),
Style::default().fg(theme.muted),
),
];
if area.width >= 100 {
spans.extend([
Span::raw("private markets made computable"),
Span::styled(
format!(" {} ", display_origin(&config.api_base_url)),
Style::default().fg(theme.muted),
),
]);
}
spans.extend([
Span::styled(format!("{indicator} "), Style::default().fg(state_color)),
Span::styled(state, Style::default().fg(state_color)),
]);
let title = Line::from(spans);
frame.render_widget(Paragraph::new(title), area);
}
fn render_search(frame: &mut Frame<'_>, area: Rect, app: &mut App, theme: Theme) {
let [composer, content] =
Layout::vertical([Constraint::Length(3), Constraint::Min(3)]).areas(area);
let query_title = format!(
" {} · Tab switches mode{} ",
app.query_mode.label(),
if app.focus == Focus::Query {
" · editing"
} else {
""
}
);
let content_width = composer.width.saturating_sub(2);
let (visible_query, cursor_column) =
query_window(&app.query, app.query_cursor, usize::from(content_width));
let query_line = if app.query.is_empty() {
Line::styled(
app.query_mode.placeholder(),
Style::default().fg(theme.muted),
)
} else {
Line::raw(visible_query)
};
let query = Paragraph::new(query_line)
.block(
Block::default()
.borders(Borders::ALL)
.title(query_title)
.border_style(if app.focus == Focus::Query {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.muted)
}),
)
.style(Style::default());
frame.render_widget(query, composer);
if app.focus == Focus::Query && app.terminal_focused && app.overlay.is_none() {
frame.set_cursor_position(Position::new(
composer.x + 1 + cursor_column,
composer.y + 1,
));
}
if app.query_mode == crate::tui::app::QueryMode::Document {
frame.render_widget(
Paragraph::new(vec![
Line::styled(
"Permanent source document lookup",
Style::default()
.fg(theme.accent)
.add_modifier(Modifier::BOLD),
),
Line::raw(""),
Line::raw("Paste a doc_ ID and press Enter."),
Line::raw(""),
Line::raw("Only rights-qualified metadata is requested."),
Line::raw("Document bytes, previews, and signed URLs are unavailable."),
])
.block(Block::default().borders(Borders::ALL).title(" evidence "))
.wrap(Wrap { trim: false }),
content,
);
} else if content.width >= 100 {
let [results, preview] =
Layout::horizontal([Constraint::Percentage(46), Constraint::Percentage(54)])
.areas(content);
render_results(frame, results, app, theme);
render_preview(frame, preview, app.selected(), theme);
} else {
render_results(frame, content, app, theme);
}
}
fn render_results(frame: &mut Frame<'_>, area: Rect, app: &mut App, theme: Theme) {
let items = app
.results
.iter()
.map(|company| {
let name = company.name.as_deref().unwrap_or("n/a");
let country = company.country.as_deref().unwrap_or("--");
let score = company
.relevance
.map(|score| format!(" {score:.3}"))
.unwrap_or_default();
ListItem::new(Line::from(vec![
Span::styled(format!("{country:<2} "), Style::default().fg(theme.muted)),
Span::raw(name),
Span::styled(score, Style::default().fg(theme.muted)),
Span::styled(
format!(" {}", company.id),
Style::default().fg(theme.accent),
),
]))
})
.collect::<Vec<_>>();
let list = List::new(items)
.block(
Block::default()
.borders(Borders::ALL)
.title(format!(" companies · {} ", app.results.len()))
.border_style(if app.focus == Focus::Results {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.muted)
}),
)
.highlight_symbol("› ")
.highlight_style(theme.selected);
let selected = if app.results.is_empty() {
None
} else {
Some(app.selection.min(app.results.len() - 1))
};
let mut state = ListState::default().with_selected(selected);
frame.render_stateful_widget(list, area, &mut state);
}
fn render_preview(
frame: &mut Frame<'_>,
area: Rect,
company: Option<&CompanyListItem>,
theme: Theme,
) {
let Some(company) = company else {
frame.render_widget(
Paragraph::new("Submit a query, then select a company.")
.block(Block::default().borders(Borders::ALL).title(" preview "))
.style(Style::default().fg(theme.muted)),
area,
);
return;
};
let mut lines = vec![
field_line("ID", company.id.as_str(), theme.accent),
field_line(
"name",
company.name.as_deref().unwrap_or("n/a"),
Color::Reset,
),
field_line(
"country",
company.country.as_deref().unwrap_or("n/a"),
Color::Reset,
),
field_line(
"status",
company.status.as_deref().unwrap_or("n/a"),
theme.good,
),
];
if let Some(score) = company.relevance {
lines.push(field_line(
"relevance",
&format!("{score:.4}"),
Color::Reset,
));
}
if !company.match_reasons.is_empty() {
lines.push(field_line(
"matched by",
&company.match_reasons.join(", "),
Color::Reset,
));
}
lines.push(Line::raw(""));
lines.push(Line::styled(
"Enter opens the canonical company profile.",
Style::default().fg(theme.muted),
));
frame.render_widget(
Paragraph::new(lines)
.block(Block::default().borders(Borders::ALL).title(" preview "))
.wrap(Wrap { trim: false }),
area,
);
}
fn render_detail(frame: &mut Frame<'_>, area: Rect, app: &App, theme: Theme) {
let Some(company) = app.detail.as_ref() else {
frame.render_widget(
Paragraph::new("No company loaded.")
.block(Block::default().borders(Borders::ALL).title(" company ")),
area,
);
return;
};
let rows = [
("ID", company.id.to_string()),
("lifecycle", company.lifecycle.status.clone()),
("name", optional(company.name.as_deref())),
("country", optional(company.country_code.as_deref())),
(
"company status",
optional(company.company_status.as_deref()),
),
("company type", optional(company.company_type.as_deref())),
("industry", optional(company.industry.as_deref())),
(
"business model",
optional(company.business_model.as_deref()),
),
(
"product category",
optional(company.product_category.as_deref()),
),
(
"operating geography",
optional(company.operating_geography.as_deref()),
),
("as of", optional(company.as_of_date.as_deref())),
]
.into_iter()
.map(|(label, value)| {
Row::new([label.to_owned(), value]).style(if label == "ID" {
Style::default().fg(theme.accent)
} else {
Style::default()
})
});
let table = Table::new(rows, [Constraint::Length(22), Constraint::Min(20)])
.block(
Block::default()
.borders(Borders::ALL)
.title(" canonical company "),
)
.column_spacing(2);
if area.width >= 100 {
let [profile, evidence] =
Layout::horizontal([Constraint::Percentage(68), Constraint::Percentage(32)])
.areas(area);
frame.render_widget(table, profile);
frame.render_widget(
Paragraph::new(vec![
Line::styled("Source-linked evidence", Style::default().fg(theme.accent)),
Line::raw(""),
Line::raw("Press o to inspect current source-attributed officers."),
Line::raw(""),
Line::raw("Use Tab to select document mode and inspect a doc_ ID."),
Line::raw("Fact resources and document bytes remain governance-gated."),
])
.block(Block::default().borders(Borders::ALL).title(" evidence "))
.wrap(Wrap { trim: false }),
evidence,
);
} else {
frame.render_widget(table, area);
}
}
fn render_officers(frame: &mut Frame<'_>, area: Rect, app: &mut App, theme: Theme) {
let Some(page) = app.officers.as_ref() else {
frame.render_widget(
Paragraph::new("No officer resource loaded.")
.block(Block::default().borders(Borders::ALL).title(" officers ")),
area,
);
return;
};
let selected = page.data.get(app.officer_selection);
let title = format!(" current officers · {} ", page.data.len());
let header = Row::new(["NAME", "ROLE", "APPOINTED", "SOURCE"]).style(
Style::default()
.fg(theme.muted)
.add_modifier(Modifier::BOLD),
);
let rows = page.data.iter().map(|officer| {
Row::new([
officer.name.clone(),
if officer.roles.is_empty() {
"n/a".to_owned()
} else {
officer.roles.join(", ")
},
optional(officer.appointed_on.as_deref()),
officer.source.system.clone(),
])
});
let table = Table::new(
rows,
[
Constraint::Length(24),
Constraint::Min(16),
Constraint::Length(12),
Constraint::Length(20),
],
)
.header(header)
.block(Block::default().borders(Borders::ALL).title(title))
.column_spacing(1)
.row_highlight_style(theme.selected)
.highlight_symbol("› ");
let selected_index = (!page.data.is_empty())
.then_some(app.officer_selection.min(page.data.len().saturating_sub(1)));
let mut state = TableState::default().with_selected(selected_index);
if area.width >= 110 {
let [list, provenance] =
Layout::horizontal([Constraint::Percentage(72), Constraint::Percentage(28)])
.areas(area);
frame.render_stateful_widget(table, list, &mut state);
render_officer_source(frame, provenance, page, selected, theme);
} else {
frame.render_stateful_widget(table, area, &mut state);
}
}
fn render_officer_source(
frame: &mut Frame<'_>,
area: Rect,
page: &crate::client::CompanyOfficerPage,
officer: Option<&crate::client::CompanyOfficerResource>,
theme: Theme,
) {
let mut lines = vec![field_line(
"company",
page.company_id.as_str(),
theme.accent,
)];
if page.requested_company_id != page.company_id {
lines.push(field_line(
"requested",
page.requested_company_id.as_str(),
Color::Reset,
));
}
lines.push(Line::raw(""));
if let Some(officer) = officer {
lines.extend([
field_line("source", &officer.source.system, theme.accent),
field_line(
"observed",
officer.source.observed_at.as_deref().unwrap_or("n/a"),
Color::Reset,
),
field_line(
"published",
officer.source.published_at.as_deref().unwrap_or("n/a"),
Color::Reset,
),
field_line(
"source URL",
officer.source.url.as_deref().unwrap_or("n/a"),
Color::Reset,
),
]);
} else {
lines.push(Line::styled(
"No current officers returned.",
Style::default().fg(theme.muted),
));
}
if page.has_more {
lines.extend([
Line::raw(""),
Line::styled(
"The response is bounded. Use the headless command with a higher --limit.",
Style::default().fg(theme.warn),
),
]);
}
frame.render_widget(
Paragraph::new(lines)
.block(Block::default().borders(Borders::ALL).title(" provenance "))
.wrap(Wrap { trim: false }),
area,
);
}
fn render_document(frame: &mut Frame<'_>, area: Rect, app: &App, theme: Theme) {
let Some(document) = app.document.as_ref() else {
frame.render_widget(
Paragraph::new("No document metadata loaded.")
.block(Block::default().borders(Borders::ALL).title(" document ")),
area,
);
return;
};
let rows = [
("ID", document.id.to_string()),
("lifecycle", document.lifecycle.status.clone()),
("company", document.company_id.to_string()),
("type", document.document_type.clone()),
("category", optional(document.document_category.as_deref())),
("title", optional(document.title.as_deref())),
("file name", optional(document.file_name.as_deref())),
("content type", optional(document.content_type.as_deref())),
("extension", optional(document.file_extension.as_deref())),
("SHA-256", optional(document.sha256.as_deref())),
(
"byte size",
document
.byte_size
.map_or_else(|| "n/a".to_owned(), |size| size.to_string()),
),
("filed", optional(document.filed_at.as_deref())),
(
"published date",
optional(document.published_date.as_deref()),
),
("published", optional(document.published_at.as_deref())),
("collected", document.collected_at.clone()),
("availability", document.availability.clone()),
]
.into_iter()
.map(|(label, value)| {
Row::new([label.to_owned(), value]).style(if label == "ID" || label == "company" {
Style::default().fg(theme.accent)
} else {
Style::default()
})
});
let table = Table::new(rows, [Constraint::Length(20), Constraint::Min(20)])
.block(
Block::default()
.borders(Borders::ALL)
.title(" document metadata "),
)
.column_spacing(2)
.row_highlight_style(theme.selected)
.highlight_symbol("› ");
let mut state = TableState::default()
.with_selected(Some(app.document_selection.min(DOCUMENT_FIELD_COUNT - 1)));
if area.width >= 100 {
let [metadata, provenance] =
Layout::horizontal([Constraint::Percentage(68), Constraint::Percentage(32)])
.areas(area);
frame.render_stateful_widget(table, metadata, &mut state);
let metadata_access = if document.access.metadata {
"allowed"
} else {
"denied"
};
let byte_access = if document.access.bytes {
"allowed"
} else {
"unavailable"
};
frame.render_widget(
Paragraph::new(vec![
field_line("source", &document.source.system, theme.accent),
field_line("source record", &document.source.record_id, Color::Reset),
Line::raw(""),
field_line("metadata", metadata_access, theme.good),
field_line("document bytes", byte_access, theme.warn),
Line::raw(""),
Line::styled(
"Metadata access is not a content grant. No open or download action is available.",
Style::default().fg(theme.muted),
),
])
.block(Block::default().borders(Borders::ALL).title(" provenance "))
.wrap(Wrap { trim: false }),
provenance,
);
} else {
frame.render_stateful_widget(table, area, &mut state);
}
}
fn render_auth(
frame: &mut Frame<'_>,
area: Rect,
app: &App,
theme: Theme,
config: &EffectiveConfig,
) {
let mut lines = vec![
field_line(
"endpoint",
&display_origin(&config.api_base_url),
Color::Reset,
),
field_line("profile", &config.profile, Color::Reset),
field_line(
"credential source",
&config
.credential
.as_ref()
.map(|credential| credential.kind().to_string())
.unwrap_or_else(|| "none".to_owned()),
Color::Reset,
),
Line::raw(""),
];
if let Some(caller) = app.caller.as_ref() {
lines.extend([
field_line("authenticated", "yes", theme.good),
field_line("principal", &caller.principal_type, Color::Reset),
field_line("organization", &caller.organization_id, Color::Reset),
field_line("credential", &caller.credential_id, theme.accent),
field_line("scopes", &caller.scopes.join(", "), Color::Reset),
field_line(
"max search",
&caller.limits.max_search_results.to_string(),
Color::Reset,
),
]);
} else if app.loading {
lines.push(Line::styled("Verifying…", Style::default().fg(theme.warn)));
} else {
lines.push(Line::styled(
"No verified caller response. Press a to retry.",
Style::default().fg(theme.warn),
));
}
frame.render_widget(
Paragraph::new(lines)
.block(
Block::default()
.borders(Borders::ALL)
.title(" authentication "),
)
.wrap(Wrap { trim: false }),
area,
);
}
fn render_help(frame: &mut Frame<'_>, area: Rect, theme: Theme) {
let popup = centered_fixed(
area,
area.width.saturating_sub(4).min(78),
area.height.saturating_sub(2).min(20),
);
frame.render_widget(Clear, popup);
let heading = Line::styled(
"Coragrid terminal controls",
Style::default()
.fg(theme.accent)
.add_modifier(Modifier::BOLD),
);
let help = if popup.height >= 18 {
vec![
heading,
Line::raw(""),
Line::raw("Query"),
Line::raw(" Tab modes · Enter submit · ←/→ move · Ctrl+W word"),
Line::raw(" Home/End · Backspace/Delete · Ctrl+U clear · ↓ results"),
Line::raw(""),
Line::raw("Results and views"),
Line::raw(" ↑/↓ or j/k select · PgUp/PgDn · Enter open · / query"),
Line::raw(" g/G first/last · o officers · r refresh · a auth · Esc back"),
Line::raw(""),
Line::raw("Global"),
Line::raw(" F1 help · Ctrl+C cancel/exit · Ctrl+Q quit · Ctrl+Z suspend (Unix)"),
Line::raw(""),
Line::styled(
"Headless parity includes cgd documents get <doc_id> --metadata",
Style::default().fg(theme.muted),
),
]
} else {
vec![
heading,
Line::raw("Tab mode · Enter submit/open · ↑/↓ select"),
Line::raw("←/→ edit · Ctrl+W word · Ctrl+U clear"),
Line::raw("/ query · a auth · r refresh · Esc back"),
Line::raw("F1/Esc close · Ctrl+C cancel · Ctrl+Q quit"),
Line::styled(
"Headless commands remain available.",
Style::default().fg(theme.muted),
),
]
};
frame.render_widget(
Paragraph::new(help)
.block(Block::default().borders(Borders::ALL).title(" help "))
.wrap(Wrap { trim: false }),
popup,
);
}
fn render_footer(frame: &mut Frame<'_>, area: Rect, app: &App, theme: Theme) {
let notice = app.notice.as_deref().unwrap_or("ready");
let notice_color = if notice.starts_with("failed") {
theme.bad
} else if app.loading {
theme.warn
} else {
theme.muted
};
let [status_area, hints_area] =
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas(area);
let status = if app.loading {
format!(" {} {notice}", app.spinner())
} else {
format!(" {notice}")
};
if area.width >= 100 {
let [notice_area, request_area] =
Layout::horizontal([Constraint::Min(20), Constraint::Percentage(42)])
.areas(status_area);
frame.render_widget(
Paragraph::new(status).style(Style::default().fg(notice_color)),
notice_area,
);
if let Some(request_id) = app.request_id.as_deref() {
frame.render_widget(
Paragraph::new(format!("request {request_id} "))
.alignment(Alignment::Right)
.style(Style::default().fg(theme.muted)),
request_area,
);
}
} else {
frame.render_widget(
Paragraph::new(status).style(Style::default().fg(notice_color)),
status_area,
);
}
frame.render_widget(
Paragraph::new(contextual_hints(app, area.width))
.alignment(Alignment::Right)
.style(Style::default().fg(theme.muted)),
hints_area,
);
}
fn render_too_small(frame: &mut Frame<'_>, area: Rect, theme: Theme) {
frame.render_widget(
Paragraph::new(vec![
Line::styled(
"Terminal too small for Coragrid TUI.",
Style::default().fg(theme.warn),
),
Line::raw("Resize to at least 60×12, or use headless commands:"),
Line::raw("cgd resolve --help"),
Line::raw("cgd companies search --help"),
Line::raw("cgd documents get --help"),
Line::raw("Press Ctrl+Q to quit."),
])
.block(Block::default().borders(Borders::ALL).title(" cgd "))
.wrap(Wrap { trim: false }),
area,
);
}
fn field_line(label: &str, value: &str, color: Color) -> Line<'static> {
Line::from(vec![
Span::styled(
format!("{label:<20} "),
Style::default().fg(Color::DarkGray),
),
Span::styled(value.to_owned(), Style::default().fg(color)),
])
}
fn optional(value: Option<&str>) -> String {
value.unwrap_or("n/a").to_owned()
}
fn centered_fixed(area: Rect, width: u16, height: u16) -> Rect {
let [vertical] = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(height)])
.flex(ratatui::layout::Flex::Center)
.areas(area);
let [horizontal] = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Length(width)])
.flex(ratatui::layout::Flex::Center)
.areas(vertical);
horizontal
}
fn query_window(query: &str, cursor: usize, max_width: usize) -> (String, u16) {
if max_width == 0 {
return (String::new(), 0);
}
let mut start = cursor;
let mut width_before_cursor = 0;
let max_width_before_cursor = max_width.saturating_sub(1);
for (index, grapheme) in query[..cursor].grapheme_indices(true).rev() {
let width = UnicodeWidthStr::width(grapheme);
if width_before_cursor + width > max_width_before_cursor {
break;
}
start = index;
width_before_cursor += width;
}
let mut visible = String::new();
let mut visible_width = 0;
for grapheme in query[start..].graphemes(true) {
let width = UnicodeWidthStr::width(grapheme);
if visible_width + width > max_width {
break;
}
visible.push_str(grapheme);
visible_width += width;
}
(visible, width_before_cursor as u16)
}
fn contextual_hints(app: &App, width: u16) -> &'static str {
if app.overlay == Some(Overlay::Help) {
return "F1/Esc close help · Ctrl+Q quit ";
}
if width < 75 {
return "F1 help · Ctrl+Q quit ";
}
match (app.route, app.focus) {
(Route::Search, Focus::Query) => {
"Enter submit · Tab mode · ↓ results · F1 help · Ctrl+Q quit "
}
(Route::Search, Focus::Results) => {
"↑/↓ select · Enter open · / query · F1 help · Ctrl+Q quit "
}
(Route::Detail, _) => "o officers · r refresh · Esc back · F1 help · Ctrl+Q quit ",
(Route::Officers, _) => "↑/↓ select · r refresh · Esc company · F1 help · Ctrl+Q quit ",
(Route::Document, _) => "↑/↓ fields · r refresh · Esc back · F1 help · Ctrl+Q quit ",
(Route::Auth, _) => "a retry · Esc back · F1 help · Ctrl+Q quit ",
}
}
#[cfg(test)]
mod tests {
use ratatui::backend::TestBackend;
use ratatui::Terminal;
use std::path::PathBuf;
use std::time::Duration;
use url::Url;
use super::*;
use crate::config::{EffectiveConfig, OutputFormat};
#[test]
fn representative_layouts_render_without_panicking() {
let config = EffectiveConfig {
profile: "test".to_owned(),
api_base_url: Url::parse("https://api.coragrid.com/").unwrap(),
output: OutputFormat::Table,
timeout: Duration::from_secs(10),
no_color: true,
workspace: None,
credential_ref: None,
credential: None,
config_path: PathBuf::from("/test/config.toml"),
warnings: Vec::new(),
};
for (width, height) in [(60, 20), (100, 30), (160, 45)] {
let backend = TestBackend::new(width, height);
let mut terminal = Terminal::new(backend).unwrap();
let mut app = App::new(&[]);
app.set_query("Nordic robotics");
terminal
.draw(|frame| {
render(
frame,
&mut app,
Theme::from_argument(ThemeArg::Mono),
&config,
)
})
.unwrap();
let company_id = "co_014d2pf2dbsqqg28t5cy4tqkff"
.parse::<crate::client::CompanyId>()
.unwrap();
app.route = Route::Officers;
app.officers = Some(crate::client::CompanyOfficerPage {
object: "company_officer_list".to_owned(),
requested_company_id: company_id.clone(),
company_id,
data: vec![crate::client::CompanyOfficerResource {
object: "company_officer".to_owned(),
name: "Anna Virtanen".to_owned(),
roles: vec!["Chief executive officer".to_owned()],
appointed_on: Some("2024-01-15".to_owned()),
resigned_on: None,
source: crate::client::OfficerSource {
system: "official_company_register".to_owned(),
url: Some("https://registry.example/officers/anna".to_owned()),
title: None,
published_at: None,
observed_at: Some("2026-07-15T07:00:00Z".to_owned()),
},
}],
has_more: false,
});
terminal
.draw(|frame| {
render(
frame,
&mut app,
Theme::from_argument(ThemeArg::Mono),
&config,
)
})
.unwrap();
let document: crate::client::Envelope<crate::client::DocumentResource> =
serde_json::from_str(crate::client::TEST_DOCUMENT_METADATA).unwrap();
app.route = Route::Document;
app.document = Some(document.data);
terminal
.draw(|frame| {
render(
frame,
&mut app,
Theme::from_argument(ThemeArg::Mono),
&config,
)
})
.unwrap();
}
}
#[test]
fn query_window_keeps_a_wide_character_cursor_visible() {
let query = "abcdefghij🙂k";
let cursor = query.find('🙂').unwrap() + '🙂'.len_utf8();
let (visible, column) = query_window(query, cursor, 6);
assert_eq!(visible, "hij🙂k");
assert_eq!(column, 5);
}
}