changed bell style option to a simple boolean

This commit is contained in:
2026-02-23 14:06:10 -05:00
parent 6f334395f7
commit 5a8b7831a8
4 changed files with 16 additions and 35 deletions

View File

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

View File

@@ -223,11 +223,8 @@ impl FernVi {
let hint = self.history.get_hint();
self.editor.set_hint(hint);
}
None => match read_shopts(|s| s.core.bell_style) {
crate::shopt::FernBellStyle::Audible => {
None => {
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<()> {
match read_shopts(|o| o.core.bell_style) {
FernBellStyle::Audible => {
if read_shopts(|o| o.core.bell_enabled) {
self.flush_write("\x07")?;
}
FernBellStyle::Visible => {
log::warn!("Visual bell is not supported in fern shell yet");
}
FernBellStyle::Disable => { /* Do nothing */ }
}
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)]
pub enum FernEditMode {
#[default]
@@ -159,7 +149,7 @@ pub struct ShOptCore {
pub max_hist: usize,
pub interactive_comments: bool,
pub auto_hist: bool,
pub bell_style: FernBellStyle,
pub bell_enabled: bool,
pub max_recurse_depth: usize,
}
@@ -221,7 +211,7 @@ impl ShOptCore {
self.auto_hist = val;
}
"bell_style" => {
let Ok(val) = val.parse::<FernBellStyle>() else {
let Ok(val) = val.parse::<bool>() else {
return Err(
ShErr::simple(
ShErrKind::SyntaxErr,
@@ -233,7 +223,7 @@ impl ShOptCore {
),
);
};
self.bell_style = val;
self.bell_enabled = val;
}
"max_recurse_depth" => {
let Ok(val) = val.parse::<usize>() else {
@@ -311,8 +301,8 @@ impl ShOptCore {
Ok(Some(output))
}
"bell_style" => {
let mut output = String::from("What type of bell style to use for the bell character\n");
output.push_str(&format!("{}", self.bell_style));
let mut output = String::from("Whether or not to allow fern to trigger the terminal bell");
output.push_str(&format!("{}", self.bell_enabled));
Ok(Some(output))
}
"max_recurse_depth" => {
@@ -355,7 +345,7 @@ impl Display for ShOptCore {
self.interactive_comments
));
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));
let final_output = output.join("\n");
@@ -373,7 +363,7 @@ impl Default for ShOptCore {
max_hist: 1000,
interactive_comments: true,
auto_hist: true,
bell_style: FernBellStyle::Audible,
bell_enabled: true,
max_recurse_depth: 1000,
}
}