diff --git a/Cargo.lock b/Cargo.lock index 5e8010b..c16fd94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1427,7 +1427,7 @@ dependencies = [ [[package]] name = "mpd_info_screen" -version = "0.2.13" +version = "0.2.14" dependencies = [ "ggez", "image", diff --git a/Cargo.toml b/Cargo.toml index 2bfaf59..7e7b8d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mpd_info_screen" -version = "0.2.13" +version = "0.2.14" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 74ebf54..51945c7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ counter, and the filename currently being played # Usage - mpd_info_screen 0.2.13 + mpd_info_screen 0.2.14 USAGE: mpd_info_screen [FLAGS] [OPTIONS] [port] @@ -24,13 +24,14 @@ counter, and the filename currently being played -V, --version Prints version information OPTIONS: - -l, --log-level [default: ERROR] [possible values: ERROR, WARNING, DEBUG, VERBOSE] + -l, --log-level [default: Error] [possible values: Error, Warning, Debug, Verbose] -p ARGS: [default: 6600] + Note that presing the Escape key when the window is focused closes the program. Also note that pressing the H key while displaying text will hide the text. diff --git a/src/debug_log.rs b/src/debug_log.rs index 9778cf4..1700a87 100644 --- a/src/debug_log.rs +++ b/src/debug_log.rs @@ -3,19 +3,19 @@ use structopt::clap::arg_enum; #[derive(Copy, Clone, Debug, PartialEq)] pub enum LogState { - ERROR, - WARNING, - DEBUG, - VERBOSE, + Error, + Warning, + Debug, + Verbose, } arg_enum! { #[derive(Copy, Clone, Debug, PartialEq)] pub enum LogLevel { - ERROR, - WARNING, - DEBUG, - VERBOSE, + Error, + Warning, + Debug, + Verbose, } } @@ -23,18 +23,18 @@ pub fn log(msg: T, state: LogState, level: LogLevel) where T: Display, { - if state == LogState::ERROR { + if state == LogState::Error { log_error(msg); - } else if state == LogState::WARNING { - if level != LogLevel::ERROR { + } else if state == LogState::Warning { + if level != LogLevel::Error { log_warning(msg); } - } else if state == LogState::DEBUG { - if level == LogLevel::DEBUG || level == LogLevel::VERBOSE { + } else if state == LogState::Debug { + if level == LogLevel::Debug || level == LogLevel::Verbose { log_debug(msg); } - } else if state == LogState::VERBOSE { - if level == LogLevel::VERBOSE { + } else if state == LogState::Verbose { + if level == LogLevel::Verbose { log_verbose(msg); } } else { @@ -46,26 +46,26 @@ pub fn log_error(msg: T) where T: Display, { - println!("ERROR: {}", msg); + println!("Error: {}", msg); } pub fn log_warning(msg: T) where T: Display, { - println!("WARNING: {}", msg); + println!("Warning: {}", msg); } pub fn log_debug(msg: T) where T: Display, { - println!("DEBUG: {}", msg); + println!("Debug: {}", msg); } pub fn log_verbose(msg: T) where T: Display, { - println!("VERBOSE: {}", msg); + println!("Verbose: {}", msg); } diff --git a/src/display.rs b/src/display.rs index e532137..c30f7ac 100644 --- a/src/display.rs +++ b/src/display.rs @@ -132,14 +132,14 @@ impl MPDDisplay { } log( "Successfully initialized MPDHandler", - debug_log::LogState::DEBUG, + debug_log::LogState::Debug, self.opts.log_level, ); } else { self.is_valid = false; log( "Failed to initialize MPDHandler", - debug_log::LogState::DEBUG, + debug_log::LogState::Debug, self.opts.log_level, ); } @@ -212,7 +212,7 @@ impl MPDDisplay { "Got image_format type {}", read_guard_opt.as_ref().unwrap().get_art_type() ), - debug_log::LogState::DEBUG, + debug_log::LogState::Debug, self.opts.log_level, ); @@ -242,7 +242,7 @@ impl MPDDisplay { .unwrap() .force_try_other_album_art() .map_err(|_| String::from("Failed to force try other album art fetching method"))?; - return Err("Got unknown format album art image".into()); + Err("Got unknown format album art image".into()) }; if is_unknown_format && !self.tried_album_art_in_dir { @@ -256,7 +256,7 @@ impl MPDDisplay { let img_result = ImageReader::with_format(Cursor::new(&image_ref), image_format) .decode() - .map_err(|e| format!("ERROR: Failed to decode album art image: {}", e)); + .map_err(|e| format!("Error: Failed to decode album art image: {}", e)); if img_result.is_err() && !self.tried_album_art_in_dir { return try_second_art_fetch_method( &mut self.tried_album_art_in_dir, @@ -273,7 +273,7 @@ impl MPDDisplay { rgba8.height() as u16, rgba8.as_raw(), ) - .map_err(|e| format!("ERROR: Failed to load album art image in ggez Image: {}", e))?; + .map_err(|e| format!("Error: Failed to load album art image in ggez Image: {}", e))?; self.album_art = Some(ggez_img); @@ -332,12 +332,12 @@ impl MPDDisplay { text_height_limit }) { - current_x = current_x * DECREASE_AMT; - current_y = current_y * DECREASE_AMT; + current_x *= DECREASE_AMT; + current_y *= DECREASE_AMT; continue; } else if screen_coords.w * MIN_WIDTH_RATIO > width { - current_x = current_x * INCREASE_AMT; - current_y = current_y * INCREASE_AMT; + current_x *= INCREASE_AMT; + current_y *= INCREASE_AMT; continue; } else { break; @@ -385,7 +385,7 @@ impl MPDDisplay { } else { log( "filename text is empty", - debug_log::LogState::WARNING, + debug_log::LogState::Warning, self.opts.log_level, ); } @@ -404,7 +404,7 @@ impl MPDDisplay { } else { log( "artist text is empty", - debug_log::LogState::WARNING, + debug_log::LogState::Warning, self.opts.log_level, ); } @@ -423,7 +423,7 @@ impl MPDDisplay { } else { log( "title text is empty", - debug_log::LogState::WARNING, + debug_log::LogState::Warning, self.opts.log_level, ); } @@ -566,7 +566,7 @@ impl EventHandler for MPDDisplay { { log( "dirty_flag cleared, acquiring shared data...", - debug_log::LogState::DEBUG, + debug_log::LogState::Debug, self.opts.log_level, ); self.shared = self @@ -613,14 +613,14 @@ impl EventHandler for MPDDisplay { } else { log( "Failed to acquire read lock for getting shared data", - debug_log::LogState::DEBUG, + debug_log::LogState::Debug, self.opts.log_level, ); } if self.album_art.is_none() { let result = self.get_image_from_data(ctx); if let Err(e) = result { - log(e, debug_log::LogState::WARNING, self.opts.log_level); + log(e, debug_log::LogState::Warning, self.opts.log_level); self.album_art = None; self.album_art_draw_transform = None; } else { diff --git a/src/main.rs b/src/main.rs index 483183c..be43427 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ pub struct Opt { short = "l", long = "log-level", possible_values = &debug_log::LogLevel::variants(), - default_value = "ERROR", + default_value = "Error", case_insensitive = true, )] log_level: debug_log::LogLevel, @@ -120,7 +120,7 @@ fn main() -> Result<(), String> { } x => log( format!("Other window event fired: {:?}", x), - debug_log::LogState::VERBOSE, + debug_log::LogState::Verbose, opt.log_level, ), }, @@ -129,13 +129,13 @@ fn main() -> Result<(), String> { let mut game_result: Result<(), GameError> = display.update(ctx); if game_result.is_err() { - println!("ERROR update: {}", game_result.unwrap_err()); + println!("Error update: {}", game_result.unwrap_err()); *control_flow = ControlFlow::Exit; return; } game_result = display.draw(ctx); if game_result.is_err() { - println!("ERROR draw: {}", game_result.unwrap_err()); + println!("Error draw: {}", game_result.unwrap_err()); *control_flow = ControlFlow::Exit; return; } @@ -148,7 +148,7 @@ fn main() -> Result<(), String> { } x => log( format!("Device event fired: {:?}", x), - debug_log::LogState::VERBOSE, + debug_log::LogState::Verbose, opt.log_level, ), } diff --git a/src/mpd_handler.rs b/src/mpd_handler.rs index 57f19d7..771d05b 100644 --- a/src/mpd_handler.rs +++ b/src/mpd_handler.rs @@ -195,7 +195,7 @@ fn read_line( buf_to_read = buf_to_read.split_off(2); result = String::from("OK"); buf.append(&mut buf_to_read); - //println!("WARNING: OK was reached"); // DEBUG + //println!("Warning: OK was reached"); // DEBUG return Ok(result); } } @@ -207,7 +207,7 @@ fn read_line( result.push(c); skip_count = s - 1; } else if let Err((msg, count)) = next_char_result { - //println!("ERROR: {}", msg); // DEBUG + //println!("Error: {}", msg); // DEBUG for i in 0..count { saved.push(buf_to_read[idx + i as usize]); } @@ -392,7 +392,7 @@ impl MPDHandler { // main thread failed to store handle to this thread log( "MPDHandle thread stopping due to failed handle storage", - LogState::ERROR, + LogState::Error, write_handle.log_level, ); break 'main; @@ -403,13 +403,13 @@ impl MPDHandler { if let Err(err_string) = self.handler_read_block(&mut buf, &mut saved, &mut saved_str) { log( format!("read_block error: {}", err_string), - LogState::WARNING, + LogState::Warning, log_level, ); } else if let Err(err_string) = self.handler_write_block() { log( format!("write_block error: {}", err_string), - LogState::WARNING, + LogState::Warning, log_level, ); } @@ -425,7 +425,7 @@ impl MPDHandler { log( "MPDHandler thread entering exit loop", - LogState::DEBUG, + LogState::Debug, log_level, ); 'exit: loop { @@ -479,7 +479,7 @@ impl MPDHandler { write_handle.art_data.len(), write_handle.art_data_size ), - LogState::DEBUG, + LogState::Debug, write_handle.log_level, ); if write_handle.art_data.len() == write_handle.art_data_size { @@ -494,7 +494,7 @@ impl MPDHandler { write_handle.art_data.len(), write_handle.art_data_size ), - LogState::DEBUG, + LogState::Debug, write_handle.log_level, ); if write_handle.art_data.len() == write_handle.art_data_size { @@ -512,7 +512,7 @@ impl MPDHandler { write_handle.is_init = false; log( "Got initial \"OK\" from MPD", - LogState::DEBUG, + LogState::Debug, write_handle.log_level, ); write_handle.poll_state = PollState::None; @@ -525,7 +525,7 @@ impl MPDHandler { if line.starts_with("OK") { log( format!("Got OK when poll state is {:?}", write_handle.poll_state), - LogState::DEBUG, + LogState::Debug, write_handle.log_level, ); match write_handle.poll_state { @@ -536,7 +536,7 @@ impl MPDHandler { write_handle.dirty_flag.store(true, Ordering::Relaxed); log( "No embedded album art", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -547,7 +547,7 @@ impl MPDHandler { write_handle.dirty_flag.store(true, Ordering::Relaxed); log( "No album art in dir", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -557,7 +557,7 @@ impl MPDHandler { write_handle.poll_state = PollState::None; break 'handle_buf; } else if line.starts_with("ACK") { - log(line, LogState::WARNING, write_handle.log_level); + log(line, LogState::Warning, write_handle.log_level); match write_handle.poll_state { PollState::Password => { write_handle.can_authenticate = false; @@ -575,7 +575,7 @@ impl MPDHandler { write_handle.dirty_flag.store(true, Ordering::Relaxed); log( "Failed to get readpicture", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); // Not setting error_text here since @@ -586,7 +586,7 @@ impl MPDHandler { write_handle.dirty_flag.store(true, Ordering::Relaxed); log( "Failed to get albumart", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); write_handle.error_text = "Failed to get album art from MPD".into(); @@ -622,7 +622,7 @@ impl MPDHandler { } else { log( "Failed to parse current song position", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -635,7 +635,7 @@ impl MPDHandler { } else { log( "Failed to parse current song duration", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -647,7 +647,7 @@ impl MPDHandler { } else { log( "Failed to parse album art byte size", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -658,7 +658,7 @@ impl MPDHandler { } else { log( "Failed to parse album art chunk byte size", - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -671,7 +671,7 @@ impl MPDHandler { } else { log( format!("Got unrecognized/ignored line: {}", line), - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); } @@ -683,7 +683,7 @@ impl MPDHandler { saved.len(), read_line_in_progress.len() ), - LogState::WARNING, + LogState::Warning, write_handle.log_level, ); *saved_str = read_line_in_progress; @@ -725,7 +725,7 @@ impl MPDHandler { } else if let Err(e) = write_result { log( format!("Failed to send password for authentication: {}", e), - LogState::ERROR, + LogState::Error, write_handle.log_level, ); } @@ -740,7 +740,7 @@ impl MPDHandler { } else if let Err(e) = write_result { log( format!("Failed to request song info over stream: {}", e), - LogState::ERROR, + LogState::Error, write_handle.log_level, ); } @@ -756,7 +756,7 @@ impl MPDHandler { } else if let Err(e) = write_result { log( format!("Failed to request status over stream: {}", e), - LogState::ERROR, + LogState::Error, write_handle.log_level, ); } @@ -775,7 +775,7 @@ impl MPDHandler { } else if let Err(e) = write_result { log( format!("Failed to request album art: {}", e), - LogState::ERROR, + LogState::Error, write_handle.log_level, ); } @@ -788,7 +788,7 @@ impl MPDHandler { } else if let Err(e) = write_result { log( format!("Failed to request album art in dir: {}", e), - LogState::ERROR, + LogState::Error, write_handle.log_level, ); } @@ -823,7 +823,7 @@ impl MPDHandlerState { self.art_data_size, self.art_data.len() ), - LogState::DEBUG, + LogState::Debug, self.log_level, ); self.art_data_size != 0 && self.art_data.len() == self.art_data_size