cursive_table_view

A sortable, scrollable multi-column table view widget for the cursive terminal UI library.

Library
Cargo
v0.15.0
53stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
29/100Needs Attention
Development Activity0
Maintenance0
Community44
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
58/100Fair
Architecture78
Code Quality55
Innovation35
Learning Curve65

cursive_table_view is a widget for the cursive TUI library that renders data as a sortable, scrollable, multi-column table inside a terminal application. You implement a small TableViewItem<H> trait describing how each item renders and compares per column, and the widget handles layout, keyboard and mouse navigation, focus, and header-driven sorting for you.

It is deliberately narrow in scope: a single generic TableView<T, H> view (implementing cursive’s View trait) plus builder-style column configuration, insertion/removal helpers, and submit/select/sort callbacks. There is no async runtime, database, or network layer involved — it is a pure in-process UI component meant to be embedded directly into a larger cursive application.

What You Get

  • A generic TableView<T, H> widget implementing cursive’s View trait, ready to embed via .with_name() like any other cursive view.
  • A TableViewItem<H> trait you implement once per data type to define column rendering and per-column comparison logic.
  • Built-in keyboard- and mouse-driven row selection, scrolling, and column-header sorting with no additional event-handling code required.
  • Two runnable examples (basic.rs, double.rs) demonstrating column configuration, sort callbacks, and item removal.

Common Use Cases

  • Sortable process or resource lists in TUI system monitors.
  • Scrollable log or query-result browsers inside CLI tools.
  • Multi-column pickers for selecting one item among many in an interactive terminal workflow.

Under The Hood

Architecture TableView<T, H> implements cursive’s View trait (draw/layout/on_event) and is generic over an item type T (implementing TableViewItem<H>) and a column-key type H. Internal state includes a scroll::Core for viewport scrolling, a Vec<TableColumn<H>> plus a HashMap<H, usize> for column lookup, the raw items: Vec<T>, and a separate rows_to_items: Vec<usize> index that maps display order to underlying items — sorting rewrites this index rather than the items vector, keeping item identity and mutation stable across re-sorts. Callbacks (on_sort, on_submit, on_select) are Arc-wrapped Send+Sync closures so they satisfy cursive’s cross-thread callback requirements. Drawing is split into draw_columns (headers), draw_item (a single row), and draw_content (the scrolled viewport), all invoked from the View::draw override, with layout_content computing per-column widths during View::layout. The crate is a single flat module (src/lib.rs, ~1,265 lines) with no submodules; changing the TableViewItem trait or the rows_to_items indirection would touch nearly every draw, sort, and selection method since they all key off it.

Tech Stack A Rust crate (edition 2021) built for the cursive TUI ecosystem, with a single runtime dependency, cursive_core 0.4.0 (the trait/layout backend that the full cursive crate re-exports), plus dev-dependencies cursive 0.21.0 and rand 0.8 used only by the examples and tests. There is no async runtime, database, or web layer — it is a pure in-process UI widget meant to be linked into another cursive-based terminal binary, built with stock cargo and no custom build script or workspace.

Code Quality Two unit tests in a #[cfg(test)] module cover only the insert_item path (inserting into an empty table and an existing one); sorting, removal, column management, and event handling have no dedicated tests, and there is no CI workflow in the repository. Error handling favors idiomatic Option returns (borrow_item, remove_item) over panics for out-of-bounds or missing lookups. The crate enables #![deny(missing_docs, …)] at the top of lib.rs, forcing every public item to carry a doc comment, which gives it unusually complete inline documentation for its size. Naming is consistent and idiomatic (snake_case, builder-style set_x/x pairs). No clippy or rustfmt configuration is present.

What Makes It Unique The widget itself is a standard sortable multi-column list/grid — the kind of component many GUI toolkits ship out of the box — implemented with well-known Rust patterns (index-indirection for sorting, Arc-wrapped callback closures) rather than anything novel. Its real value is context: cursive’s TUI ecosystem has very few ready-made table/grid widgets, so this crate fills a specific, narrow gap for anyone building a terminal data grid on cursive rather than writing row layout and sort logic from scratch.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search