feat: config file, closes #47
Enable use of a config file, with custom keymap and custom colours
This commit is contained in:
@@ -11,7 +11,7 @@ use ratatui::{
|
||||
widgets::{ListItem, ListState},
|
||||
};
|
||||
|
||||
use crate::ui::ORANGE;
|
||||
use crate::config::AppColors;
|
||||
|
||||
use super::Header;
|
||||
|
||||
@@ -265,16 +265,28 @@ impl State {
|
||||
pub const fn is_alive(self) -> bool {
|
||||
matches!(self, Self::Running(_))
|
||||
}
|
||||
/// Color of the state for the containers section
|
||||
/// TODO allow usable editable colours
|
||||
pub const fn get_color(self) -> Color {
|
||||
|
||||
/// Check if state is running & healthy
|
||||
pub const fn is_healthy(self) -> bool {
|
||||
match self {
|
||||
Self::Paused => Color::Yellow,
|
||||
Self::Removing => Color::LightRed,
|
||||
Self::Restarting => Color::LightGreen,
|
||||
Self::Running(RunningState::Healthy) => Color::Green,
|
||||
Self::Running(RunningState::Unhealthy) => ORANGE,
|
||||
_ => Color::Red,
|
||||
Self::Running(x) => match x {
|
||||
RunningState::Healthy => true,
|
||||
RunningState::Unhealthy => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
/// Color of the state for the containers section
|
||||
pub const fn get_color(self, colors: AppColors) -> Color {
|
||||
match self {
|
||||
Self::Dead => colors.container_state.dead,
|
||||
Self::Exited => colors.container_state.exited,
|
||||
Self::Paused => colors.container_state.paused,
|
||||
Self::Removing => colors.container_state.removing,
|
||||
Self::Restarting => colors.container_state.restarting,
|
||||
Self::Running(RunningState::Healthy) => colors.container_state.running_healthy,
|
||||
Self::Running(RunningState::Unhealthy) => colors.container_state.running_unhealthy,
|
||||
Self::Unknown => colors.container_state.unknown,
|
||||
}
|
||||
}
|
||||
/// Dirty way to create order for the state, rather than impl Ord
|
||||
@@ -348,14 +360,14 @@ pub enum DockerCommand {
|
||||
}
|
||||
|
||||
impl DockerCommand {
|
||||
pub const fn get_color(self) -> Color {
|
||||
pub const fn get_color(self, colors: AppColors) -> Color {
|
||||
match self {
|
||||
Self::Pause => Color::Yellow,
|
||||
Self::Restart => Color::Magenta,
|
||||
Self::Start => Color::Green,
|
||||
Self::Stop => Color::Red,
|
||||
Self::Delete => Color::Gray,
|
||||
Self::Resume => Color::Blue,
|
||||
Self::Pause => colors.commands.pause,
|
||||
Self::Restart => colors.commands.restart,
|
||||
Self::Start => colors.commands.start,
|
||||
Self::Stop => colors.commands.stop,
|
||||
Self::Delete => colors.commands.delete,
|
||||
Self::Resume => colors.commands.resume,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -12,7 +12,7 @@ mod container_state;
|
||||
|
||||
use crate::{
|
||||
app_error::AppError,
|
||||
parse_args::CliArgs,
|
||||
config::Config,
|
||||
ui::{log_sanitizer, GuiState, Status},
|
||||
ENTRY_POINT,
|
||||
};
|
||||
@@ -123,13 +123,13 @@ pub struct AppData {
|
||||
filter: Filter,
|
||||
hidden_containers: Vec<ContainerItem>,
|
||||
sorted_by: Option<(Header, SortedOrder)>,
|
||||
pub args: CliArgs,
|
||||
pub config: Config,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg(test)]
|
||||
pub struct AppData {
|
||||
pub args: CliArgs,
|
||||
pub config: Config,
|
||||
pub containers: StatefulList<ContainerItem>,
|
||||
pub error: Option<AppError>,
|
||||
pub filter: Filter,
|
||||
@@ -139,9 +139,9 @@ pub struct AppData {
|
||||
|
||||
impl AppData {
|
||||
/// Generate a default app_state
|
||||
pub fn default(args: CliArgs) -> Self {
|
||||
pub fn default(config: Config) -> Self {
|
||||
Self {
|
||||
args,
|
||||
config,
|
||||
containers: StatefulList::new(vec![]),
|
||||
error: None,
|
||||
filter: Filter::new(),
|
||||
@@ -657,8 +657,8 @@ impl AppData {
|
||||
|
||||
/// Error related methods
|
||||
/// Get single app_state error
|
||||
pub const fn get_error(&self) -> Option<AppError> {
|
||||
self.error
|
||||
pub fn get_error(&self) -> Option<AppError> {
|
||||
self.error.clone()
|
||||
}
|
||||
|
||||
/// Remove single app_state error
|
||||
@@ -682,7 +682,7 @@ impl AppData {
|
||||
/// Check if selected container is oxker and also that oxker is being run in a container
|
||||
pub fn is_oxker_in_container(&self) -> bool {
|
||||
self.get_selected_container()
|
||||
.is_some_and(|i| i.is_oxker && self.args.in_container)
|
||||
.is_some_and(|i| i.is_oxker && self.config.in_container)
|
||||
}
|
||||
|
||||
/// Find the widths for the strings in the containers panel.
|
||||
@@ -877,10 +877,10 @@ impl AppData {
|
||||
|
||||
/// Update logs of a given container, based on id
|
||||
pub fn update_log_by_id(&mut self, logs: Vec<String>, id: &ContainerId) {
|
||||
let color = self.args.color;
|
||||
let raw = self.args.raw;
|
||||
let color = self.config.color_logs;
|
||||
let raw = self.config.raw_logs;
|
||||
|
||||
let timestamp = self.args.timestamp;
|
||||
let timestamp = self.config.show_timestamp;
|
||||
|
||||
if let Some(container) = self.get_any_container_by_id(id) {
|
||||
if !container.is_oxker {
|
||||
|
||||
Reference in New Issue
Block a user