mirror of
https://github.com/talwat/lowfi
synced 2025-05-17 17:52:19 +00:00
fix: switch to using stdout
This commit is contained in:
parent
60a00f189e
commit
5d2e6c6d23
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -982,7 +982,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.2.4"
|
version = "1.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"Inflector",
|
"Inflector",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.3.0"
|
version = "1.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "An extremely simple lofi player."
|
description = "An extremely simple lofi player."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
18
src/play.rs
18
src/play.rs
@ -1,12 +1,10 @@
|
|||||||
//! Responsible for the basic initialization & shutdown of the audio server & frontend.
|
//! Responsible for the basic initialization & shutdown of the audio server & frontend.
|
||||||
|
|
||||||
use std::{io::stderr, sync::Arc};
|
use std::io::stdout;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crossterm::{cursor::SavePosition, terminal};
|
use crossterm::cursor::SavePosition;
|
||||||
use tokio::{
|
use tokio::{sync::mpsc, task};
|
||||||
sync::mpsc::{self},
|
|
||||||
task::{self},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
use crate::player::{ui, Messages};
|
use crate::player::{ui, Messages};
|
||||||
@ -16,12 +14,10 @@ use crate::player::{ui, Messages};
|
|||||||
pub async fn play(alternate: bool) -> eyre::Result<()> {
|
pub async fn play(alternate: bool) -> eyre::Result<()> {
|
||||||
// Save the position. This is important since later on we can revert to this position
|
// Save the position. This is important since later on we can revert to this position
|
||||||
// and clear any potential error messages that may have showed up.
|
// and clear any potential error messages that may have showed up.
|
||||||
// TODO: Figure how to set some sort of flag to hide error messages within rodio,
|
// TODO: Figure how to set some sort of flag to hide error messages within alsa/rodio,
|
||||||
// TODO: Instead of just ignoring & clearing them after.
|
// TODO: Instead of just ignoring & clearing them after.
|
||||||
crossterm::execute!(stderr(), SavePosition)?;
|
// TODO: Fix this, as it doesn't work with some terminals when the cursor is at the bottom of the terminal.
|
||||||
|
crossterm::execute!(stdout(), SavePosition)?;
|
||||||
// Enable raw mode early in theory to prevent uncontrolled text in the terminal from the user.
|
|
||||||
terminal::enable_raw_mode()?;
|
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel(8);
|
let (tx, rx) = mpsc::channel(8);
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ impl Player {
|
|||||||
|
|
||||||
/// This is the main "audio server".
|
/// This is the main "audio server".
|
||||||
///
|
///
|
||||||
/// `rx` & `ts` are used to communicate with it, for example when to
|
/// `rx` & `tx` are used to communicate with it, for example when to
|
||||||
/// skip tracks or pause.
|
/// skip tracks or pause.
|
||||||
pub async fn play(
|
pub async fn play(
|
||||||
player: Arc<Self>,
|
player: Arc<Self>,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! The module which manages all user interface, including inputs.
|
//! The module which manages all user interface, including inputs.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::stderr,
|
io::stdout,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
@ -172,9 +172,9 @@ async fn interface(player: Arc<Player>, volume_timer: Arc<AtomicUsize>) -> eyre:
|
|||||||
let menu = [main, middle, controls.join(" ")]
|
let menu = [main, middle, controls.join(" ")]
|
||||||
.map(|x| format!("│ {} │\r\n", x.reset()).to_string());
|
.map(|x| format!("│ {} │\r\n", x.reset()).to_string());
|
||||||
|
|
||||||
crossterm::execute!(stderr(), Clear(ClearType::FromCursorDown))?;
|
|
||||||
crossterm::execute!(
|
crossterm::execute!(
|
||||||
stderr(),
|
stdout(),
|
||||||
|
Clear(ClearType::FromCursorDown),
|
||||||
MoveToColumn(0),
|
MoveToColumn(0),
|
||||||
Print(format!("┌{}┐\r\n", "─".repeat(WIDTH + 2))),
|
Print(format!("┌{}┐\r\n", "─".repeat(WIDTH + 2))),
|
||||||
Print(menu.join("")),
|
Print(menu.join("")),
|
||||||
@ -197,14 +197,17 @@ pub async fn start(
|
|||||||
alternate: bool,
|
alternate: bool,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
crossterm::execute!(
|
crossterm::execute!(
|
||||||
stderr(),
|
stdout(),
|
||||||
RestorePosition,
|
RestorePosition,
|
||||||
|
Clear(ClearType::CurrentLine),
|
||||||
Clear(ClearType::FromCursorDown),
|
Clear(ClearType::FromCursorDown),
|
||||||
Hide
|
Hide
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
terminal::enable_raw_mode()?;
|
||||||
|
|
||||||
if alternate {
|
if alternate {
|
||||||
crossterm::execute!(stderr(), EnterAlternateScreen, MoveTo(0, 0))?;
|
crossterm::execute!(stdout(), EnterAlternateScreen, MoveTo(0, 0))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let volume_timer = Arc::new(AtomicUsize::new(0));
|
let volume_timer = Arc::new(AtomicUsize::new(0));
|
||||||
@ -251,10 +254,10 @@ pub async fn start(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if alternate {
|
if alternate {
|
||||||
crossterm::execute!(stderr(), LeaveAlternateScreen)?;
|
crossterm::execute!(stdout(), LeaveAlternateScreen)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
crossterm::execute!(stderr(), Clear(ClearType::FromCursorDown), Show)?;
|
crossterm::execute!(stdout(), Clear(ClearType::FromCursorDown), Show)?;
|
||||||
terminal::disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user