mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-30 19:58:30 +00:00
improve admin command error propagation
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f047675a63
commit
bb5f2556c3
9 changed files with 192 additions and 78 deletions
|
@ -158,13 +158,18 @@ impl Console {
|
|||
|
||||
async fn process(self: Arc<Self>, line: String) {
|
||||
match self.admin.command_in_place(line, None).await {
|
||||
Ok(Some(content)) => self.output(content).await,
|
||||
Err(e) => error!("processing command: {e}"),
|
||||
_ => (),
|
||||
Ok(Some(ref content)) => self.output(content),
|
||||
Err(ref content) => self.output_err(content),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn output(self: Arc<Self>, output_content: RoomMessageEventContent) {
|
||||
fn output_err(self: Arc<Self>, output_content: &RoomMessageEventContent) {
|
||||
let output = configure_output_err(self.output.clone());
|
||||
output.print_text(output_content.body());
|
||||
}
|
||||
|
||||
fn output(self: Arc<Self>, output_content: &RoomMessageEventContent) {
|
||||
self.output.print_text(output_content.body());
|
||||
}
|
||||
|
||||
|
@ -194,12 +199,32 @@ impl Console {
|
|||
}
|
||||
}
|
||||
|
||||
/// Standalone/static markdown printer for errors.
|
||||
pub fn print_err(markdown: &str) {
|
||||
let output = configure_output_err(MadSkin::default_dark());
|
||||
output.print_text(markdown);
|
||||
}
|
||||
/// Standalone/static markdown printer.
|
||||
pub fn print(markdown: &str) {
|
||||
let output = configure_output(MadSkin::default_dark());
|
||||
output.print_text(markdown);
|
||||
}
|
||||
|
||||
fn configure_output_err(mut output: MadSkin) -> MadSkin {
|
||||
use termimad::{crossterm::style::Color, Alignment, CompoundStyle, LineStyle};
|
||||
|
||||
let code_style = CompoundStyle::with_fgbg(Color::AnsiValue(196), 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,
|
||||
};
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
fn configure_output(mut output: MadSkin) -> MadSkin {
|
||||
use termimad::{crossterm::style::Color, Alignment, CompoundStyle, LineStyle};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue