mirror of
https://github.com/talwat/lowfi
synced 2025-01-28 03:11:27 +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
|
- name: Install dependencies
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
run: sudo apt install libasound2-dev
|
run: sudo apt install libasound2-dev libssl-dev
|
||||||
|
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
uses: houseabsolute/actions-rust-cross@v0
|
uses: houseabsolute/actions-rust-cross@v0
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -982,7 +982,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.2.1"
|
version = "1.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"Inflector",
|
"Inflector",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.2.1"
|
version = "1.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "An extremely simple lofi player."
|
description = "An extremely simple lofi player."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -9,6 +9,10 @@ mod tracks;
|
|||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(about)]
|
#[command(about)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Whether to use an alternate terminal screen.
|
||||||
|
#[clap(long, short)]
|
||||||
|
alternate: bool,
|
||||||
|
|
||||||
/// The command that was ran.
|
/// The command that was ran.
|
||||||
/// This is [None] if no command was specified.
|
/// This is [None] if no command was specified.
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
@ -42,6 +46,6 @@ async fn main() -> eyre::Result<()> {
|
|||||||
} => scrape::scrape(extension, include_full).await,
|
} => scrape::scrape(extension, include_full).await,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
play::play().await
|
play::play(cli.alternate).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::{io::stderr, sync::Arc};
|
use std::{io::stderr, sync::Arc};
|
||||||
|
|
||||||
use crossterm::cursor::SavePosition;
|
use crossterm::{cursor::SavePosition, terminal};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::mpsc::{self},
|
sync::mpsc::{self},
|
||||||
task::{self},
|
task::{self},
|
||||||
@ -13,20 +13,23 @@ use crate::player::{ui, Messages};
|
|||||||
|
|
||||||
/// Initializes the audio server, and then safely stops
|
/// Initializes the audio server, and then safely stops
|
||||||
/// it when the frontend quits.
|
/// 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
|
// 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 rodio,
|
||||||
// TODO: Instead of just ignoring & clearing them after.
|
// TODO: Instead of just ignoring & clearing them after.
|
||||||
crossterm::execute!(stderr(), SavePosition)?;
|
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 (tx, rx) = mpsc::channel(8);
|
||||||
|
|
||||||
let player = Arc::new(Player::new().await?);
|
let player = Arc::new(Player::new().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?;
|
||||||
|
|
||||||
ui::start(Arc::clone(&player), tx.clone()).await?;
|
ui::start(Arc::clone(&player), tx.clone(), alternate).await?;
|
||||||
|
|
||||||
audio.abort();
|
audio.abort();
|
||||||
player.sink.stop();
|
player.sink.stop();
|
||||||
|
@ -6,10 +6,10 @@ use crate::tracks::TrackInfo;
|
|||||||
|
|
||||||
use super::Player;
|
use super::Player;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor::{Hide, MoveToColumn, MoveUp, RestorePosition, Show},
|
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, RestorePosition, Show},
|
||||||
event::{self, KeyCode, KeyModifiers},
|
event::{self, KeyCode, KeyModifiers},
|
||||||
style::{Print, Stylize},
|
style::{Print, Stylize},
|
||||||
terminal::{self, Clear, ClearType},
|
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::mpsc::Sender,
|
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.
|
/// 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!(
|
crossterm::execute!(
|
||||||
stderr(),
|
stderr(),
|
||||||
RestorePosition,
|
RestorePosition,
|
||||||
Clear(ClearType::FromCursorDown),
|
Clear(ClearType::FromCursorDown),
|
||||||
Hide
|
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)));
|
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)?;
|
crossterm::execute!(stderr(), Clear(ClearType::FromCursorDown), Show)?;
|
||||||
terminal::disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user