Skip to main content

systemprompt_cli/presentation/tables/
mod.rs

1//! Reusable `tabled` table widgets for command output.
2//!
3//! Pure shaping and rendering: each function turns domain records into a
4//! rendered table string. Callers decide where the string is printed, so the
5//! row shaping stays testable without a terminal.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10mod entities;
11mod trace;
12
13pub use self::entities::{artifact_list_table, context_list_table, db_tables_table};
14pub use self::trace::{
15    ai_requests_table, execution_steps_table, extract_latency_from_metadata, format_metadata_value,
16    mcp_tool_calls_table, task_artifacts_table, task_info_table, trace_events_table,
17};
18
19use std::fmt;
20
21use crate::shared::truncate_with_ellipsis;
22
23#[must_use]
24pub fn truncate_cell(s: &str, max_len: usize) -> String {
25    let flattened = s.replace('\n', " ").replace('\r', "");
26    truncate_with_ellipsis(&flattened, max_len)
27}
28
29pub(super) fn dash() -> String {
30    "-".to_owned()
31}
32
33pub(super) struct OrDash<T>(pub(super) Option<T>);
34
35impl<T: fmt::Display> fmt::Display for OrDash<T> {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match &self.0 {
38            Some(value) => fmt::Display::fmt(value, f),
39            None => f.write_str("-"),
40        }
41    }
42}
43
44pub(super) fn millis(value: Option<impl fmt::Display>) -> String {
45    value.map_or_else(dash, |ms| format!("{ms}ms"))
46}