themes
This commit is contained in:
parent
01774cb9c2
commit
5c6ced8ca0
4 changed files with 69 additions and 21 deletions
65
src/main.rs
65
src/main.rs
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
use ratatui_themes::{Theme, ThemeName};
|
||||
use serde_json::de;
|
||||
use std::{
|
||||
fs::{self, DirEntry},
|
||||
io,
|
||||
|
|
@ -23,7 +24,7 @@ use ratatui::{
|
|||
crossterm::event::{self, Event, KeyCode, KeyModifiers},
|
||||
layout::{Constraint, HorizontalAlignment, Layout, Rect},
|
||||
style::Style,
|
||||
text::{Span, Text},
|
||||
text::{Line, Span, Text},
|
||||
widgets::{
|
||||
Block, Clear, List, ListItem, ListState, Padding, Paragraph, StatefulWidget, Widget, Wrap,
|
||||
},
|
||||
|
|
@ -35,9 +36,9 @@ pub mod model;
|
|||
pub mod processing;
|
||||
pub mod reader;
|
||||
|
||||
pub fn run(logs_dir: PathBuf, compiler_root: Option<PathBuf>) {
|
||||
pub fn run(logs_dir: PathBuf, compiler_root: Option<PathBuf>, theme: ThemeName) {
|
||||
let terminal = ratatui::init();
|
||||
let theme = Theme::new(ThemeName::OneDarkPro);
|
||||
let theme = Theme::new(theme);
|
||||
let app_result = App::new(logs_dir, compiler_root, theme).run(terminal);
|
||||
ratatui::restore();
|
||||
|
||||
|
|
@ -458,12 +459,13 @@ impl Widget for &mut App {
|
|||
{
|
||||
let full_file_path = canonical_rustc_root.join(&file);
|
||||
Hyperlink::new(
|
||||
format!("In file: {}", file.display()),
|
||||
Line::from(format!("In file: {}", file.display())).style(default),
|
||||
format!("file://{}:{line}", full_file_path.display()),
|
||||
)
|
||||
.render(first_line, buf);
|
||||
} else {
|
||||
Span::from(format!("In file: {}:{line}", file.display()))
|
||||
Line::from(format!("In file: {}:{line}", file.display()))
|
||||
.style(default)
|
||||
.render(first_line, buf);
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +491,7 @@ impl Widget for &mut App {
|
|||
(res, height)
|
||||
});
|
||||
|
||||
let list = ListView::new(builder, items.len());
|
||||
let list = ListView::new(builder, items.len()).style(default);
|
||||
StatefulWidget::render(list, footer_area, buf, &mut lv.footer_list);
|
||||
}
|
||||
Tab::Empty => {}
|
||||
|
|
|
|||
|
|
@ -91,10 +91,11 @@ impl LogEntry {
|
|||
|
||||
pub fn line_text(&self, accessed: bool, inline_depth: usize) -> Line<'static> {
|
||||
const NO_MESSAGE: &str = "<no message>";
|
||||
const SPACES_BEFORE: &str = " ";
|
||||
let indent = " >".repeat(inline_depth);
|
||||
match self {
|
||||
LogEntry::Single { raw } => format!(
|
||||
" ┃{}{}",
|
||||
" >".repeat(inline_depth),
|
||||
"{SPACES_BEFORE}┃{indent}{}",
|
||||
raw.fields.message().unwrap_or(NO_MESSAGE)
|
||||
)
|
||||
.into(),
|
||||
|
|
@ -105,13 +106,13 @@ impl LogEntry {
|
|||
&& let Some(s) = val.as_str()
|
||||
{
|
||||
Line::from(format!(
|
||||
"{:3}⭣{:3}⇊ ┃↪ {s}",
|
||||
"{:4}⭣{:4}⇊ ┃{indent}↪ {s}",
|
||||
sub_entries.len(),
|
||||
self.count().wrapping_sub(1)
|
||||
))
|
||||
} else {
|
||||
format!(
|
||||
" ┃{}",
|
||||
"{SPACES_BEFORE}┃{indent}{}",
|
||||
enter.fields.message().unwrap_or(NO_MESSAGE)
|
||||
)
|
||||
.into()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue