clean up rendering

This commit is contained in:
Crispy 2023-01-19 21:02:42 +01:00
parent 2de51f7a48
commit e239540a97

View file

@ -1,15 +1,11 @@
use crossterm::{ use crossterm::cursor::MoveTo;
cursor::MoveTo, use crossterm::event::{self, Event, KeyCode};
event::{self, Event, KeyCode}, use crossterm::terminal::{self, Clear, ClearType};
execute, use crossterm::ExecutableCommand;
terminal::{self, Clear, ClearType},
};
use rodio::{source::Source, OutputStream, OutputStreamHandle}; use rodio::{source::Source, OutputStream, OutputStreamHandle};
use std::{ use std::io::stdout;
io::stdout, use std::sync::{Arc, Mutex};
sync::{Arc, Mutex}, use std::time::Duration;
time::Duration,
};
mod sound; mod sound;
use sound::Snoud; use sound::Snoud;
@ -69,6 +65,8 @@ impl App {
.unwrap(); .unwrap();
terminal::enable_raw_mode().unwrap(); terminal::enable_raw_mode().unwrap();
stdout().execute(Clear(ClearType::All)).unwrap();
while !self.quit { while !self.quit {
self.render(); self.render();
self.input(); self.input();
@ -77,20 +75,17 @@ impl App {
} }
fn render(&mut self) { fn render(&mut self) {
execute!(stdout(), Clear(ClearType::All), MoveTo(0, 0)).unwrap(); stdout().execute(MoveTo(0, 0)).unwrap();
terminal::disable_raw_mode().unwrap(); println!("Snoud - ambient sound player\n\r");
println!("Snoud!!");
println!("--------");
for (i, channel) in self.channels.iter().enumerate() { for (i, channel) in self.channels.iter().enumerate() {
println!( println!(
"{}{}:\n {:.0}", "{}{}:\r\n {:3.0}%\r\n",
if i == self.selected_index { ">" } else { " " }, if i == self.selected_index { ">" } else { " " },
&channel.name, &channel.name,
(channel.volume * 100.0) (channel.volume * 100.0)
); );
} }
terminal::enable_raw_mode().unwrap();
} }
fn input(&mut self) { fn input(&mut self) {