更好看的状态显示

This commit is contained in:
shenjack-5600u 2025-04-07 23:21:35 +08:00
parent 15b3e328d4
commit 3c5cf2e92c
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F

View File

@ -1,5 +1,6 @@
use std::{path::Path, str::FromStr}; use std::{path::Path, str::FromStr};
use colored::Colorize;
use toml_edit::{value, DocumentMut, Key, Table, TomlError, Value}; use toml_edit::{value, DocumentMut, Key, Table, TomlError, Value};
use tracing::{event, Level}; use tracing::{event, Level};
@ -135,16 +136,20 @@ impl PluginConfigFile {
} }
event!(Level::INFO, "同步插件状态"); event!(Level::INFO, "同步插件状态");
let plugins = PyStatus::get_mut(); let plugins = PyStatus::get_mut();
fn fmt_bool(b: bool) -> String {
if b { "启用".green().to_string() } else { "禁用".red().to_string() }
}
plugins.files.iter_mut().for_each(|(path, status)| { plugins.files.iter_mut().for_each(|(path, status)| {
let plugin_id = status.get_id(); let plugin_id = status.get_id();
let config_status = self.get_status(&plugin_id); let config_status = self.get_status(&plugin_id);
event!( event!(
Level::INFO, Level::INFO,
"插件状态: {}({:?}) {} -> {}", "插件状态: {} {} -> {}",
status.get_id(), status.get_id(),
path, fmt_bool(status.enabled),
status.enabled, fmt_bool(config_status)
config_status
); );
status.enabled = config_status; status.enabled = config_status;
}); });