This commit is contained in:
Jana Dönszelmann 2026-02-24 23:54:15 +01:00
parent 01774cb9c2
commit 5c6ced8ca0
No known key found for this signature in database
4 changed files with 69 additions and 21 deletions

View file

@ -1,20 +1,68 @@
use std::{
env::temp_dir,
ffi::OsString,
fmt::{Debug, Display},
fs::{self, File},
mem,
path::PathBuf,
process::{Command, exit},
str::FromStr,
};
mod tui;
use clap::{Parser, Subcommand};
use clap::{Parser, Subcommand, ValueEnum, builder::PossibleValue};
use jiff::Zoned;
use ratatui_themes::ThemeName;
#[repr(transparent)]
#[derive(Clone)]
pub struct Theme(ThemeName);
impl Debug for Theme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Display for Theme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.slug())
}
}
impl FromStr for Theme {
type Err = <ThemeName as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}
impl ValueEnum for Theme {
fn value_variants<'a>() -> &'a [Self] {
// Safety: repr transparent
unsafe { mem::transmute(ThemeName::all()) }
}
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
Some(PossibleValue::new(self.to_string()))
}
}
#[derive(Subcommand, Debug)]
enum Preset {
/// Explore logs
Show,
Show {
/// Path where the compiler source code lives, for links in the TUI to work.
#[arg(long = "compiler-root")]
compiler_root: Option<PathBuf>,
/// Path where the compiler source code lives, for links in the TUI to work.
#[arg(default_value_t = Theme(ThemeName::OneDarkPro))]
#[arg(long = "theme")]
theme: Theme,
},
/// Get all the typesystem related logs
Types,
@ -49,11 +97,6 @@ struct Args {
#[arg(long = "logs-dir")]
logs_dir: PathBuf,
/// Path where the compiler source code lives, for links in the TUI to work.
#[arg(global = true)]
#[arg(long = "compiler-root")]
compiler_root: Option<PathBuf>,
#[arg(trailing_var_arg = true)]
#[arg(allow_hyphen_values = true)]
#[arg(global = true)]
@ -65,12 +108,14 @@ fn main() {
preset,
logs_dir,
rest,
compiler_root,
} = Args::parse();
let rustc_log = match preset {
Preset::Show => {
tui::run(logs_dir, compiler_root);
Preset::Show {
compiler_root,
theme: Theme(theme)
}=> {
tui::run(logs_dir, compiler_root, theme);
exit(0);
}
Preset::Types => {