rmptuif7894f1
add toggle mute keymap
+36 −1
4 files changed
- M README.md +1 −0
- M src/app.rs +1 −1
- M src/connection.rs +17 −0
- M src/event/handler.rs +17 −0
| @@ -15,6 +15,7 @@ rmptui is a minimal tui mpd client made with rust. | |||
| 15 | 15 | | `p` | Toggle pause | | |
| 16 | 16 | | `+`/`=` | Increase volume | | |
| 17 | 17 | | `-` | Decrease volume | | |
| 18 | + | | `m` | Toggle Mute | | |
| 18 | 19 | | `D` | Get dmenu prompt | | |
| 19 | 20 | | `j`/`Down` | Scroll down | | |
| 20 | 21 | | `k`/`Up` | Scroll up | | |
| @@ -429,7 +429,7 @@ impl App { | |||
| 429 | 429 | } | |
| 430 | 430 | } | |
| 431 | 431 | ||
| 432 | − | pub fn handle_mouse_left_click(&mut self, x: u16, y: u16) -> AppResult<()> { | |
| 432 | + | pub fn handle_mouse_left_click(&mut self, _x: u16, _y: u16) -> AppResult<()> { | |
| 433 | 433 | Ok(()) | |
| 434 | 434 | } | |
| 435 | 435 | } | |
| @@ -5,6 +5,12 @@ use mpd::{Client, State}; | |||
| 5 | 5 | use simple_dmenu::dmenu; | |
| 6 | 6 | use std::time::Duration; | |
| 7 | 7 | ||
| 8 | + | #[derive(Debug)] | |
| 9 | + | pub enum VolumeStatus { | |
| 10 | + | Muted(i8), | |
| 11 | + | Unmuted, | |
| 12 | + | } | |
| 13 | + | ||
| 8 | 14 | #[derive(Debug)] | |
| 9 | 15 | /// struct storing the mpd Client related stuff | |
| 10 | 16 | pub struct Connection { | |
| @@ -16,6 +22,7 @@ pub struct Connection { | |||
| 16 | 22 | pub current_song: Song, | |
| 17 | 23 | pub stats: mpd::Stats, | |
| 18 | 24 | pub status: mpd::Status, | |
| 25 | + | pub volume_status: VolumeStatus, | |
| 19 | 26 | } | |
| 20 | 27 | ||
| 21 | 28 | impl Connection { | |
| @@ -41,6 +48,13 @@ impl Connection { | |||
| 41 | 48 | .currentsong() | |
| 42 | 49 | .unwrap_or_else(|_| Some(empty_song.clone())) | |
| 43 | 50 | .unwrap_or(empty_song); | |
| 51 | + | ||
| 52 | + | let volume_status = if status.volume == 0 { | |
| 53 | + | VolumeStatus::Muted(status.volume) | |
| 54 | + | } else { | |
| 55 | + | VolumeStatus::Unmuted | |
| 56 | + | }; | |
| 57 | + | ||
| 44 | 58 | Ok(Self { | |
| 45 | 59 | conn, | |
| 46 | 60 | songs_filenames, | |
| @@ -50,6 +64,7 @@ impl Connection { | |||
| 50 | 64 | current_song, | |
| 51 | 65 | stats, | |
| 52 | 66 | status, | |
| 67 | + | volume_status, | |
| 53 | 68 | }) | |
| 54 | 69 | } | |
| 55 | 70 | ||
| @@ -207,6 +222,7 @@ impl Connection { | |||
| 207 | 222 | pub fn inc_volume(&mut self, v: i8) { | |
| 208 | 223 | let cur = self.status.volume; | |
| 209 | 224 | if cur + v <= 100 { | |
| 225 | + | self.volume_status = VolumeStatus::Unmuted; | |
| 210 | 226 | self.conn.volume(cur + v).unwrap(); | |
| 211 | 227 | } | |
| 212 | 228 | } | |
| @@ -215,6 +231,7 @@ impl Connection { | |||
| 215 | 231 | pub fn dec_volume(&mut self, v: i8) { | |
| 216 | 232 | let cur = self.status.volume; | |
| 217 | 233 | if cur - v >= 0 { | |
| 234 | + | self.volume_status = VolumeStatus::Unmuted; | |
| 218 | 235 | self.conn.volume(cur - v).unwrap(); | |
| 219 | 236 | } | |
| 220 | 237 | } | |
| @@ -1,5 +1,6 @@ | |||
| 1 | 1 | use crate::{ | |
| 2 | 2 | app::{App, AppResult, SelectedTab}, | |
| 3 | + | connection::VolumeStatus, | |
| 3 | 4 | ui::InputMode, | |
| 4 | 5 | }; | |
| 5 | 6 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}; | |
| @@ -138,6 +139,22 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 138 | 139 | app.conn.update_status(); | |
| 139 | 140 | } | |
| 140 | 141 | ||
| 142 | + | // Toggle Mute | |
| 143 | + | KeyCode::Char('m') => { | |
| 144 | + | match app.conn.volume_status { | |
| 145 | + | VolumeStatus::Muted(v) => { | |
| 146 | + | app.conn.conn.volume(v)?; | |
| 147 | + | app.conn.volume_status = VolumeStatus::Unmuted; | |
| 148 | + | } | |
| 149 | + | VolumeStatus::Unmuted => { | |
| 150 | + | let current_volume = app.conn.status.volume; | |
| 151 | + | app.conn.conn.volume(0)?; | |
| 152 | + | app.conn.volume_status = VolumeStatus::Muted(current_volume); | |
| 153 | + | } | |
| 154 | + | } | |
| 155 | + | app.conn.update_status(); | |
| 156 | + | } | |
| 157 | + | ||
| 141 | 158 | // Update MPD database | |
| 142 | 159 | KeyCode::Char('U') => { | |
| 143 | 160 | app.conn.conn.rescan()?; | |