mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-08 04:25:23 +00:00
refactor(debug): improve configuration debug logging
This commit is contained in:
parent
82e3f890c8
commit
ddadf3937d
@ -2,12 +2,12 @@ use crate::action::Action;
|
|||||||
use crate::event::{convert_raw_event_to_key, Key};
|
use crate::event::{convert_raw_event_to_key, Key};
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Hash)]
|
||||||
pub enum Binding {
|
pub enum Binding {
|
||||||
SingleKey(Key),
|
SingleKey(Key),
|
||||||
MultipleKeys(Vec<Key>),
|
MultipleKeys(Vec<Key>),
|
||||||
@ -28,7 +28,7 @@ impl Display for Binding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
|
||||||
pub struct KeyBindings(pub FxHashMap<Action, Binding>);
|
pub struct KeyBindings(pub FxHashMap<Action, Binding>);
|
||||||
|
|
||||||
impl<I> From<I> for KeyBindings
|
impl<I> From<I> for KeyBindings
|
||||||
|
@ -10,7 +10,7 @@ use directories::ProjectDirs;
|
|||||||
pub use keybindings::merge_keybindings;
|
pub use keybindings::merge_keybindings;
|
||||||
pub use keybindings::{parse_key, Binding, KeyBindings};
|
pub use keybindings::{parse_key, Binding, KeyBindings};
|
||||||
use previewers::PreviewersConfig;
|
use previewers::PreviewersConfig;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use shell_integration::ShellIntegrationConfig;
|
use shell_integration::ShellIntegrationConfig;
|
||||||
pub use themes::Theme;
|
pub use themes::Theme;
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
@ -25,7 +25,7 @@ mod ui;
|
|||||||
const DEFAULT_CONFIG: &str = include_str!("../../.config/config.toml");
|
const DEFAULT_CONFIG: &str = include_str!("../../.config/config.toml");
|
||||||
|
|
||||||
#[allow(dead_code, clippy::module_name_repetitions)]
|
#[allow(dead_code, clippy::module_name_repetitions)]
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct AppConfig {
|
pub struct AppConfig {
|
||||||
#[serde(default = "get_data_dir")]
|
#[serde(default = "get_data_dir")]
|
||||||
@ -48,7 +48,7 @@ impl Hash for AppConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Hash)]
|
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Hash)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// General application configuration
|
/// General application configuration
|
||||||
@ -128,7 +128,10 @@ impl Config {
|
|||||||
let final_cfg =
|
let final_cfg =
|
||||||
Self::merge_user_with_default(default_config, user_cfg);
|
Self::merge_user_with_default(default_config, user_cfg);
|
||||||
|
|
||||||
debug!("Config: {:?}", final_cfg);
|
debug!(
|
||||||
|
"Configuration: \n{}",
|
||||||
|
toml::to_string(&final_cfg).unwrap()
|
||||||
|
);
|
||||||
Ok(final_cfg)
|
Ok(final_cfg)
|
||||||
} else {
|
} else {
|
||||||
// otherwise, create the default configuration file
|
// otherwise, create the default configuration file
|
||||||
@ -209,10 +212,8 @@ pub fn get_data_dir() -> PathBuf {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let directory = if let Some(s) = data_folder {
|
let directory = if let Some(s) = data_folder {
|
||||||
debug!("Using data directory: {:?}", s);
|
|
||||||
s
|
s
|
||||||
} else if let Some(proj_dirs) = project_directory() {
|
} else if let Some(proj_dirs) = project_directory() {
|
||||||
debug!("Falling back to default data dir");
|
|
||||||
proj_dirs.data_local_dir().to_path_buf()
|
proj_dirs.data_local_dir().to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from("../../../../..").join(".data")
|
PathBuf::from("../../../../..").join(".data")
|
||||||
@ -233,20 +234,17 @@ pub fn get_config_dir() -> PathBuf {
|
|||||||
.filter(|p| p.is_absolute())
|
.filter(|p| p.is_absolute())
|
||||||
});
|
});
|
||||||
let directory = if let Some(s) = config_dir {
|
let directory = if let Some(s) = config_dir {
|
||||||
debug!("Config directory: {:?}", s);
|
|
||||||
s
|
s
|
||||||
} else if cfg!(unix) {
|
} else if cfg!(unix) {
|
||||||
// default to ~/.config/television for unix systems
|
// default to ~/.config/television for unix systems
|
||||||
if let Some(base_dirs) = directories::BaseDirs::new() {
|
if let Some(base_dirs) = directories::BaseDirs::new() {
|
||||||
let cfg_dir =
|
let cfg_dir =
|
||||||
base_dirs.home_dir().join(".config").join("television");
|
base_dirs.home_dir().join(".config").join("television");
|
||||||
debug!("Config directory: {:?}", cfg_dir);
|
|
||||||
cfg_dir
|
cfg_dir
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from("../../../../..").join(".config")
|
PathBuf::from("../../../../..").join(".config")
|
||||||
}
|
}
|
||||||
} else if let Some(proj_dirs) = project_directory() {
|
} else if let Some(proj_dirs) = project_directory() {
|
||||||
debug!("Falling back to default config dir");
|
|
||||||
proj_dirs.config_local_dir().to_path_buf()
|
proj_dirs.config_local_dir().to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from("../../../../..").join("../../../../../.config")
|
PathBuf::from("../../../../..").join("../../../../../.config")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::preview::{previewers, PreviewerConfig};
|
use crate::preview::{previewers, PreviewerConfig};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, Hash)]
|
||||||
pub struct PreviewersConfig {
|
pub struct PreviewersConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub basic: BasicPreviewerConfig,
|
pub basic: BasicPreviewerConfig,
|
||||||
@ -17,10 +17,10 @@ impl From<PreviewersConfig> for PreviewerConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, Hash)]
|
||||||
pub struct BasicPreviewerConfig {}
|
pub struct BasicPreviewerConfig {}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Hash)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct FilePreviewerConfig {
|
pub struct FilePreviewerConfig {
|
||||||
//pub max_file_size: u64,
|
//pub max_file_size: u64,
|
||||||
@ -36,5 +36,5 @@ impl Default for FilePreviewerConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, Hash)]
|
||||||
pub struct EnvVarPreviewerConfig {}
|
pub struct EnvVarPreviewerConfig {}
|
||||||
|
@ -4,9 +4,9 @@ use crate::config::parse_key;
|
|||||||
use crate::event::Key;
|
use crate::event::Key;
|
||||||
use crate::utils::hashmaps;
|
use crate::utils::hashmaps;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ShellIntegrationConfig {
|
pub struct ShellIntegrationConfig {
|
||||||
/// DEPRECATED: This is a legacy configuration option that is no longer used.
|
/// DEPRECATED: This is a legacy configuration option that is no longer used.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::screen::layout::{InputPosition, PreviewTitlePosition};
|
use crate::screen::layout::{InputPosition, PreviewTitlePosition};
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ use super::themes::DEFAULT_THEME;
|
|||||||
|
|
||||||
const DEFAULT_UI_SCALE: u16 = 100;
|
const DEFAULT_UI_SCALE: u16 = 100;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Hash)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct UiConfig {
|
pub struct UiConfig {
|
||||||
pub use_nerd_font_icons: bool,
|
pub use_nerd_font_icons: bool,
|
||||||
|
@ -15,7 +15,7 @@ use crossterm::event::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::{signal, sync::mpsc};
|
use tokio::{signal, sync::mpsc};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, trace, warn};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Event<I> {
|
pub enum Event<I> {
|
||||||
@ -247,7 +247,7 @@ fn flush_resize_events(first_resize: (u16, u16)) -> ((u16, u16), (u16, u16)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_raw_event_to_key(event: KeyEvent) -> Key {
|
pub fn convert_raw_event_to_key(event: KeyEvent) -> Key {
|
||||||
debug!("Raw event: {:?}", event);
|
trace!("Raw event: {:?}", event);
|
||||||
if event.kind == KeyEventKind::Release {
|
if event.kind == KeyEventKind::Release {
|
||||||
return Key::Null;
|
return Key::Null;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||||||
|
|
||||||
use ratatui::layout;
|
use ratatui::layout;
|
||||||
use ratatui::layout::{Constraint, Direction, Rect};
|
use ratatui::layout::{Constraint, Direction, Rect};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::config::UiConfig;
|
use crate::config::UiConfig;
|
||||||
|
|
||||||
@ -46,7 +46,9 @@ impl HelpBarLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Deserialize, Default, PartialEq, Hash)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, Deserialize, Serialize, Default, PartialEq, Hash,
|
||||||
|
)]
|
||||||
pub enum InputPosition {
|
pub enum InputPosition {
|
||||||
#[serde(rename = "top")]
|
#[serde(rename = "top")]
|
||||||
#[default]
|
#[default]
|
||||||
@ -64,7 +66,9 @@ impl Display for InputPosition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Deserialize, Default, PartialEq, Hash)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, Deserialize, Serialize, Default, PartialEq, Hash,
|
||||||
|
)]
|
||||||
pub enum PreviewTitlePosition {
|
pub enum PreviewTitlePosition {
|
||||||
#[serde(rename = "top")]
|
#[serde(rename = "top")]
|
||||||
#[default]
|
#[default]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user