feat: improve slightly media key support

This commit is contained in:
talwat 2024-10-04 00:09:39 +02:00
parent 706ba97428
commit 0ef844a3f2
3 changed files with 19 additions and 6 deletions

View File

@ -13,7 +13,7 @@ use crate::Args;
pub async fn play(args: Args) -> eyre::Result<()> {
let (tx, rx) = mpsc::channel(8);
let player = Arc::new(Player::new().await?);
let player = Arc::new(Player::new(args.alternate).await?);
let audio = task::spawn(Player::play(Arc::clone(&player), tx.clone(), rx));
tx.send(Messages::Init).await?;

View File

@ -106,8 +106,12 @@ impl Player {
}
/// Initializes the entire player, including audio devices & sink.
pub async fn new() -> eyre::Result<Self> {
let (_stream, handle) = if cfg!(target_os = "linux") {
///
/// `silent` can control whether alsa's output should be redirected,
/// but this option is only applicable on Linux, as on MacOS & Windows
/// it will never be silent.
pub async fn new(silent: bool) -> eyre::Result<Self> {
let (_stream, handle) = if silent && cfg!(target_os = "linux") {
Self::silent_get_output_stream()?
} else {
OutputStream::try_default()?

View File

@ -14,7 +14,10 @@ use crate::Args;
use super::Player;
use crossterm::{
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, Show},
event::{self, KeyCode, KeyModifiers, KeyboardEnhancementFlags, PushKeyboardEnhancementFlags},
event::{
self, KeyCode, KeyModifiers, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags,
PushKeyboardEnhancementFlags,
},
style::{Print, Stylize},
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
};
@ -105,11 +108,12 @@ pub async fn start(queue: Arc<Player>, sender: Sender<Messages>, args: Args) ->
}
terminal::enable_raw_mode()?;
let enhancement = terminal::supports_keyboard_enhancement()?;
if terminal::supports_keyboard_enhancement()? {
if enhancement {
crossterm::execute!(
stdout(),
PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES,)
PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES)
)?;
}
@ -173,6 +177,11 @@ pub async fn start(queue: Arc<Player>, sender: Sender<Messages>, args: Args) ->
}
crossterm::execute!(stdout(), Clear(ClearType::FromCursorDown), Show)?;
if enhancement {
crossterm::execute!(stdout(), PopKeyboardEnhancementFlags)?;
}
terminal::disable_raw_mode()?;
Ok(())