mirror of
https://github.com/talwat/lowfi
synced 2024-12-26 03:01:55 +00:00
feat: add --alternate flag
This commit is contained in:
parent
5a498b1c98
commit
69ce498a05
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -58,7 +58,7 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: sudo apt install libasound2-dev
|
||||
run: sudo apt install libasound2-dev libssl-dev
|
||||
|
||||
- name: Build binary
|
||||
uses: houseabsolute/actions-rust-cross@v0
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -982,7 +982,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
|
||||
[[package]]
|
||||
name = "lowfi"
|
||||
version = "1.2.1"
|
||||
version = "1.2.2"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"arc-swap",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "lowfi"
|
||||
version = "1.2.1"
|
||||
version = "1.2.2"
|
||||
edition = "2021"
|
||||
description = "An extremely simple lofi player."
|
||||
license = "MIT"
|
||||
|
@ -9,6 +9,10 @@ mod tracks;
|
||||
#[derive(Parser)]
|
||||
#[command(about)]
|
||||
struct Args {
|
||||
/// Whether to use an alternate terminal screen.
|
||||
#[clap(long, short)]
|
||||
alternate: bool,
|
||||
|
||||
/// The command that was ran.
|
||||
/// This is [None] if no command was specified.
|
||||
#[command(subcommand)]
|
||||
@ -42,6 +46,6 @@ async fn main() -> eyre::Result<()> {
|
||||
} => scrape::scrape(extension, include_full).await,
|
||||
}
|
||||
} else {
|
||||
play::play().await
|
||||
play::play(cli.alternate).await
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::{io::stderr, sync::Arc};
|
||||
|
||||
use crossterm::cursor::SavePosition;
|
||||
use crossterm::{cursor::SavePosition, terminal};
|
||||
use tokio::{
|
||||
sync::mpsc::{self},
|
||||
task::{self},
|
||||
@ -13,20 +13,23 @@ use crate::player::{ui, Messages};
|
||||
|
||||
/// Initializes the audio server, and then safely stops
|
||||
/// it when the frontend quits.
|
||||
pub async fn play() -> 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
|
||||
// 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: Instead of just ignoring & clearing them after.
|
||||
crossterm::execute!(stderr(), 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 player = Arc::new(Player::new().await?);
|
||||
let audio = task::spawn(Player::play(Arc::clone(&player), tx.clone(), rx));
|
||||
tx.send(Messages::Init).await?;
|
||||
|
||||
ui::start(Arc::clone(&player), tx.clone()).await?;
|
||||
ui::start(Arc::clone(&player), tx.clone(), alternate).await?;
|
||||
|
||||
audio.abort();
|
||||
player.sink.stop();
|
||||
|
@ -6,10 +6,10 @@ use crate::tracks::TrackInfo;
|
||||
|
||||
use super::Player;
|
||||
use crossterm::{
|
||||
cursor::{Hide, MoveToColumn, MoveUp, RestorePosition, Show},
|
||||
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, RestorePosition, Show},
|
||||
event::{self, KeyCode, KeyModifiers},
|
||||
style::{Print, Stylize},
|
||||
terminal::{self, Clear, ClearType},
|
||||
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use tokio::{
|
||||
sync::mpsc::Sender,
|
||||
@ -136,15 +136,24 @@ async fn interface(queue: Arc<Player>) -> eyre::Result<()> {
|
||||
}
|
||||
|
||||
/// Initializes the UI, this will also start taking input from the user.
|
||||
pub async fn start(queue: Arc<Player>, sender: Sender<Messages>) -> eyre::Result<()> {
|
||||
///
|
||||
/// `alternate` controls whether to use [EnterAlternateScreen] in order to hide
|
||||
/// previous terminal history.
|
||||
pub async fn start(
|
||||
queue: Arc<Player>,
|
||||
sender: Sender<Messages>,
|
||||
alternate: bool,
|
||||
) -> eyre::Result<()> {
|
||||
crossterm::execute!(
|
||||
stderr(),
|
||||
RestorePosition,
|
||||
Clear(ClearType::FromCursorDown),
|
||||
Hide
|
||||
)?;
|
||||
terminal::enable_raw_mode()?;
|
||||
//crossterm::execute!(stderr(), EnterAlternateScreen, MoveTo(0, 0))?;
|
||||
|
||||
if alternate {
|
||||
crossterm::execute!(stderr(), EnterAlternateScreen, MoveTo(0, 0))?;
|
||||
}
|
||||
|
||||
task::spawn(interface(Arc::clone(&queue)));
|
||||
|
||||
@ -179,7 +188,10 @@ pub async fn start(queue: Arc<Player>, sender: Sender<Messages>) -> eyre::Result
|
||||
}
|
||||
}
|
||||
|
||||
//crossterm::execute!(stderr(), LeaveAlternateScreen)?;
|
||||
if alternate {
|
||||
crossterm::execute!(stderr(), LeaveAlternateScreen)?;
|
||||
}
|
||||
|
||||
crossterm::execute!(stderr(), Clear(ClearType::FromCursorDown), Show)?;
|
||||
terminal::disable_raw_mode()?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user