1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Cleanroom Rust port of upstream Go source file: `renderer.go`
//! Upstream Target Tag / Version: `v2.0.8`
//!
//! <public-docs>
//! # Renderer Trait
//!
//! Renderer interface trait for Bubble Tea v2.0.8 (`render(View)`, `flush(bool)`, `insert_above`, `clear_screen`).
//! </public-docs>
use crate::model::Cmd;
use crate::mouse::MouseMsg;
use crate::view::View;
use std::fmt;
/// Renderer interface for Bubble Tea v2.0.8.
pub trait Renderer: Send + Sync {
/// Starts the renderer.
fn start(&mut self);
/// Closes the renderer and flushes any remaining data.
fn close(&mut self) -> Result<(), Box<dyn std::error::Error>>;
/// Renders a declarative View frame.
fn render(&mut self, view: View);
/// Flushes renderer output buffer to terminal stdout.
fn flush(&mut self, closing: bool) -> Result<(), Box<dyn std::error::Error>>;
/// Resets renderer to initial state.
fn reset(&mut self);
/// Inserts unmanaged lines above the TUI renderer.
fn insert_above(&mut self, s: String) -> Result<(), Box<dyn std::error::Error>>;
/// Resize notification.
fn resize(&mut self, width: usize, height: usize);
/// Clears terminal screen.
fn clear_screen(&mut self);
/// Write raw string to output.
fn write_string(&mut self, s: &str) -> Result<usize, Box<dyn std::error::Error>>;
/// Mouse event interceptor.
fn on_mouse(&mut self, msg: MouseMsg) -> Cmd;
/// Sets the cursor movement optimizations (hard tabs, backspace,
/// newline mapping).
fn set_optimizations(&mut self, hard_tabs: bool, backspace: bool, map_nl: bool);
/// Sets the terminal color profile used for downsampling colors.
fn set_color_profile(&mut self, p: rusty_colorprofile::Profile);
}
/// PrintLineMsg represents a line printed above the TUI.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrintLineMsg {
/// Message body.
pub message_body: String,
}
/// Println prints above the Program.
pub fn print_ln(args: fmt::Arguments<'_>) -> Cmd {
let body = args.to_string();
Some(Box::new(move || {
Some(Box::new(PrintLineMsg { message_body: body }))
}))
}
/// Printf prints formatted output above the Program.
pub fn print_f(args: fmt::Arguments<'_>) -> Cmd {
let body = args.to_string();
Some(Box::new(move || {
Some(Box::new(PrintLineMsg { message_body: body }))
}))
}