Just format the code :P
This commit is contained in:
parent
355ef0db93
commit
cb5c02d0b9
4 changed files with 67 additions and 42 deletions
|
@ -1,13 +1,13 @@
|
|||
mod events;
|
||||
mod query;
|
||||
mod player_settings;
|
||||
mod query;
|
||||
|
||||
use crate::cmus::query::CmusQueryResponse;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use typed_builder::TypedBuilder;
|
||||
use crate::cmus::query::CmusQueryResponse;
|
||||
|
||||
#[derive(Debug, PartialEq, Default)]
|
||||
pub struct TrackMetadata {
|
||||
|
@ -176,7 +176,9 @@ impl Track {
|
|||
/// And collect the output, and parse it into a `CmusQueryResponse`.
|
||||
/// If the cmus is not running, or the socket is not available, this function will return an error.
|
||||
#[inline]
|
||||
pub fn ping_cmus(query_command: &mut std::process::Command) -> Result<CmusQueryResponse, CmusError> {
|
||||
pub fn ping_cmus(
|
||||
query_command: &mut std::process::Command,
|
||||
) -> Result<CmusQueryResponse, CmusError> {
|
||||
// Just run the command, and collect the output.
|
||||
let output = query_command
|
||||
.output()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::cmus::CmusError;
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use crate::cmus::CmusError;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct PlayerSettings {
|
||||
|
@ -41,7 +41,7 @@ impl FromStr for AAAMode {
|
|||
"all" => Ok(Self::All),
|
||||
"album" => Ok(Self::Album),
|
||||
"artist" => Ok(Self::Artist),
|
||||
_ => Err(CmusError::UnknownAAAMode(s.to_string()))
|
||||
_ => Err(CmusError::UnknownAAAMode(s.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl FromStr for Shuffle {
|
|||
"off" => Ok(Self::Off),
|
||||
"tracks" => Ok(Self::Tracks),
|
||||
"albums" => Ok(Self::Albums),
|
||||
_ => Err(CmusError::UnknownShuffleMode(s.to_string()))
|
||||
_ => Err(CmusError::UnknownShuffleMode(s.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,15 +72,25 @@ impl FromStr for PlayerSettings {
|
|||
for line in s.lines() {
|
||||
if line.starts_with("set ") {
|
||||
let line = &line[4..];
|
||||
let (key, value) = line.split_once(" ").ok_or(CmusError::UnknownError("Corrupted cmus response".to_string()))?;
|
||||
let (key, value) = line.split_once(" ").ok_or(CmusError::UnknownError(
|
||||
"Corrupted cmus response".to_string(),
|
||||
))?;
|
||||
|
||||
match key {
|
||||
"repeat" => repeat = value == "true",
|
||||
"repeat_current" => repeat_current = value == "true",
|
||||
"shuffle" => shuffle = Shuffle::from_str(value)?,
|
||||
"aaa_mode" => aaa_mode = AAAMode::from_str(value)?,
|
||||
"vol_left" => volume.left = value.parse().map_err(|e: ParseIntError| CmusError::UnknownError(e.to_string()))?,
|
||||
"vol_right" => volume.right = value.parse().map_err(|e: ParseIntError| CmusError::UnknownError(e.to_string()))?,
|
||||
"vol_left" => {
|
||||
volume.left = value
|
||||
.parse()
|
||||
.map_err(|e: ParseIntError| CmusError::UnknownError(e.to_string()))?
|
||||
}
|
||||
"vol_right" => {
|
||||
volume.right = value
|
||||
.parse()
|
||||
.map_err(|e: ParseIntError| CmusError::UnknownError(e.to_string()))?
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +120,10 @@ mod tests {
|
|||
assert_eq!(all, Ok(AAAMode::All));
|
||||
assert_eq!(album, Ok(AAAMode::Album));
|
||||
assert_eq!(artist, Ok(AAAMode::Artist));
|
||||
assert_eq!(unknown, Err(CmusError::UnknownAAAMode("unknown".to_string())));
|
||||
assert_eq!(
|
||||
unknown,
|
||||
Err(CmusError::UnknownAAAMode("unknown".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -123,7 +136,10 @@ mod tests {
|
|||
assert_eq!(off, Ok(Shuffle::Off));
|
||||
assert_eq!(tracks, Ok(Shuffle::Tracks));
|
||||
assert_eq!(albums, Ok(Shuffle::Albums));
|
||||
assert_eq!(unknown, Err(CmusError::UnknownShuffleMode("unknown".to_string())));
|
||||
assert_eq!(
|
||||
unknown,
|
||||
Err(CmusError::UnknownShuffleMode("unknown".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -133,15 +149,18 @@ mod tests {
|
|||
|
||||
let settings = PlayerSettings::from_str(setting_sample);
|
||||
|
||||
assert_eq!(settings, Ok(PlayerSettings {
|
||||
repeat: false,
|
||||
repeat_current: false,
|
||||
shuffle: Shuffle::Tracks,
|
||||
aaa_mode: AAAMode::Artist,
|
||||
volume: Volume {
|
||||
left: 46,
|
||||
right: 46,
|
||||
}
|
||||
}));
|
||||
assert_eq!(
|
||||
settings,
|
||||
Ok(PlayerSettings {
|
||||
repeat: false,
|
||||
repeat_current: false,
|
||||
shuffle: Shuffle::Tracks,
|
||||
aaa_mode: AAAMode::Artist,
|
||||
volume: Volume {
|
||||
left: 46,
|
||||
right: 46,
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::str::FromStr;
|
||||
use crate::cmus::{CmusError, Track};
|
||||
use crate::cmus::player_settings::PlayerSettings;
|
||||
use crate::cmus::{CmusError, Track};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// This struct is used to store the row status response from cmus.
|
||||
/// So we don't parse it and take the time then we don't need it.
|
||||
|
@ -41,10 +41,10 @@ impl CmusQueryResponse {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use test_context::{test_context, TestContext};
|
||||
use super::*;
|
||||
use crate::cmus::player_settings::{AAAMode, Shuffle};
|
||||
use crate::cmus::TrackStatus;
|
||||
use super::*;
|
||||
use test_context::{test_context, TestContext};
|
||||
|
||||
#[test]
|
||||
fn test_parse_query_from_str() {
|
||||
|
@ -54,8 +54,14 @@ mod tests {
|
|||
assert!(query.is_ok());
|
||||
let query = query.unwrap();
|
||||
|
||||
assert_eq!(query.track_row, include_str!("../../tests/samples/row/cmus-remote-output-track-row.txt"));
|
||||
assert_eq!(query.player_settings_row, include_str!("../../tests/samples/row/cmus-remote-output-player-row.txt"));
|
||||
assert_eq!(
|
||||
query.track_row,
|
||||
include_str!("../../tests/samples/row/cmus-remote-output-track-row.txt")
|
||||
);
|
||||
assert_eq!(
|
||||
query.player_settings_row,
|
||||
include_str!("../../tests/samples/row/cmus-remote-output-player-row.txt")
|
||||
);
|
||||
}
|
||||
|
||||
struct Context {
|
||||
|
@ -67,9 +73,7 @@ mod tests {
|
|||
let row = include_str!("../../tests/samples/row/cmus-remote-output-row.txt");
|
||||
let query = CmusQueryResponse::from_str(row).unwrap();
|
||||
|
||||
Self {
|
||||
query,
|
||||
}
|
||||
Self { query }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +85,10 @@ mod tests {
|
|||
assert!(track.is_ok());
|
||||
let track = track.unwrap();
|
||||
|
||||
assert_eq!(track.path, "/mnt/Data/Music/FLAC/Taylor Swift/Taylor Swift - Speak Now/12 - Haunted.mp3");
|
||||
assert_eq!(
|
||||
track.path,
|
||||
"/mnt/Data/Music/FLAC/Taylor Swift/Taylor Swift - Speak Now/12 - Haunted.mp3"
|
||||
);
|
||||
assert_eq!(track.status, TrackStatus::Playing);
|
||||
assert_eq!(track.position, 34);
|
||||
assert_eq!(track.duration, 242);
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -19,7 +19,6 @@ fn main() {
|
|||
&args.cmus_socket_password,
|
||||
);
|
||||
|
||||
|
||||
let sleep = || {
|
||||
std::thread::sleep(std::time::Duration::from_millis(args.interval));
|
||||
};
|
||||
|
@ -43,18 +42,16 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
/* // Compare the track info with the previous one, and if they are the same, just sleep for a while and try again.
|
||||
if track == previous_track {
|
||||
sleep();
|
||||
continue;
|
||||
}
|
||||
/* // Compare the track info with the previous one, and if they are the same, just sleep for a while and try again.
|
||||
if track == previous_track {
|
||||
sleep();
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the track info is different from the previous one, get the changes events.
|
||||
let changes = track.get_changes(&previous_track);
|
||||
*/
|
||||
// If the track info is different from the previous one, get the changes events.
|
||||
let changes = track.get_changes(&previous_track);
|
||||
*/
|
||||
|
||||
sleep();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue