use serde::{Deserialize, Serialize};
use super::Config;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum FooterMode {
#[default]
Auto,
On,
Off,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ColorMode {
#[default]
Auto,
Always,
Never,
Minimal,
Inverted,
Dark,
Light,
Mono,
}
impl ColorMode {
pub fn from_keyword(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"auto" => Some(Self::Auto),
"always" | "on" => Some(Self::Always),
"never" | "off" => Some(Self::Never),
"minimal" => Some(Self::Minimal),
"inverted" => Some(Self::Inverted),
"dark" => Some(Self::Dark),
"light" => Some(Self::Light),
"mono" | "monochrome" => Some(Self::Mono),
_ => None,
}
}
pub fn keyword(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::Always => "always",
Self::Never => "never",
Self::Minimal => "minimal",
Self::Inverted => "inverted",
Self::Dark => "dark",
Self::Light => "light",
Self::Mono => "mono",
}
}
pub fn forced(self) -> Option<bool> {
match self {
Self::Always | Self::Minimal | Self::Inverted | Self::Dark | Self::Light => Some(true),
Self::Never | Self::Mono => Some(false),
Self::Auto => None,
}
}
pub fn is_mono(self) -> bool {
matches!(self, Self::Mono)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum MarkdownMode {
#[default]
Auto,
On,
Off,
}
#[must_use]
pub fn session_markdown_mode(report: &mut dyn FnMut(crate::tty::Notice<'static>)) -> MarkdownMode {
if let Some(mode) = std::env::var("NEWT_MARKDOWN")
.ok()
.as_deref()
.and_then(MarkdownMode::from_keyword)
{
return mode;
}
Config::resolve_unpublished(report)
.ok()
.and_then(|c| c.tui)
.map(|t| t.markdown)
.unwrap_or_default()
}
#[must_use]
pub fn markdown_is_session_pinned() -> bool {
std::env::var("NEWT_MARKDOWN")
.ok()
.as_deref()
.and_then(MarkdownMode::from_keyword)
.is_some()
}
impl MarkdownMode {
pub fn from_keyword(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"auto" => Some(Self::Auto),
"on" | "always" => Some(Self::On),
"off" | "never" => Some(Self::Off),
_ => None,
}
}
pub fn keyword(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::On => "on",
Self::Off => "off",
}
}
pub fn forced(self) -> Option<bool> {
match self {
Self::On => Some(true),
Self::Off => Some(false),
Self::Auto => None,
}
}
}
#[must_use]
pub fn session_spill_lines() -> Option<usize> {
std::env::var("NEWT_SPILL_LINES")
.ok()
.and_then(|v| v.trim().parse::<usize>().ok())
}
pub fn set_session_spill_lines(rows: Option<usize>) {
match rows {
Some(n) => crate::process_env::set_var("NEWT_SPILL_LINES", &n.to_string()),
None => crate::process_env::remove_var("NEWT_SPILL_LINES"),
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ThinkingMode {
Stream,
#[default]
Fold,
Off,
}
pub(super) fn default_spill_lines() -> usize {
3
}
pub(super) fn default_time_marker_secs() -> u64 {
300
}
pub(super) fn default_tool_output_lines() -> usize {
20
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum EditMode {
Emacs,
Vi,
#[default]
Nano,
}
impl EditMode {
pub fn as_str(&self) -> &'static str {
match self {
Self::Emacs => "emacs",
Self::Vi => "vi",
Self::Nano => "nano",
}
}
pub fn toggle(&self) -> Self {
match self {
Self::Emacs => Self::Vi,
Self::Vi => Self::Nano,
Self::Nano => Self::Emacs,
}
}
}