From 8affdc43a677cf51f04dc16a36978e5adde12fb3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 17 Jun 2024 00:19:17 +0000 Subject: [PATCH] additional termimad config Signed-off-by: Jason Volk --- src/service/admin/console.rs | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/service/admin/console.rs b/src/service/admin/console.rs index dc967d00..1603a057 100644 --- a/src/service/admin/console.rs +++ b/src/service/admin/console.rs @@ -27,24 +27,12 @@ const HISTORY_LIMIT: usize = 48; impl Console { #[must_use] pub fn new() -> Arc { - use termimad::{crossterm::style::Color, Alignment, CompoundStyle, LineStyle}; - - let mut output = MadSkin::default_dark(); - let code_style = CompoundStyle::with_fgbg(Color::AnsiValue(40), Color::AnsiValue(234)); - output.inline_code = code_style.clone(); - output.code_block = LineStyle { - left_margin: 0, - right_margin: 0, - align: Alignment::Left, - compound_style: code_style, - }; - Arc::new(Self { worker_join: None.into(), input_abort: None.into(), command_abort: None.into(), history: VecDeque::with_capacity(HISTORY_LIMIT).into(), - output, + output: configure_output(MadSkin::default_dark()), }) } @@ -175,8 +163,7 @@ impl Console { } async fn output(self: Arc, output_content: RoomMessageEventContent) { - let output = self.output.term_text(output_content.body()); - println!("{output}"); + self.output.print_text(output_content.body()); } fn set_history(&self, readline: &mut Readline) { @@ -192,3 +179,26 @@ impl Console { history.truncate(HISTORY_LIMIT); } } + +fn configure_output(mut output: MadSkin) -> MadSkin { + use termimad::{crossterm::style::Color, Alignment, CompoundStyle, LineStyle}; + + let code_style = CompoundStyle::with_fgbg(Color::AnsiValue(40), Color::AnsiValue(234)); + output.inline_code = code_style.clone(); + output.code_block = LineStyle { + left_margin: 0, + right_margin: 0, + align: Alignment::Left, + compound_style: code_style, + }; + + let table_style = CompoundStyle::default(); + output.table = LineStyle { + left_margin: 1, + right_margin: 1, + align: Alignment::Left, + compound_style: table_style, + }; + + output +}