cqlsh_rs/pager.rs
1//! Built-in terminal pager using sapling-streampager.
2//!
3//! Provides a less-like pager with vertical/horizontal scrolling, search,
4//! and proper ANSI color support. Uses termwiz for ANSI-aware rendering,
5//! so horizontal scrolling works correctly with colored output.
6//! Small output that fits the terminal is printed directly (Hybrid mode).
7
8use std::io::Cursor;
9
10use streampager::config::{InterfaceMode, WrappingMode};
11use streampager::Pager;
12
13/// Display content through the streampager pager.
14///
15/// Supports up/down scrolling, left/right horizontal scrolling for wide tables,
16/// `/pattern` search, and correctly handles ANSI color codes.
17/// If the content fits the terminal screen, it is printed directly (Hybrid mode).
18///
19/// An optional `title` is shown at the top of the pager (e.g., column names).
20///
21/// Returns `Err` if the pager fails to start; caller should fall back to direct print.
22pub fn page_content(content: &str, title: &str) -> anyhow::Result<()> {
23 let mut pager = Pager::new_using_system_terminal()?;
24 pager.set_interface_mode(InterfaceMode::Hybrid);
25 pager.set_wrapping_mode(WrappingMode::Unwrapped);
26 pager.set_scroll_past_eof(false);
27 pager.add_stream(Cursor::new(content.to_owned().into_bytes()), title)?;
28 pager.run()?;
29 Ok(())
30}