mirror of
				https://github.com/talwat/lowfi
				synced 2025-10-30 18:58:45 +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]] | ||||
| name = "lowfi" | ||||
| version = "1.2.4" | ||||
| version = "1.3.1" | ||||
| dependencies = [ | ||||
|  "Inflector", | ||||
|  "arc-swap", | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| [package] | ||||
| name = "lowfi" | ||||
| version = "1.3.0" | ||||
| version = "1.3.1" | ||||
| edition = "2021" | ||||
| description = "An extremely simple lofi player." | ||||
| 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.
 | ||||
| 
 | ||||
| use std::{io::stderr, sync::Arc}; | ||||
| use std::io::stdout; | ||||
| use std::sync::Arc; | ||||
| 
 | ||||
| use crossterm::{cursor::SavePosition, terminal}; | ||||
| use tokio::{ | ||||
|     sync::mpsc::{self}, | ||||
|     task::{self}, | ||||
| }; | ||||
| use crossterm::cursor::SavePosition; | ||||
| use tokio::{sync::mpsc, task}; | ||||
| 
 | ||||
| use crate::player::Player; | ||||
| use crate::player::{ui, Messages}; | ||||
| @ -16,12 +14,10 @@ use crate::player::{ui, Messages}; | ||||
| 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: Figure how to set some sort of flag to hide error messages within alsa/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()?; | ||||
|     // 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)?; | ||||
| 
 | ||||
|     let (tx, rx) = mpsc::channel(8); | ||||
| 
 | ||||
|  | ||||
| @ -131,7 +131,7 @@ impl Player { | ||||
| 
 | ||||
|     /// 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.
 | ||||
|     pub async fn play( | ||||
|         player: Arc<Self>, | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| //! The module which manages all user interface, including inputs.
 | ||||
| 
 | ||||
| use std::{ | ||||
|     io::stderr, | ||||
|     io::stdout, | ||||
|     sync::{ | ||||
|         atomic::{AtomicUsize, Ordering}, | ||||
|         Arc, | ||||
| @ -172,9 +172,9 @@ async fn interface(player: Arc<Player>, volume_timer: Arc<AtomicUsize>) -> eyre: | ||||
|         let menu = [main, middle, controls.join("    ")] | ||||
|             .map(|x| format!("│ {} │\r\n", x.reset()).to_string()); | ||||
| 
 | ||||
|         crossterm::execute!(stderr(), Clear(ClearType::FromCursorDown))?; | ||||
|         crossterm::execute!( | ||||
|             stderr(), | ||||
|             stdout(), | ||||
|             Clear(ClearType::FromCursorDown), | ||||
|             MoveToColumn(0), | ||||
|             Print(format!("┌{}┐\r\n", "─".repeat(WIDTH + 2))), | ||||
|             Print(menu.join("")), | ||||
| @ -197,14 +197,17 @@ pub async fn start( | ||||
|     alternate: bool, | ||||
| ) -> eyre::Result<()> { | ||||
|     crossterm::execute!( | ||||
|         stderr(), | ||||
|         stdout(), | ||||
|         RestorePosition, | ||||
|         Clear(ClearType::CurrentLine), | ||||
|         Clear(ClearType::FromCursorDown), | ||||
|         Hide | ||||
|     )?; | ||||
| 
 | ||||
|     terminal::enable_raw_mode()?; | ||||
| 
 | ||||
|     if alternate { | ||||
|         crossterm::execute!(stderr(), EnterAlternateScreen, MoveTo(0, 0))?; | ||||
|         crossterm::execute!(stdout(), EnterAlternateScreen, MoveTo(0, 0))?; | ||||
|     } | ||||
| 
 | ||||
|     let volume_timer = Arc::new(AtomicUsize::new(0)); | ||||
| @ -251,10 +254,10 @@ pub async fn start( | ||||
|     } | ||||
| 
 | ||||
|     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()?; | ||||
| 
 | ||||
|     Ok(()) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user