mod ansi;
mod cells;
mod color;
mod control;
mod emoji;
pub mod error;
pub mod export_format;
mod filesize;
mod measure;
mod segment;
mod style;
pub mod styled;
pub mod terminal_theme;
mod theme;
mod console;
pub mod file_proxy;
pub mod highlighter;
pub mod json;
pub mod markup;
pub mod pager;
pub mod text;
pub mod wrap;
pub mod r#box;
pub mod align;
pub mod bar;
pub mod columns;
pub mod constrain;
pub mod group;
pub mod layout;
pub mod live;
pub mod live_render;
pub mod loop_helpers;
pub mod markdown;
pub mod padding;
pub mod panel;
pub mod pretty;
pub mod progress;
pub mod progress_bar;
pub mod prompt;
pub mod recorder;
pub mod region;
pub mod rule;
pub mod scope;
pub mod screen;
pub mod screen_buffer;
pub mod screen_context;
pub mod spinner;
pub mod status;
pub mod syntax;
pub mod table;
pub mod traceback;
pub mod tree;
pub use cells::{cell_len, chop_cells, set_cell_size, split_graphemes};
pub use color::{
ANSI_COLOR_NAMES, Color, ColorSystem, ColorTriplet, ColorType, EIGHT_BIT_PALETTE, Palette,
STANDARD_PALETTE, SimpleColor, WINDOWS_PALETTE, blend_rgb, parse_rgb_hex,
};
pub use console::{
Console, ConsoleOptions, JustifyMethod, OverflowMethod, PagerContext, PagerOptions,
};
pub use control::{Control, escape_control_codes, strip_control_codes};
pub use error::{ParseError, Result as ParseResult};
pub use measure::{Measurement, measure_renderables};
pub use segment::{ControlType, Segment, SegmentLines, Segments};
pub use style::{MetaValue, NULL_STYLE, Style, StyleMeta, StyleStack};
pub use text::{Span, Text, TextPart};
pub use theme::{Theme, ThemeError, ThemeStack, default_styles};
pub use wrap::divide_line;
pub use ansi::AnsiDecoder;
pub use emoji::{EMOJI, Emoji, EmojiVariant};
pub use filesize::{
decimal as filesize_decimal, decimal_with_params as filesize_decimal_with_params,
pick_unit_and_suffix,
};
pub use loop_helpers::{loop_first, loop_first_last, loop_last};
pub use highlighter::{
Highlighter, NullHighlighter, RegexHighlighter, combine_regex, iso8601_highlighter,
json_highlighter, repr_highlighter,
};
pub use json::Json;
pub use align::{Align, VerticalAlignMethod};
pub use bar::Bar;
pub use columns::Columns;
pub use constrain::Constrain;
pub use group::{Group, Lines, Renderables};
pub use padding::{Padding, PaddingDimensions};
pub use panel::Panel;
pub use rule::{AlignMethod, Rule};
pub use styled::Styled;
pub use table::{Column, Row, Table};
pub use tree::{ASCII_GUIDES, BOLD_TREE_GUIDES, TREE_GUIDES, Tree, TreeGuides, TreeNodeOptions};
pub use syntax::{AnsiTheme, DEFAULT_THEME, Syntax, SyntaxTheme, SyntectTheme};
pub use pretty::{Pretty, pprint, pretty_repr};
pub use scope::{ScopeRenderable, render_scope};
pub use layout::{Layout, LayoutRender, SplitterKind};
pub use live::{Live, LiveOptions, VerticalOverflowMethod};
pub use live_render::LiveRender;
pub use progress::{
BarColumn, DownloadColumn, FileSizeColumn, MofNCompleteColumn, Progress, ProgressColumn,
ProgressReader, ProgressTask, RenderableColumn, SpinnerColumn, TaskID, TaskProgressColumn,
TextColumn, TimeElapsedColumn, TimeRemainingColumn, TotalFileSizeColumn, TrackConfig,
TransferSpeedColumn, WrapFileBuilder,
};
pub use progress_bar::ProgressBar;
pub use recorder::FrameRecorder;
pub use region::Region;
pub use screen::Screen;
pub use screen_buffer::{Cell, ScreenBuffer};
pub use screen_context::ScreenContext;
pub use spinner::{Spinner, spinner_names};
pub use status::Status;
pub use traceback::{Frame, Stack, SyntaxErrorInfo, Trace, Traceback, TracebackBuilder};
pub use prompt::{
Confirm, FloatPrompt, IntPrompt, InvalidResponse, Prompt, PromptError, Result as PromptResult,
};
pub use file_proxy::FileProxy;
pub use pager::{BufferPager, NullPager, Pager, SystemPager};
pub use export_format::{CONSOLE_HTML_FORMAT, CONSOLE_SVG_FORMAT};
pub use terminal_theme::{
DEFAULT_TERMINAL_THEME, DIMMED_MONOKAI, MONOKAI, NIGHT_OWLISH, SVG_EXPORT_THEME, TerminalTheme,
};
pub use markup::escape as escape_markup;
pub trait Renderable: Send + Sync {
fn render(&self, console: &Console, options: &ConsoleOptions) -> Segments;
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement {
Measurement::from_segments(&self.render(console, options))
}
}
pub trait RichCast {
type Output: Renderable;
fn rich(&self) -> Self::Output;
}
impl Renderable for str {
fn render(&self, _console: &Console, _options: &ConsoleOptions) -> Segments {
Segments::from(Segment::new(self.to_owned()))
}
}
impl Renderable for String {
fn render(&self, _console: &Console, _options: &ConsoleOptions) -> Segments {
Segments::from(Segment::new(self.clone()))
}
}
#[macro_export]
macro_rules! log {
($console:expr, $renderable:expr) => {
$console.log($renderable, Some(file!()), Some(line!()))
};
}
use std::sync::{Mutex, OnceLock};
pub fn get_console() -> &'static Mutex<Console> {
static CONSOLE: OnceLock<Mutex<Console>> = OnceLock::new();
CONSOLE.get_or_init(|| Mutex::new(Console::new()))
}
#[macro_export]
macro_rules! rich_print {
($($arg:tt)*) => {{
let text = format!($($arg)*);
if let Ok(mut console) = $crate::get_console().lock() {
let rendered = $crate::Text::from_markup(&text, true)
.unwrap_or_else(|_| $crate::Text::plain(&text));
let _ = console.print(&rendered, None, None, None, false, "\n");
}
}};
}