rusty_bubbletea/
renderer.rs1use crate::model::Cmd;
11use crate::mouse::MouseMsg;
12use crate::view::View;
13use std::fmt;
14
15pub trait Renderer: Send + Sync {
17 fn start(&mut self);
19
20 fn close(&mut self) -> Result<(), Box<dyn std::error::Error>>;
22
23 fn render(&mut self, view: View);
25
26 fn flush(&mut self, closing: bool) -> Result<(), Box<dyn std::error::Error>>;
28
29 fn reset(&mut self);
31
32 fn insert_above(&mut self, s: String) -> Result<(), Box<dyn std::error::Error>>;
34
35 fn resize(&mut self, width: usize, height: usize);
37
38 fn clear_screen(&mut self);
40
41 fn write_string(&mut self, s: &str) -> Result<usize, Box<dyn std::error::Error>>;
43
44 fn on_mouse(&mut self, msg: MouseMsg) -> Cmd;
46
47 fn set_optimizations(&mut self, hard_tabs: bool, backspace: bool, map_nl: bool);
50
51 fn set_color_profile(&mut self, p: rusty_colorprofile::Profile);
53}
54
55#[derive(Debug, Clone, PartialEq, Eq)]
57pub struct PrintLineMsg {
58 pub message_body: String,
60}
61
62pub fn print_ln(args: fmt::Arguments<'_>) -> Cmd {
64 let body = args.to_string();
65 Some(Box::new(move || {
66 Some(Box::new(PrintLineMsg { message_body: body }))
67 }))
68}
69
70pub fn print_f(args: fmt::Arguments<'_>) -> Cmd {
72 let body = args.to_string();
73 Some(Box::new(move || {
74 Some(Box::new(PrintLineMsg { message_body: body }))
75 }))
76}