New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for running commands on BEL #2298
Conversation
Opening this before I document the changes and add them to config file in case there are any comments ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One somewhat real comment, and then a couple of naming suggestions.
src/config/mod.rs
Outdated
#[inline] | ||
pub fn bell_command(&self) -> Option<CommandWrapper> { | ||
self.bell_command.clone() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don's have getters for the other launcher (it's simply a pub
field). I don't love the idea of having a lone pub
field on the struct, but at the same time, I really would like to avoid clone
. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using .as_ref()
would probably work here to return an Option<&CommandWrapper>
. No clones necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure how to do this? surely you don't want me to litter all the structures with lifetime annotations just because of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertgzr I know this is outdated, but FWIW this would work:
struct A(Option<u32>);
impl A {
fn get(&self) -> Option<&u32> {
self.0.as_ref()
}
}
fn main() {
println!("{:?}", A(Some(10)).get());
println!("{:?}", A(None).get());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Even though it might only be of limited use, even to people desiring an audio bell, I think a bell command is a powerful solution which enables the user to take matters into their own hands without having to outright deny the feature.
This is probably the most likely approach to this issue so I'm generally not against moving forward with it, however I do think there should be a bit of refactoring to get this implemented properly.
Dropping the bell_command
in the visual_bell
section is a bit of a contradiction, since it's completely unrelated to any visual bell effect. So I think than renaming the visual bell to just bell
would make sense.
Here's a draft of how a new version might look like:
# Bell
#
# The bell is triggered every time the BEL escape sequence is received.
bell:
# Visual Bell Animation
#
# Animation effect for flashing the screen when the visual bell is rung.
#
# Values for `animation`:
# - Ease
# - EaseOut
# - EaseOutSine
# - EaseOutQuad
# - EaseOutCubic
# - EaseOutQuart
# - EaseOutQuint
# - EaseOutExpo
# - EaseOutCirc
# - Linear
animation: Testing
# Duration of the visual bell flash. A `duration` of `0` will disable the
# visual bell animation.
duration: 0
# Visual bell animation color.
color: '0xffffff'
# Visual Bell Command
#
# This program is executed whenever the visual bell is rung. Setting
# `command` to `None` will disable it.
#
# Example:
# command:
# program: /bin/notify-send
# args: ["Hello, World!"]
command: None
Of course we can't just remove visual_bell
, so we'd have to alias that to bell
with a deprecation warning similar to what's already done in other parts of the config file (see deprecation comments in src/config/mod.rs).
Do you still intend to work on this? |
Adds a new configuration option under `visual_bell` called `bell_command` that reuses the command formatting of the keybindings. This allows for things like playing a notification sound. See alacritty#1528 (comment) Closes alacritty#1528
re-ping @chrisduerr @nixpulvis in case this slipped through your queues ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ping @chrisduerr @nixpulvis in case this slipped through your queues ;)
It did indeed. Apologies for the late reply.
This is missing the documentation in the default alacritty.yml
to be updated. The default config file should always work properly and represent the code structure.
This PR also requires a rebase to allow it to build again.
|
||
// TODO: DEPRECATED | ||
#[serde(default, deserialize_with = "failure_default")] | ||
visual_bell: BellConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated fields should be moved to the end of the config.
There also is no deprecation warning for this field which informs people about this change. This should be added.
Additionally the old config fields must still work properly during the deprecation period. We can't just remove fields.
start_time: None, | ||
} | ||
} | ||
|
||
/// Ring the visual bell, and return its intensity. | ||
pub fn ring(&mut self) -> f64 { | ||
self.run_command(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A newline after self.run_command()
would be nice to make it clear it's logically separated from the rest of the bell logic.
Bell { | ||
animation: bell_config.animation, | ||
duration: bell_config.duration(), | ||
command: bell_config.command.clone(), | ||
start_time: None, | ||
} | ||
} | ||
|
||
/// Ring the visual bell, and return its intensity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed from visual bell to just bell, since it also executes the bell command.
} | ||
} | ||
|
||
pub fn run_command(&self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function name does not correctly represent what is done inside the function. A generic command execution should not print bell
errors.
I'd recommend inlining this into the run
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't mind a Bell::run_command
function like this, though I don't care much either way since Bell::ring
is so short. I don't see why logging errors can't be part of the run_command
logic.
If this were to be left as it's own function it could be hidden as an internal detail by removing the pub
declaration.
let visual_bell_config = &config.visual_bell; | ||
self.animation = visual_bell_config.animation; | ||
self.duration = visual_bell_config.duration(); | ||
let bell_config = &config.bell; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining this variable here has no benefits, since config.bell
and bell_config
are exactly the same length.
This comment has been minimized.
This comment has been minimized.
While I like the idea of running commands on BEL, I don't really like the proposed integration into |
Due to this improved design for handling things like this and the amount of time this PR has been stale without any interest in it, I'm going to close this PR. If there is interest in picking this back up, I'd recommend starting out with the new design suggested in #3182. If there are any uncertainties, please leave them in that issue. Thanks for your work. |
Adds a new configuration option under
visual_bell
calledbell_command
that reuses the command formatting of the keybindings.This allows for things like playing a notification sound.
See #1528 (comment)
Closes #1528