rmptui0c8cfe3
add stats to Connection struct
+10 −1
2 files changed
- M src/connection.rs +9 −0
- M src/ui.rs +1 −1
| @@ -19,6 +19,7 @@ pub struct Connection { | |||
| 19 | 19 | pub repeat: bool, | |
| 20 | 20 | pub random: bool, | |
| 21 | 21 | pub current_song: Song, | |
| 22 | + | pub stats: mpd::Stats, | |
| 22 | 23 | } | |
| 23 | 24 | ||
| 24 | 25 | impl Connection { | |
| @@ -43,6 +44,7 @@ impl Connection { | |||
| 43 | 44 | let volume: u8 = status.volume as u8; | |
| 44 | 45 | let repeat = status.repeat; | |
| 45 | 46 | let random = status.random; | |
| 47 | + | let stats = conn.stats().unwrap_or_default(); | |
| 46 | 48 | ||
| 47 | 49 | let current_song = conn | |
| 48 | 50 | .currentsong() | |
| @@ -58,6 +60,7 @@ impl Connection { | |||
| 58 | 60 | repeat, | |
| 59 | 61 | random, | |
| 60 | 62 | current_song, | |
| 63 | + | stats, | |
| 61 | 64 | }) | |
| 62 | 65 | } | |
| 63 | 66 | ||
| @@ -81,6 +84,7 @@ impl Connection { | |||
| 81 | 84 | .currentsong() | |
| 82 | 85 | .unwrap_or_else(|_| Some(empty_song.clone())) | |
| 83 | 86 | .unwrap_or(empty_song); | |
| 87 | + | let stats = self.conn.stats().unwrap_or_default(); | |
| 84 | 88 | ||
| 85 | 89 | // Playback State | |
| 86 | 90 | match status.state { | |
| @@ -103,7 +107,12 @@ impl Connection { | |||
| 103 | 107 | // Random mode | |
| 104 | 108 | self.random = status.random; | |
| 105 | 109 | ||
| 110 | + | // Current song | |
| 106 | 111 | self.current_song = current_song; | |
| 112 | + | ||
| 113 | + | // | |
| 114 | + | ||
| 115 | + | self.stats = stats; | |
| 107 | 116 | } | |
| 108 | 117 | ||
| 109 | 118 | /// Get progress ratio of current playing song | |
| @@ -46,7 +46,7 @@ pub fn render(app: &mut App, frame: &mut Frame) { | |||
| 46 | 46 | ||
| 47 | 47 | /// Draws the directory | |
| 48 | 48 | fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |
| 49 | − | let total_songs = app.conn.conn.stats().unwrap().songs.to_string(); | |
| 49 | + | let total_songs = app.conn.stats.songs.to_string(); | |
| 50 | 50 | ||
| 51 | 51 | let rows = app.browser.filetree.iter().enumerate().map(|(i, (t, s))| { | |
| 52 | 52 | if t == "file" { | |