Added config/cli arg for the state to start in

This commit is contained in:
Xithrius 2022-10-21 23:25:47 -07:00
parent 0d622334c9
commit 2a9e793735
No known key found for this signature in database
GPG Key ID: A867F27CC80B28C1
5 changed files with 54 additions and 14 deletions

View File

@ -15,6 +15,8 @@ tick_delay = 30
maximum_messages = 150
# The file path to log to.
log_file = ""
# The state the application will start in.
start_state = "normal"
[storage]
# If previous channels switched to should be tracked.

View File

@ -1,9 +1,12 @@
#![allow(clippy::use_self)]
use std::{
cmp::{Eq, PartialEq},
collections::VecDeque,
};
use rustyline::line_buffer::LineBuffer;
use serde::{Deserialize, Serialize};
use tui::style::Style;
use crate::{
@ -18,7 +21,7 @@ use crate::{
const INPUT_BUFFER_LIMIT: usize = 4096;
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum State {
Normal,
Insert,
@ -84,7 +87,7 @@ impl App {
messages: VecDeque::with_capacity(config.terminal.maximum_messages),
storage: Storage::new("storage.json", &config.storage),
filters: Filters::new("filters.txt", &config.filters),
state: State::Normal,
state: config.terminal.start_state.clone(),
input_buffer: LineBuffer::with_capacity(INPUT_BUFFER_LIMIT),
buffer_suggestion: None,
scroll_offset: 0,

View File

@ -1,8 +1,11 @@
use clap::{builder::PossibleValue, Parser};
use clap::{builder::PossibleValue, Parser, ValueEnum};
use crate::handlers::config::{Alignment, CompleteConfig, Palette, Theme};
use crate::handlers::{
app::State,
config::{Alignment, CompleteConfig, Palette, Theme},
};
impl clap::ValueEnum for Alignment {
impl ValueEnum for Alignment {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Left, Self::Center, Self::Right]
}
@ -16,7 +19,7 @@ impl clap::ValueEnum for Alignment {
}
}
impl clap::ValueEnum for Palette {
impl ValueEnum for Palette {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Pastel, Self::Vibrant, Self::Warm, Self::Cool]
}
@ -31,7 +34,7 @@ impl clap::ValueEnum for Palette {
}
}
impl clap::ValueEnum for Theme {
impl ValueEnum for Theme {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Dark, Self::Light]
}
@ -44,6 +47,28 @@ impl clap::ValueEnum for Theme {
}
}
impl ValueEnum for State {
fn value_variants<'a>() -> &'a [Self] {
&[
Self::Normal,
Self::Insert,
Self::Help,
Self::ChannelSwitch,
Self::MessageSearch,
]
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(PossibleValue::new(match self {
Self::Normal => "normal",
Self::Insert => "insert",
Self::Help => "help",
Self::ChannelSwitch => "channel",
Self::MessageSearch => "search",
}))
}
}
#[derive(Parser, Debug)]
#[clap(rename_all = "kebab-case")]
#[clap(author, version, about)]
@ -82,6 +107,9 @@ pub struct Cli {
/// The theme of the terminal
#[arg(long)]
pub theme: Option<Theme>,
/// The starting state of the terminal
#[arg(short, long)]
pub start_state: Option<State>,
}
pub fn merge_args_into_config(config: &mut CompleteConfig, args: Cli) {
@ -97,6 +125,9 @@ pub fn merge_args_into_config(config: &mut CompleteConfig, args: Cli) {
if let Some(max_messages) = args.max_messages {
config.terminal.maximum_messages = max_messages;
}
if let Some(start_state) = args.start_state {
config.terminal.start_state = start_state;
}
// Twitch arguments
if let Some(channel) = args.channel {

View File

@ -12,7 +12,10 @@ use color_eyre::eyre::{bail, Error, Result};
use serde::{Deserialize, Serialize};
use crate::{
handlers::args::{merge_args_into_config, Cli},
handlers::{
app::State,
args::{merge_args_into_config, Cli},
},
utils::pathing::config_path,
};
@ -53,8 +56,10 @@ pub struct TerminalConfig {
pub maximum_messages: usize,
/// The file path to log to.
pub log_file: Option<String>,
/// if debug logging should be enabled
/// if debug logging should be enabled.
pub verbose: bool,
/// What state the application should start in.
pub start_state: State,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@ -120,6 +125,7 @@ impl Default for TerminalConfig {
maximum_messages: 150,
log_file: None,
verbose: false,
start_state: State::Normal,
}
}
}

View File

@ -9,16 +9,14 @@ use tui::{
};
use crate::{
handlers::config::{FrontendConfig, Palette},
handlers::config::{FrontendConfig, Palette, Theme},
utils::{
colors::hsl_to_rgb,
styles::{self, HIGHLIGHT_NAME_DARK, HIGHLIGHT_NAME_LIGHT},
styles::{HIGHLIGHT_NAME_DARK, HIGHLIGHT_NAME_LIGHT, SYSTEM_CHAT},
text::align_text,
},
};
use super::config::Theme;
lazy_static! {
pub static ref FUZZY_FINDER: SkimMatcherV2 = SkimMatcherV2::default();
}
@ -182,7 +180,7 @@ impl Data {
frontend_config.maximum_username_length,
))
.style(if self.system {
styles::SYSTEM_CHAT
SYSTEM_CHAT
} else {
Style::default().fg(self.hash_username(&frontend_config.palette))
}),