Skip to content

Commit ec88ffd

Browse files
authored
Merge pull request kstep#29 from AsamK/toggle_pause
Implement toggle pause command, by sending pause without argument
2 parents 1f81b55 + fff9040 commit ec88ffd

File tree

6 files changed

+47
-58
lines changed

6 files changed

+47
-58
lines changed

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ fn_arg_indent = "Tabbed"
88
single_line_if_else = true
99
reorder_imports = true
1010
chain_base_indent = "Tabbed"
11-
chain_indent = "Tabbed"
11+
chain_indent = "Block"
12+
chain_one_line_max = 160

src/client.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ impl<S: Read + Write> Client<S> {
166166
self.run_command("stop", ()).and_then(|_| self.expect_ok())
167167
}
168168

169+
/// Toggle pause state
170+
pub fn toggle_pause(&mut self) -> Result<()> {
171+
self.run_command("pause", ()).and_then(|_| self.expect_ok())
172+
}
173+
169174
/// Set pause state
170175
pub fn pause(&mut self, value: bool) -> Result<()> {
171176
self.run_command("pause", value as u8).and_then(|_| self.expect_ok())
@@ -474,8 +479,12 @@ impl<S: Read + Write> Client<S> {
474479
/// List all channels available for current connection
475480
pub fn channels(&mut self) -> Result<Vec<Channel>> {
476481
self.run_command("channels", ()).and_then(|_| self.read_list("channel")).map(|v| {
477-
v.into_iter().map(|b| unsafe { Channel::new_unchecked(b) }).collect()
478-
})
482+
v.into_iter()
483+
.map(|b| unsafe {
484+
Channel::new_unchecked(b)
485+
})
486+
.collect()
487+
})
479488
}
480489

481490
/// Read queued messages from subscribed channels
@@ -553,32 +562,26 @@ impl<S: Read + Write> Client<S> {
553562

554563
/// List all stickers from a given object, identified by type and uri
555564
pub fn stickers(&mut self, typ: &str, uri: &str) -> Result<Vec<String>> {
556-
self.run_command("sticker list", (typ, uri)).and_then(|_| self.read_list("sticker")).map(|v| {
557-
v.into_iter()
558-
.map(|b| {
559-
b.splitn(2, '=')
560-
.nth(1)
561-
.map(|s| s.to_owned())
562-
.unwrap()
563-
})
564-
.collect()
565-
})
565+
self.run_command("sticker list", (typ, uri))
566+
.and_then(|_| self.read_list("sticker"))
567+
.map(|v| v.into_iter().map(|b| b.splitn(2, '=').nth(1).map(|s| s.to_owned()).unwrap()).collect())
566568
}
567569

568570
/// List all (file, sticker) pairs for sticker name and objects of given type
569571
/// from given directory (identified by uri)
570572
pub fn find_sticker(&mut self, typ: &str, uri: &str, name: &str) -> Result<Vec<(String, String)>> {
571-
self.run_command("sticker find", (typ, uri, name)).and_then(|_| {
572-
self.read_pairs()
573-
.split("file")
574-
.map(|rmap| {
575-
rmap.map(|mut map| {
576-
(map.remove("file").unwrap(),
577-
map.remove("sticker").and_then(|s| s.splitn(2, '=').nth(1).map(|s| s.to_owned())).unwrap())
578-
})
579-
})
580-
.collect()
581-
})
573+
self.run_command("sticker find", (typ, uri, name))
574+
.and_then(|_| {
575+
self.read_pairs()
576+
.split("file")
577+
.map(|rmap| {
578+
rmap.map(|mut map| {
579+
(map.remove("file").unwrap(),
580+
map.remove("sticker").and_then(|s| s.splitn(2, '=').nth(1).map(|s| s.to_owned())).unwrap())
581+
})
582+
})
583+
.collect()
584+
})
582585
}
583586

584587
/// List all files of a given type under given directory (identified by uri)

src/message.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ impl Channel {
6565
/// Valid channel name can contain only English letters (`A`-`Z`, `a`-`z`),
6666
/// numbers (`0`-`9`), underscore, forward slash, dot and colon (`_`, `/`, `.`, `:`)
6767
pub fn is_valid_name(name: &str) -> bool {
68-
name.bytes().all(|b| {
69-
(0x61 <= b && b <= 0x7a) || (0x41 <= b && b <= 0x5a) || (0x30 <= b && b <= 0x39) ||
70-
(b == 0x5f || b == 0x2f || b == 0x2e || b == 0x3a)
71-
})
68+
name.bytes()
69+
.all(|b| {
70+
(0x61 <= b && b <= 0x7a) || (0x41 <= b && b <= 0x5a) || (0x30 <= b && b <= 0x39) ||
71+
(b == 0x5f || b == 0x2f || b == 0x2e || b == 0x3a)
72+
})
7273
}
7374
}

src/proto.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,11 @@ pub trait Proto {
107107
fn read_structs<'a, T>(&'a mut self, key: &'static str) -> Result<Vec<T>>
108108
where T: 'a + FromMap
109109
{
110-
self.read_pairs()
111-
.split(key)
112-
.map(|v| v.and_then(FromMap::from_map))
113-
.collect()
110+
self.read_pairs().split(key).map(|v| v.and_then(FromMap::from_map)).collect()
114111
}
115112

116113
fn read_list(&mut self, key: &'static str) -> Result<Vec<String>> {
117-
self.read_pairs()
118-
.filter(|r| r.as_ref().map(|&(ref a, _)| *a == key).unwrap_or(true))
119-
.map(|r| r.map(|(_, b)| b))
120-
.collect()
114+
self.read_pairs().filter(|r| r.as_ref().map(|&(ref a, _)| *a == key).unwrap_or(true)).map(|r| r.map(|(_, b)| b)).collect()
121115
}
122116

123117
fn read_struct<'a, T>(&'a mut self) -> Result<T>

src/song.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ impl Default for Range {
6969

7070
impl fmt::Display for Range {
7171
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
72-
self.0
73-
.num_seconds()
74-
.fmt(f)?;
72+
self.0.num_seconds().fmt(f)?;
7573
f.write_str(":")?;
7674
if let Some(v) = self.1 {
7775
v.num_seconds().fmt(f)?;

src/status.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ impl Encodable for Status {
7373
e.emit_option(|e| match self.time {
7474
Some(p) => {
7575
e.emit_option_some(|e| {
76-
e.emit_tuple(2, |e| {
76+
e.emit_tuple(2, |e| {
7777
e.emit_tuple_arg(0, |e| p.0.num_seconds().encode(e))?;
7878
e.emit_tuple_arg(1, |e| p.1.num_seconds().encode(e))?;
7979
Ok(())
8080
})
81-
})
81+
})
8282
}
8383
None => e.emit_option_none(),
8484
})
@@ -197,18 +197,8 @@ impl FromIter for Status {
197197
})
198198
}
199199
// TODO" => float errors don't work on stable
200-
"elapsed" => {
201-
result.elapsed = line.1
202-
.parse::<f32>()
203-
.ok()
204-
.map(|v| Duration::milliseconds((v * 1000.0) as i64))
205-
}
206-
"duration" => {
207-
result.duration = line.1
208-
.parse::<f32>()
209-
.ok()
210-
.map(|v| Duration::milliseconds((v * 1000.0) as i64))
211-
}
200+
"elapsed" => result.elapsed = line.1.parse::<f32>().ok().map(|v| Duration::milliseconds((v * 1000.0) as i64)),
201+
"duration" => result.duration = line.1.parse::<f32>().ok().map(|v| Duration::milliseconds((v * 1000.0) as i64)),
212202
"bitrate" => result.bitrate = Some(try!(line.1.parse())),
213203
"xfade" => result.crossfade = Some(Duration::seconds(try!(line.1.parse()))),
214204
// "mixrampdb" => 0.0, //get_field!(map, "mixrampdb"),
@@ -242,11 +232,13 @@ impl FromStr for AudioFormat {
242232
let mut it = s.split(':');
243233
Ok(AudioFormat {
244234
rate: try!(it.next().ok_or(ParseError::NoRate).and_then(|v| v.parse().map_err(ParseError::BadRate))),
245-
bits: try!(it.next().ok_or(ParseError::NoBits).and_then(|v| if &*v == "f" {
246-
Ok(0)
247-
} else {
248-
v.parse().map_err(ParseError::BadBits)
249-
})),
235+
bits: try!(it.next()
236+
.ok_or(ParseError::NoBits)
237+
.and_then(|v| if &*v == "f" {
238+
Ok(0)
239+
} else {
240+
v.parse().map_err(ParseError::BadBits)
241+
})),
250242
chans: try!(it.next().ok_or(ParseError::NoChans).and_then(|v| v.parse().map_err(ParseError::BadChans))),
251243
})
252244
}

0 commit comments

Comments
 (0)