mirror of
https://github.com/talwat/lowfi
synced 2025-01-28 03:11:27 +00:00
feat: improve slightly media key support
This commit is contained in:
parent
706ba97428
commit
0ef844a3f2
@ -13,7 +13,7 @@ use crate::Args;
|
|||||||
pub async fn play(args: Args) -> eyre::Result<()> {
|
pub async fn play(args: Args) -> eyre::Result<()> {
|
||||||
let (tx, rx) = mpsc::channel(8);
|
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));
|
let audio = task::spawn(Player::play(Arc::clone(&player), tx.clone(), rx));
|
||||||
tx.send(Messages::Init).await?;
|
tx.send(Messages::Init).await?;
|
||||||
|
|
||||||
|
@ -106,8 +106,12 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes the entire player, including audio devices & sink.
|
/// 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()?
|
Self::silent_get_output_stream()?
|
||||||
} else {
|
} else {
|
||||||
OutputStream::try_default()?
|
OutputStream::try_default()?
|
||||||
|
@ -14,7 +14,10 @@ use crate::Args;
|
|||||||
use super::Player;
|
use super::Player;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, Show},
|
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, Show},
|
||||||
event::{self, KeyCode, KeyModifiers, KeyboardEnhancementFlags, PushKeyboardEnhancementFlags},
|
event::{
|
||||||
|
self, KeyCode, KeyModifiers, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags,
|
||||||
|
PushKeyboardEnhancementFlags,
|
||||||
|
},
|
||||||
style::{Print, Stylize},
|
style::{Print, Stylize},
|
||||||
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
|
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()?;
|
terminal::enable_raw_mode()?;
|
||||||
|
let enhancement = terminal::supports_keyboard_enhancement()?;
|
||||||
|
|
||||||
if terminal::supports_keyboard_enhancement()? {
|
if enhancement {
|
||||||
crossterm::execute!(
|
crossterm::execute!(
|
||||||
stdout(),
|
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)?;
|
crossterm::execute!(stdout(), Clear(ClearType::FromCursorDown), Show)?;
|
||||||
|
|
||||||
|
if enhancement {
|
||||||
|
crossterm::execute!(stdout(), PopKeyboardEnhancementFlags)?;
|
||||||
|
}
|
||||||
|
|
||||||
terminal::disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user