feat: add colors to term views; log what component is being built; terminal view uses adwaita color scheme

This commit is contained in:
Gabriele Musco 2024-07-26 21:03:36 +02:00
parent 2473d81817
commit 1e4648b021
14 changed files with 149 additions and 15 deletions

View file

@ -2,12 +2,17 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::collections::{HashMap, VecDeque};
pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building Basalt...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -2,6 +2,7 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::{
@ -11,6 +12,10 @@ use std::{
pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building Libsurvive...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -1,9 +1,17 @@
use std::collections::VecDeque;
use crate::{
constants::pkg_data_dir, paths::get_cache_dir, profile::Profile, ui::job_worker::job::WorkerJob,
constants::pkg_data_dir, paths::get_cache_dir, profile::Profile, termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
pub fn get_build_mercury_job(profile: &Profile) -> WorkerJob {
WorkerJob::new_cmd(
pub fn get_build_mercury_jobs(profile: &Profile) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::new();
jobs.push_back(WorkerJob::new_printer(
"Building Mercury...",
Some(TermColor::Blue),
));
jobs.push_back(WorkerJob::new_cmd(
None,
pkg_data_dir()
.join("scripts/build_mercury.sh")
@ -13,5 +21,7 @@ pub fn get_build_mercury_job(profile: &Profile) -> WorkerJob {
profile.prefix.to_string_lossy().to_string(),
get_cache_dir().to_string_lossy().to_string(),
]),
)
));
jobs
}

View file

@ -2,6 +2,7 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::{
@ -11,6 +12,10 @@ use std::{
pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building Monado...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -2,6 +2,7 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::{
@ -11,6 +12,10 @@ use std::{
pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building OpenComposite...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -2,6 +2,7 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::{
@ -11,6 +12,10 @@ use std::{
pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building OpenHMD...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -2,6 +2,7 @@ use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
termcolor::TermColor,
ui::job_worker::job::WorkerJob,
};
use std::{
@ -11,6 +12,10 @@ use std::{
pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
jobs.push_back(WorkerJob::new_printer(
"Building WiVRn...",
Some(TermColor::Blue),
));
let git = Git {
repo: profile

View file

@ -1,6 +1,8 @@
use serde::{de::Visitor, Deserialize, Serialize};
use std::{fmt::Display, slice::Iter, str::FromStr};
use crate::termcolor::TermColor;
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)]
pub enum LogLevel {
Trace,
@ -89,6 +91,17 @@ impl LogLevel {
Self::Error => 99,
}
}
pub fn colored(&self) -> String {
match self {
Self::Trace => TermColor::Gray,
Self::Debug => TermColor::Gray,
Self::Info => TermColor::Blue,
Self::Warning => TermColor::Yellow,
Self::Error => TermColor::Red,
}
.colorize(&self.to_string())
}
}
impl PartialOrd for LogLevel {

View file

@ -42,6 +42,7 @@ pub mod runner;
pub mod runner_pipeline;
pub mod steam_linux_runtime_injector;
pub mod steamvr_utils;
pub mod termcolor;
pub mod ui;
pub mod xdg;
pub mod xr_devices;

49
src/termcolor.rs Normal file
View file

@ -0,0 +1,49 @@
const ANSI_ESCAPE_BEGIN: &str = "\u{001B}[";
const ANSI_ESCAPE_END: &str = "m";
const ANSI_RESET: u8 = 0;
const ANSI_BLACK: u8 = 30;
const ANSI_RED: u8 = 31;
const ANSI_GREEN: u8 = 32;
const ANSI_YELLOW: u8 = 33;
const ANSI_BLUE: u8 = 34;
const ANSI_PURPLE: u8 = 35;
const ANSI_CYAN: u8 = 36;
const ANSI_WHITE: u8 = 37;
// const ANSI_BG_ADDENDUM: u8 = 10;
const ANSI_BRIGHT_ADDENDUM: u8 = 60;
#[derive(Debug, Clone, Copy)]
pub enum TermColor {
Black,
Red,
Green,
Yellow,
Blue,
Purple,
Cyan,
White,
Gray,
}
impl TermColor {
fn code(&self) -> u8 {
match self {
Self::Black => ANSI_BLACK,
Self::Red => ANSI_RED,
Self::Green => ANSI_GREEN,
Self::Yellow => ANSI_YELLOW,
Self::Blue => ANSI_BLUE,
Self::Purple => ANSI_PURPLE,
Self::Cyan => ANSI_CYAN,
Self::White => ANSI_WHITE,
Self::Gray => ANSI_BLACK + ANSI_BRIGHT_ADDENDUM,
}
}
pub fn colorize(&self, s: &str) -> String {
format!("{ANSI_ESCAPE_BEGIN}{code}{ANSI_ESCAPE_END}{s}{ANSI_ESCAPE_BEGIN}{ANSI_RESET}{ANSI_ESCAPE_END}", code = self.code())
}
}

View file

@ -12,7 +12,7 @@ use super::util::{copy_text, open_with_default_handler};
use super::wivrn_conf_editor::{WivrnConfEditor, WivrnConfEditorInit, WivrnConfEditorMsg};
use crate::builders::build_basalt::get_build_basalt_jobs;
use crate::builders::build_libsurvive::get_build_libsurvive_jobs;
use crate::builders::build_mercury::get_build_mercury_job;
use crate::builders::build_mercury::get_build_mercury_jobs;
use crate::builders::build_monado::get_build_monado_jobs;
use crate::builders::build_opencomposite::get_build_opencomposite_jobs;
use crate::builders::build_openhmd::get_build_openhmd_jobs;
@ -460,7 +460,7 @@ impl SimpleComponent for App {
}
if profile.features.mercury_enabled {
missing_deps.extend(get_missing_mercury_deps());
jobs.push_back(get_build_mercury_job(&profile));
jobs.extend(get_build_mercury_jobs(&profile));
}
jobs.extend(match profile.xrservice_type {
XRServiceType::Monado => get_build_monado_jobs(&profile, clean_build),

View file

@ -172,7 +172,7 @@ impl SimpleComponent for DebugView {
false => None,
true => Some(format!(
"{lvl}\t[{file}:{func}]\r\n\t{msg}\r\n",
lvl = o.level,
lvl = o.level.colored(),
file = o.file,
func = o.func,
msg = o.message.replace('\n', "\r\n")

View file

@ -1,5 +1,7 @@
use std::collections::HashMap;
use crate::termcolor::TermColor;
#[derive(Debug, Clone)]
pub struct CmdWorkerData {
pub environment: HashMap<String, String>,
@ -44,6 +46,21 @@ impl WorkerJob {
})
}
pub fn new_printer(txt: &str, color: Option<TermColor>) -> Self {
let out = format!(
"{}\n",
if let Some(c) = color {
c.colorize(txt)
} else {
txt.to_string()
}
);
Self::new_func(Box::new(move || FuncWorkerOut {
out: vec![out],
success: true,
}))
}
pub fn new_func(func: Box<dyn FnOnce() -> FuncWorkerOut + Send + Sync + 'static>) -> Self {
Self::Func(FuncWorkerData { func })
}

View file

@ -1,6 +1,6 @@
use gtk4::gdk;
use relm4::adw;
use vte4::{Terminal, TerminalExt};
use vte4::{Terminal, TerminalExt, TerminalExtManual};
const MAX_SCROLLBACK: u32 = 2000;
@ -10,6 +10,13 @@ pub struct TermWidget {
pub term: Terminal,
}
const ADW_LIGHT_FG: &str = "#000000";
const ADW_DARK_FG: &str = "#ffffff";
const ADW_PALETTE: [&str; 16] = [
"#241f31", "#c01c28", "#2ec27e", "#f5c211", "#1e78e4", "#9841bb", "#0ab9dc", "#c0bfbc",
"#5e5c64", "#ed333b", "#57e389", "#f8e45c", "#51a1ff", "#c061cb", "#4fd2fd", "#f6f5f4",
];
impl TermWidget {
pub fn new() -> Self {
let term = Terminal::builder()
@ -31,14 +38,21 @@ impl TermWidget {
}
pub fn set_color_scheme(&self) {
// TODO: use theme colors
if adw::StyleManager::default().is_dark() {
self.term
.set_color_foreground(&gdk::RGBA::new(1.0, 1.0, 1.0, 1.0));
let fg = if adw::StyleManager::default().is_dark() {
ADW_DARK_FG
} else {
self.term
.set_color_foreground(&gdk::RGBA::new(0.0, 0.0, 0.0, 1.0));
}
ADW_LIGHT_FG
};
let rgba_palette = ADW_PALETTE
.iter()
.map(|c| gdk::RGBA::parse(*c).unwrap())
.collect::<Vec<gdk::RGBA>>();
self.term.set_colors(
Some(&gdk::RGBA::parse(fg).unwrap()),
None,
// better way to convert to vec of references?
rgba_palette.iter().collect::<Vec<&gdk::RGBA>>().as_slice(),
);
}
pub fn feed(&self, txt: &str) {