mirror of
https://github.com/talwat/lowfi
synced 2024-12-27 11:41:54 +00:00
fix: use CString
instead of new rust syntax to fix older versions of rust throwing compilation errors
This commit is contained in:
parent
543aeee78c
commit
10a3263c82
@ -2,7 +2,7 @@
|
|||||||
//! This also has the code for the underlying
|
//! This also has the code for the underlying
|
||||||
//! audio server which adds new tracks.
|
//! audio server which adds new tracks.
|
||||||
|
|
||||||
use std::{collections::VecDeque, sync::Arc, time::Duration};
|
use std::{collections::VecDeque, ffi::CString, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use arc_swap::ArcSwapOption;
|
use arc_swap::ArcSwapOption;
|
||||||
use downloader::Downloader;
|
use downloader::Downloader;
|
||||||
@ -118,22 +118,29 @@ unsafe impl Sync for Player {}
|
|||||||
impl Player {
|
impl Player {
|
||||||
/// This gets the output stream while also shutting up alsa with [libc].
|
/// This gets the output stream while also shutting up alsa with [libc].
|
||||||
fn silent_get_output_stream() -> eyre::Result<(OutputStream, OutputStreamHandle)> {
|
fn silent_get_output_stream() -> eyre::Result<(OutputStream, OutputStreamHandle)> {
|
||||||
|
// Get the file descriptor to stderr from libc.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static stderr: *mut libc::FILE;
|
static stderr: *mut libc::FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mode = c"w".as_ptr();
|
|
||||||
|
|
||||||
// This is a bit of an ugly hack that basically just uses `libc` to redirect alsa's
|
// This is a bit of an ugly hack that basically just uses `libc` to redirect alsa's
|
||||||
// output to `/dev/null` so that it wont be shoved down our throats.
|
// output to `/dev/null` so that it wont be shoved down our throats.
|
||||||
|
|
||||||
// SAFETY: Simple enough to be impossible to fail. Hopefully.
|
// The mode which to redirect terminal output with.
|
||||||
unsafe { freopen(c"/dev/null".as_ptr(), mode, stderr) };
|
let mode = CString::new("w")?.as_ptr();
|
||||||
|
|
||||||
|
// First redirect to /dev/null, which basically silences alsa.
|
||||||
|
let null = CString::new("/dev/null")?.as_ptr();
|
||||||
|
// SAFETY: Simple enough to be impossible to fail. Hopefully.
|
||||||
|
unsafe { freopen(null, mode, stderr) };
|
||||||
|
|
||||||
|
// Make the OutputStream while stderr is still redirected to /dev/null.
|
||||||
let (stream, handle) = OutputStream::try_default()?;
|
let (stream, handle) = OutputStream::try_default()?;
|
||||||
|
|
||||||
|
// Redirect back to the current terminal, so that other output isn't silenced.
|
||||||
|
let tty = CString::new("/dev/tty")?.as_ptr();
|
||||||
// SAFETY: See the first call to `freopen`.
|
// SAFETY: See the first call to `freopen`.
|
||||||
unsafe { freopen(c"/dev/tty".as_ptr(), mode, stderr) };
|
unsafe { freopen(tty, mode, stderr) };
|
||||||
|
|
||||||
Ok((stream, handle))
|
Ok((stream, handle))
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,7 @@ impl PlayerInterface for Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn pause(&self) -> fdo::Result<()> {
|
async fn pause(&self) -> fdo::Result<()> {
|
||||||
self.sender
|
self.sender.send(Messages::Pause).await.map_err(|_| ERROR)
|
||||||
.send(Messages::Pause)
|
|
||||||
.await
|
|
||||||
.map_err(|_| ERROR)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn play_pause(&self) -> fdo::Result<()> {
|
async fn play_pause(&self) -> fdo::Result<()> {
|
||||||
@ -95,10 +92,7 @@ impl PlayerInterface for Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn play(&self) -> fdo::Result<()> {
|
async fn play(&self) -> fdo::Result<()> {
|
||||||
self.sender
|
self.sender.send(Messages::Play).await.map_err(|_| ERROR)
|
||||||
.send(Messages::Play)
|
|
||||||
.await
|
|
||||||
.map_err(|_| ERROR)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn seek(&self, _offset: Time) -> fdo::Result<()> {
|
async fn seek(&self, _offset: Time) -> fdo::Result<()> {
|
||||||
|
@ -131,7 +131,7 @@ async fn interface(player: Arc<Player>, minimalist: bool) -> eyre::Result<()> {
|
|||||||
VOLUME_TIMER.store(0, Ordering::Relaxed);
|
VOLUME_TIMER.store(0, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
let controls = components::controls(&player, WIDTH);
|
let controls = components::controls(WIDTH);
|
||||||
|
|
||||||
let menu = if minimalist {
|
let menu = if minimalist {
|
||||||
vec![action, middle]
|
vec![action, middle]
|
||||||
|
@ -103,9 +103,9 @@ pub fn action(player: &Player, width: usize) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the bottom controls bar, and also spaces it properly.
|
/// Creates the bottom controls bar, and also spaces it properly.
|
||||||
pub fn controls(player: &Player, width: usize) -> String {
|
pub fn controls(width: usize) -> String {
|
||||||
let play_pause = if player.sink.is_paused() { ["[p]", "lay "] } else { ["[p]", "ause"] };
|
let controls = [["[s]", "kip"], ["[p]", "ause"], ["[q]", "uit"]];
|
||||||
let controls = [["[s]", "kip"], play_pause, ["[q]", "uit"]];
|
|
||||||
let len: usize = controls.concat().iter().map(|x| x.len()).sum();
|
let len: usize = controls.concat().iter().map(|x| x.len()).sum();
|
||||||
let controls = controls.map(|x| format!("{}{}", x[0].bold(), x[1]));
|
let controls = controls.map(|x| format!("{}{}", x[0].bold(), x[1]));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user