feat: add parameter help icons with editable help.csv

This commit is contained in:
xin
2026-06-18 15:43:31 +08:00
parent c1a76a5875
commit c017129c9f
13 changed files with 243 additions and 229 deletions

View File

@ -0,0 +1,54 @@
use serde::Serialize;
use tauri::command;
use std::path::PathBuf;
#[derive(Debug, Serialize)]
pub struct HelpEntry {
pub key: String,
pub label: String,
pub description: String,
}
fn defaults_dir() -> PathBuf {
std::env::current_exe()
.unwrap_or_else(|_| PathBuf::from("."))
.parent()
.unwrap_or_else(|| std::path::Path::new("."))
.to_path_buf()
}
const DEFAULT_CSV: &str = include_str!("../../../help.csv");
#[command]
pub fn load_help_csv() -> Vec<HelpEntry> {
let path = defaults_dir().join("help.csv");
// Always write embedded default so file stays in sync with the binary
if let Some(parent) = path.parent() {
let _ = std::fs::create_dir_all(parent);
}
let _ = std::fs::write(&path, DEFAULT_CSV);
match std::fs::read_to_string(&path) {
Ok(c) => parse_csv(&c),
Err(_) => parse_csv(DEFAULT_CSV),
}
}
fn parse_csv(content: &str) -> Vec<HelpEntry> {
let mut entries = Vec::new();
for (i, line) in content.lines().enumerate() {
if i == 0 { continue; }
let trimmed = line.trim();
if trimmed.is_empty() { continue; }
let parts: Vec<&str> = trimmed.splitn(3, ',').collect();
if parts.len() == 3 {
entries.push(HelpEntry {
key: parts[0].trim().to_string(),
label: parts[1].trim().to_string(),
description: parts[2].trim().to_string(),
});
}
}
entries
}

View File

@ -4,3 +4,4 @@ pub mod validation_commands;
pub mod path_commands;
pub mod devtools_commands;
pub mod defaults_commands;
pub mod help_commands;

View File

@ -47,6 +47,7 @@ pub fn run() {
commands::defaults_commands::load_default_background,
commands::defaults_commands::save_planner_defaults,
commands::defaults_commands::load_planner_defaults,
commands::help_commands::load_help_csv,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");