Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ license = "AGPL-3.0"
categories = ["command-line-utilities", "development-tools"]
readme = "README.md"
rust-version = "1.76"

[features]
default = []
clipboard = ["arboard"]
sound = ["rodio"]
default-sounds = ["sound"]

[dependencies]
anyhow = "1.0"
Expand All @@ -32,10 +33,12 @@ glob = "0.3"
iq = { version = "0.2", features = ["template"] }
lazy-regex = "3.4.1"
notify = "7.0"
rodio = { version = "0.20", optional = true, default-features = false, features = ["mp3"] }
once_cell = "1.20.3"
rodio = { version = "0.20", optional = true, default-features = false, features = ["playback", "mp3"] }
rustc-hash = "2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shellexpand = "3.1.0"
termimad = "0.31.1"
toml = "0.8"
unicode-width = "0.2"
Expand All @@ -48,6 +51,7 @@ strip = "symbols"
codegen-units = 1

[patch.crates-io]
rodio = { git = "https://github.com/RustAudio/rodio", rev = "0d352f5f2678226e843aa9c0ddea080f1e6d80ae" }
# clap-help = { path = "../clap-help" }
# termimad = { path = "../termimad" }
# crokey = { path = "../crokey" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Run this command too if you want to update bacon. Configuration has always been

Some features are disabled by default. You may enable them with

cargo install --features "clipboard sound"
cargo install --features "clipboard sound default-sounds"

## check the current project

Expand Down Expand Up @@ -116,6 +116,7 @@ Some bacon features can be disabled or enabled at compilation:

* `"clipboard"` - disabled by default : necessary for the `copy-unstyled-output` internal
* `"sound"` - disabled by default : necessary for the `play-sound` internal
* `"default-sounds"` - disabled by default: embed some default sounds for the `play-sound` internal

## Licences

Expand Down
8 changes: 7 additions & 1 deletion defaults/default-prefs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ line_format = "{kind} {path}:{line}:{column} {message}"
enabled = false # set true to allow sound
base_volume = "100%" # global volume multiplier

# Specify your own sound files, e.g.
# bepop = "~/audio/bepop.mp3"
#
# Then use its name as usual in a job, e.g.
# on_success = "play-sound(name=bepop,volume=42)"
[sound.collection]

# Uncomment and change the key-bindings you want to define
# (some of those ones are the defaults and are just here for illustration)
[keybindings]
Expand Down Expand Up @@ -110,4 +117,3 @@ base_volume = "100%" # global volume multiplier
# r = "job:run"
# ctrl-e = "export:analysis"
# ctrl-c = "copy-unstyled-output"

18 changes: 16 additions & 2 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ impl fmt::Display for Internal {
Self::Validate => write!(f, "validate"),
Self::NextMatch => write!(f, "next-match"),
Self::PreviousMatch => write!(f, "previous-match"),
Self::PlaySound(PlaySoundCommand { name, volume }) => {
Self::PlaySound(PlaySoundCommand { name, path, volume }) => {
write!(f, "play-sound(")?;
if let Some(name) = name {
write!(f, "name={},", name)?;
}
if let Some(path) = path {
write!(f, "path={},", path)?;
}
write!(f, "volume={})", volume)
}
}
Expand Down Expand Up @@ -159,12 +162,16 @@ impl std::str::FromStr for Internal {
let iter = regex_captures_iter!(r"([^=,]+)=([^=,]+)", props);
let mut volume = Volume::default();
let mut name = None;
let mut path = None;
for (_, [prop_name, prop_value]) in iter.map(|c| c.extract()) {
let prop_value = prop_value.trim();
match prop_name.trim() {
"name" => {
name = Some(prop_value.to_string());
}
"path" => {
path = Some(prop_value.to_string());
}
"volume" => {
volume = prop_value.parse()?;
}
Expand All @@ -173,7 +180,10 @@ impl std::str::FromStr for Internal {
}
}
}
return Ok(Self::PlaySound(PlaySoundCommand { name, volume }));
if name.is_some() && path.is_some() {
return Err("invalid play-sound parameter: only one of name or path can be specified".to_string());
}
return Ok(Self::PlaySound(PlaySoundCommand { name, path, volume }));
}
Err("invalid internal".to_string())
}
Expand Down Expand Up @@ -231,14 +241,17 @@ fn test_internal_string_round_trip() {
Internal::PlaySound(PlaySoundCommand::default()),
Internal::PlaySound(PlaySoundCommand {
name: None,
path: None,
volume: Volume::new(50),
}),
Internal::PlaySound(PlaySoundCommand {
name: Some("beep-beep".to_string()),
path: None,
volume: Volume::new(100),
}),
Internal::PlaySound(PlaySoundCommand {
name: None,
path: None,
volume: Volume::new(0),
}),
];
Expand All @@ -260,6 +273,7 @@ fn test_play_sound_parsing_with_space() {
];
let psc = PlaySoundCommand {
name: Some("car-horn".to_string()),
path: None,
volume: Volume::new(5),
};
for string in &strings {
Expand Down
1 change: 1 addition & 0 deletions src/jobs/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ fn test_job_apply() {
sound: SoundConfig {
enabled: Some(true),
base_volume: Some(Volume::from_str("50").unwrap()),
collection: None,
},
};
base_job.apply(&job_to_apply);
Expand Down
1 change: 1 addition & 0 deletions src/sound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ pub use {
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct PlaySoundCommand {
pub name: Option<String>,
pub path: Option<String>,
pub volume: Volume,
}
Loading