mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-02 06:08:42 +00:00
feat: add colors to term views; log what component is being built; terminal view uses adwaita color scheme
This commit is contained in:
parent
2473d81817
commit
1e4648b021
14 changed files with 149 additions and 15 deletions
|
@ -2,12 +2,17 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
|
||||||
pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building Basalt...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -11,6 +12,10 @@ use std::{
|
||||||
|
|
||||||
pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building Libsurvive...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use crate::{
|
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 {
|
pub fn get_build_mercury_jobs(profile: &Profile) -> VecDeque<WorkerJob> {
|
||||||
WorkerJob::new_cmd(
|
let mut jobs = VecDeque::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building Mercury...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
jobs.push_back(WorkerJob::new_cmd(
|
||||||
None,
|
None,
|
||||||
pkg_data_dir()
|
pkg_data_dir()
|
||||||
.join("scripts/build_mercury.sh")
|
.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(),
|
profile.prefix.to_string_lossy().to_string(),
|
||||||
get_cache_dir().to_string_lossy().to_string(),
|
get_cache_dir().to_string_lossy().to_string(),
|
||||||
]),
|
]),
|
||||||
)
|
));
|
||||||
|
|
||||||
|
jobs
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -11,6 +12,10 @@ use std::{
|
||||||
|
|
||||||
pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building Monado...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -11,6 +12,10 @@ use std::{
|
||||||
|
|
||||||
pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building OpenComposite...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -11,6 +12,10 @@ use std::{
|
||||||
|
|
||||||
pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building OpenHMD...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
build_tools::{cmake::Cmake, git::Git},
|
build_tools::{cmake::Cmake, git::Git},
|
||||||
file_utils::rm_rf,
|
file_utils::rm_rf,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
termcolor::TermColor,
|
||||||
ui::job_worker::job::WorkerJob,
|
ui::job_worker::job::WorkerJob,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -11,6 +12,10 @@ use std::{
|
||||||
|
|
||||||
pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
|
||||||
let mut jobs = VecDeque::<WorkerJob>::new();
|
let mut jobs = VecDeque::<WorkerJob>::new();
|
||||||
|
jobs.push_back(WorkerJob::new_printer(
|
||||||
|
"Building WiVRn...",
|
||||||
|
Some(TermColor::Blue),
|
||||||
|
));
|
||||||
|
|
||||||
let git = Git {
|
let git = Git {
|
||||||
repo: profile
|
repo: profile
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use serde::{de::Visitor, Deserialize, Serialize};
|
use serde::{de::Visitor, Deserialize, Serialize};
|
||||||
use std::{fmt::Display, slice::Iter, str::FromStr};
|
use std::{fmt::Display, slice::Iter, str::FromStr};
|
||||||
|
|
||||||
|
use crate::termcolor::TermColor;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)]
|
||||||
pub enum LogLevel {
|
pub enum LogLevel {
|
||||||
Trace,
|
Trace,
|
||||||
|
@ -89,6 +91,17 @@ impl LogLevel {
|
||||||
Self::Error => 99,
|
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 {
|
impl PartialOrd for LogLevel {
|
||||||
|
|
|
@ -42,6 +42,7 @@ pub mod runner;
|
||||||
pub mod runner_pipeline;
|
pub mod runner_pipeline;
|
||||||
pub mod steam_linux_runtime_injector;
|
pub mod steam_linux_runtime_injector;
|
||||||
pub mod steamvr_utils;
|
pub mod steamvr_utils;
|
||||||
|
pub mod termcolor;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod xdg;
|
pub mod xdg;
|
||||||
pub mod xr_devices;
|
pub mod xr_devices;
|
||||||
|
|
49
src/termcolor.rs
Normal file
49
src/termcolor.rs
Normal 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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ use super::util::{copy_text, open_with_default_handler};
|
||||||
use super::wivrn_conf_editor::{WivrnConfEditor, WivrnConfEditorInit, WivrnConfEditorMsg};
|
use super::wivrn_conf_editor::{WivrnConfEditor, WivrnConfEditorInit, WivrnConfEditorMsg};
|
||||||
use crate::builders::build_basalt::get_build_basalt_jobs;
|
use crate::builders::build_basalt::get_build_basalt_jobs;
|
||||||
use crate::builders::build_libsurvive::get_build_libsurvive_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_monado::get_build_monado_jobs;
|
||||||
use crate::builders::build_opencomposite::get_build_opencomposite_jobs;
|
use crate::builders::build_opencomposite::get_build_opencomposite_jobs;
|
||||||
use crate::builders::build_openhmd::get_build_openhmd_jobs;
|
use crate::builders::build_openhmd::get_build_openhmd_jobs;
|
||||||
|
@ -460,7 +460,7 @@ impl SimpleComponent for App {
|
||||||
}
|
}
|
||||||
if profile.features.mercury_enabled {
|
if profile.features.mercury_enabled {
|
||||||
missing_deps.extend(get_missing_mercury_deps());
|
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 {
|
jobs.extend(match profile.xrservice_type {
|
||||||
XRServiceType::Monado => get_build_monado_jobs(&profile, clean_build),
|
XRServiceType::Monado => get_build_monado_jobs(&profile, clean_build),
|
||||||
|
|
|
@ -172,7 +172,7 @@ impl SimpleComponent for DebugView {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(format!(
|
true => Some(format!(
|
||||||
"{lvl}\t[{file}:{func}]\r\n\t{msg}\r\n",
|
"{lvl}\t[{file}:{func}]\r\n\t{msg}\r\n",
|
||||||
lvl = o.level,
|
lvl = o.level.colored(),
|
||||||
file = o.file,
|
file = o.file,
|
||||||
func = o.func,
|
func = o.func,
|
||||||
msg = o.message.replace('\n', "\r\n")
|
msg = o.message.replace('\n', "\r\n")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::termcolor::TermColor;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CmdWorkerData {
|
pub struct CmdWorkerData {
|
||||||
pub environment: HashMap<String, String>,
|
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 {
|
pub fn new_func(func: Box<dyn FnOnce() -> FuncWorkerOut + Send + Sync + 'static>) -> Self {
|
||||||
Self::Func(FuncWorkerData { func })
|
Self::Func(FuncWorkerData { func })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use gtk4::gdk;
|
use gtk4::gdk;
|
||||||
use relm4::adw;
|
use relm4::adw;
|
||||||
use vte4::{Terminal, TerminalExt};
|
use vte4::{Terminal, TerminalExt, TerminalExtManual};
|
||||||
|
|
||||||
const MAX_SCROLLBACK: u32 = 2000;
|
const MAX_SCROLLBACK: u32 = 2000;
|
||||||
|
|
||||||
|
@ -10,6 +10,13 @@ pub struct TermWidget {
|
||||||
pub term: Terminal,
|
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 {
|
impl TermWidget {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let term = Terminal::builder()
|
let term = Terminal::builder()
|
||||||
|
@ -31,14 +38,21 @@ impl TermWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_color_scheme(&self) {
|
pub fn set_color_scheme(&self) {
|
||||||
// TODO: use theme colors
|
let fg = if adw::StyleManager::default().is_dark() {
|
||||||
if adw::StyleManager::default().is_dark() {
|
ADW_DARK_FG
|
||||||
self.term
|
|
||||||
.set_color_foreground(&gdk::RGBA::new(1.0, 1.0, 1.0, 1.0));
|
|
||||||
} else {
|
} else {
|
||||||
self.term
|
ADW_LIGHT_FG
|
||||||
.set_color_foreground(&gdk::RGBA::new(0.0, 0.0, 0.0, 1.0));
|
};
|
||||||
}
|
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) {
|
pub fn feed(&self, txt: &str) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue