Quit on error, log
parent
1d33339439
commit
abfccf1a17
|
@ -105,6 +105,12 @@ dependencies = [
|
|||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paris"
|
||||
version = "1.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2eaf2319cd71dd9ff38c72bebde61b9ea657134abcf26ae4205f54f772a32810"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
|
@ -327,5 +333,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"crossterm",
|
||||
"mpd",
|
||||
"paris",
|
||||
"tui",
|
||||
]
|
||||
|
|
|
@ -23,6 +23,7 @@ images = []
|
|||
tui = "0.19"
|
||||
crossterm = "0.25"
|
||||
mpd = "*"
|
||||
paris = { version = "1.5", features = ["no_logger", "macros"] }
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -7,6 +7,7 @@ use std::{
|
|||
error::Error,
|
||||
io,
|
||||
time::{Duration, Instant},
|
||||
process::{ExitCode,exit},
|
||||
};
|
||||
use tui::{
|
||||
backend::{Backend, CrosstermBackend},
|
||||
|
@ -16,7 +17,8 @@ use tui::{
|
|||
widgets::{Block, BorderType, Borders, Gauge, List, ListItem, ListState},
|
||||
Frame, Terminal,
|
||||
};
|
||||
extern crate mpd;
|
||||
|
||||
use paris::error;
|
||||
|
||||
use mpd::Client;
|
||||
use std::net::TcpStream;
|
||||
|
@ -80,9 +82,19 @@ struct App<'a> {
|
|||
|
||||
impl<'a> App<'a> {
|
||||
fn new() -> App<'a> {
|
||||
let client = match Client::connect("127.0.0.1:6600") {
|
||||
Ok(conn) => {
|
||||
conn
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Could not connect to MPD daemon: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
App {
|
||||
items: StatefulList::with_items(vec![("Item0", 1), ("Item1", 2), ("Item2", 3)]),
|
||||
mpd_client: Client::connect("127.0.0.1:6600").unwrap(),
|
||||
mpd_client: client,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +122,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
terminal.show_cursor()?;
|
||||
|
||||
if let Err(err) = res {
|
||||
println!("{:?}", err)
|
||||
error!("{:?}", err)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -143,6 +155,12 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App, tick_rate: Dura
|
|||
}
|
||||
|
||||
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||
let mpd_status = match app.mpd_client.status() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
// Wrapping block for a group
|
||||
// Just draw the block and the group on the same area and build the group
|
||||
// with at least a margin of 1
|
||||
|
@ -236,8 +254,17 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
|||
f.render_widget(songs, bottom_chunks[2]);
|
||||
|
||||
// Timeline
|
||||
let time = app.mpd_client.status().unwrap().time.unwrap();
|
||||
let percent: f64 = (time.0.num_seconds() as f64 / time.1.num_seconds() as f64) * 100.0;
|
||||
let percent = match mpd_status.time {
|
||||
Some(t) => {
|
||||
let played = t.0.num_seconds() as f64;
|
||||
let total = t.1.num_seconds() as f64;
|
||||
let result = played / total;
|
||||
result * 100.0
|
||||
},
|
||||
None => {
|
||||
0.0
|
||||
},
|
||||
};
|
||||
let timeline = Gauge::default()
|
||||
.block(Block::default().borders(Borders::NONE))
|
||||
.gauge_style(Style::default().fg(Color::Red))
|
||||
|
|
Loading…
Reference in New Issue