浏览输入框、工作栏、海洋、主题与海洋生物,再参考 Rust 示例将 Codewhale 的终端组件用于你的应用。
输入消息,按 Enter 显示消息,按 Esc 退出。入门示例在一个小应用中连接可编辑输入、原生输入框与工作栏。
git clone https://github.com/codewhale-hq/codewhale-ratatui cd codewhale-ratatui cargo run --locked --example starter
Rust 1.89+ · MIT 许可证
将组件库添加到 Cargo.toml。可使用现有终端后端,或为新应用启用 Crossterm。
[dependencies] codewhale-ratatui = { git = "https://github.com/codewhale-hq/codewhale-ratatui", rev = "4d5b05ba0709eb850e7415929b51c4db083d1241" } ratatui = { version = "0.30.2", default-features = false, features = ["std", "crossterm_0_29"] } crossterm = "0.29"
启动时检测一次主题,再传入绘制函数。Theme::detect().tui() 会选择原生终端配色。
let theme = codewhale_ratatui::Theme::detect().tui();
pub fn draw_composer( area: ratatui::layout::Rect, buffer: &mut ratatui::buffer::Buffer, theme: &codewhale_ratatui::Theme, draft: &codewhale_ratatui::TextInputState, ) -> Option<ratatui::layout::Position> { use codewhale_ratatui::{NativeComposer, Paint}; let area = area.intersection(buffer.area); if area.is_empty() { return None; } let composer = NativeComposer::new(draft.text()) .focused(true) .cursor(draft.cursor()) .can_submit(!draft.is_empty()) .placeholder("Type a line, then press Enter"); let height = composer.desired_height(area.width, area.height); let slot = ratatui::layout::Rect::new(area.x, area.bottom() - height, area.width, height); composer.paint(slot, buffer, theme); composer.cursor_position(slot) }
选择一个起点,或浏览下方的全部组件。
The live component gallery
The native conversation layout, composer and workbar, plus interactive component studies
使用示例数据,由 Rust 组件渲染。选择终端配置和宽度,比较不同布局。
TerminalShell
Message
NativeComposer
PostureBar
MetricsLine
Workbar
OceanColumn
你的应用管理状态、时间与操作。组件渲染到你提供的 Ratatui 帧。