changed bell style option to a simple boolean

This commit is contained in:
2026-02-23 14:06:10 -05:00
parent 632e7b6f00
commit 34b780c644
4 changed files with 16 additions and 35 deletions

View File

@@ -58,10 +58,10 @@ in
default = true; default = true;
description = "Whether to automatically add commands to the history as they are executed"; description = "Whether to automatically add commands to the history as they are executed";
}; };
bellStyle = lib.mkOption { bellEnabled = lib.mkOption {
type = lib.types.enum [ "none" "audible" "visible" ]; type = lib.types.bool;
default = "audible"; default = true;
description = "The style of bell to use for notifications and errors"; description = "Whether to allow fern to ring the terminal bell on certain events (e.g. command completion, errors, etc.)";
}; };
maxRecurseDepth = lib.mkOption { maxRecurseDepth = lib.mkOption {
type = lib.types.int; type = lib.types.int;
@@ -117,7 +117,7 @@ in
"shopt core.max_hist=${toString cfg.settings.maxHistoryEntries}" "shopt core.max_hist=${toString cfg.settings.maxHistoryEntries}"
"shopt core.interactive_comments=${boolToString cfg.settings.interactiveComments}" "shopt core.interactive_comments=${boolToString cfg.settings.interactiveComments}"
"shopt core.auto_hist=${boolToString cfg.settings.autoHistory}" "shopt core.auto_hist=${boolToString cfg.settings.autoHistory}"
"shopt core.bell_style=${cfg.settings.bellStyle}" "shopt core.bell_enabled=${boolToString cfg.settings.bellEnabled}"
"shopt core.max_recurse_depth=${toString cfg.settings.maxRecurseDepth}" "shopt core.max_recurse_depth=${toString cfg.settings.maxRecurseDepth}"
"shopt prompt.trunc_prompt_path=${toString cfg.settings.promptPathSegments}" "shopt prompt.trunc_prompt_path=${toString cfg.settings.promptPathSegments}"

View File

@@ -223,11 +223,8 @@ impl FernVi {
let hint = self.history.get_hint(); let hint = self.history.get_hint();
self.editor.set_hint(hint); self.editor.set_hint(hint);
} }
None => match read_shopts(|s| s.core.bell_style) { None => {
crate::shopt::FernBellStyle::Audible => {
self.writer.send_bell().ok(); self.writer.send_bell().ok();
}
crate::shopt::FernBellStyle::Visible | crate::shopt::FernBellStyle::Disable => {}
}, },
} }

View File

@@ -977,15 +977,9 @@ impl LineWriter for TermWriter {
} }
fn send_bell(&mut self) -> ShResult<()> { fn send_bell(&mut self) -> ShResult<()> {
match read_shopts(|o| o.core.bell_style) { if read_shopts(|o| o.core.bell_enabled) {
FernBellStyle::Audible => {
self.flush_write("\x07")?; self.flush_write("\x07")?;
} }
FernBellStyle::Visible => {
log::warn!("Visual bell is not supported in fern shell yet");
}
FernBellStyle::Disable => { /* Do nothing */ }
}
Ok(()) Ok(())
} }

View File

@@ -27,16 +27,6 @@ impl FromStr for FernBellStyle {
} }
} }
impl Display for FernBellStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FernBellStyle::Audible => write!(f, "audible"),
FernBellStyle::Visible => write!(f, "visible"),
FernBellStyle::Disable => write!(f, "disable"),
}
}
}
#[derive(Default, Clone, Copy, Debug)] #[derive(Default, Clone, Copy, Debug)]
pub enum FernEditMode { pub enum FernEditMode {
#[default] #[default]
@@ -159,7 +149,7 @@ pub struct ShOptCore {
pub max_hist: usize, pub max_hist: usize,
pub interactive_comments: bool, pub interactive_comments: bool,
pub auto_hist: bool, pub auto_hist: bool,
pub bell_style: FernBellStyle, pub bell_enabled: bool,
pub max_recurse_depth: usize, pub max_recurse_depth: usize,
} }
@@ -221,7 +211,7 @@ impl ShOptCore {
self.auto_hist = val; self.auto_hist = val;
} }
"bell_style" => { "bell_style" => {
let Ok(val) = val.parse::<FernBellStyle>() else { let Ok(val) = val.parse::<bool>() else {
return Err( return Err(
ShErr::simple( ShErr::simple(
ShErrKind::SyntaxErr, ShErrKind::SyntaxErr,
@@ -233,7 +223,7 @@ impl ShOptCore {
), ),
); );
}; };
self.bell_style = val; self.bell_enabled = val;
} }
"max_recurse_depth" => { "max_recurse_depth" => {
let Ok(val) = val.parse::<usize>() else { let Ok(val) = val.parse::<usize>() else {
@@ -311,8 +301,8 @@ impl ShOptCore {
Ok(Some(output)) Ok(Some(output))
} }
"bell_style" => { "bell_style" => {
let mut output = String::from("What type of bell style to use for the bell character\n"); let mut output = String::from("Whether or not to allow fern to trigger the terminal bell");
output.push_str(&format!("{}", self.bell_style)); output.push_str(&format!("{}", self.bell_enabled));
Ok(Some(output)) Ok(Some(output))
} }
"max_recurse_depth" => { "max_recurse_depth" => {
@@ -355,7 +345,7 @@ impl Display for ShOptCore {
self.interactive_comments self.interactive_comments
)); ));
output.push(format!("auto_hist = {}", self.auto_hist)); output.push(format!("auto_hist = {}", self.auto_hist));
output.push(format!("bell_style = {}", self.bell_style)); output.push(format!("bell_enabled = {}", self.bell_enabled));
output.push(format!("max_recurse_depth = {}", self.max_recurse_depth)); output.push(format!("max_recurse_depth = {}", self.max_recurse_depth));
let final_output = output.join("\n"); let final_output = output.join("\n");
@@ -373,7 +363,7 @@ impl Default for ShOptCore {
max_hist: 1000, max_hist: 1000,
interactive_comments: true, interactive_comments: true,
auto_hist: true, auto_hist: true,
bell_style: FernBellStyle::Audible, bell_enabled: true,
max_recurse_depth: 1000, max_recurse_depth: 1000,
} }
} }