Skip to content

Commit f94e5fd

Browse files
authored
#10 Feature add volume control (#11)
* feat: 10 add volume control
1 parent c9ae939 commit f94e5fd

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ loshell
3434
| `q` | Quit |
3535
| `s` | Play/stop radio |
3636
| `←/→` | Switch station |
37+
| `[ / ]` | Switch station |
3738
| `p` | Toggle pomodoro |
3839
| `space` | Start/pause timer |
3940
| `r` | Reset timer |

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,22 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
106106
height: 1,
107107
};
108108

109+
let vol = radio.volume();
110+
let bar_width = 12usize;
111+
let filled = (vol as usize * bar_width) / 100;
112+
let empty = bar_width - filled;
113+
let vol_bar = format!(
114+
" Volume: [{}{}] {}%",
115+
"█".repeat(filled),
116+
"-".repeat(empty),
117+
vol
118+
);
119+
109120
let station_line = Paragraph::new(Line::from(vec![
110121
Span::styled(format!("{} ", radio_icon), radio_style),
111122
Span::styled(radio.station().name, theme.hot()),
112123
Span::styled(status_text, theme.frame()),
124+
Span::styled(vol_bar, theme.frame()),
113125
]))
114126
.style(theme.base());
115127

@@ -144,6 +156,8 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
144156
Span::styled(format!("{} ", radio_action), theme.frame()),
145157
Span::styled("←/→ ", theme.accent()),
146158
Span::styled("station ", theme.frame()),
159+
Span::styled("[/] ", theme.accent()),
160+
Span::styled("volume ", theme.frame()),
147161
Span::styled("t ", theme.accent()),
148162
Span::styled("todos ", theme.frame()),
149163
Span::styled("T ", theme.accent()),
@@ -245,6 +259,8 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
245259
}
246260
KeyCode::Char('r') => pomo.stop_reset(),
247261
KeyCode::Char('+') => pomo.add_five_minutes(),
262+
KeyCode::Char('[') => radio.set_volume(radio.volume().saturating_sub(10)),
263+
KeyCode::Char(']') => radio.set_volume((radio.volume() + 10).min(100)),
248264
KeyCode::Esc => todos.toggle_visible(),
249265
_ => {}
250266
}
@@ -269,6 +285,8 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
269285
KeyCode::Char(' ') => pomo.start_pause(),
270286
KeyCode::Char('r') => pomo.stop_reset(),
271287
KeyCode::Char('+') => pomo.add_five_minutes(),
288+
KeyCode::Char('[') => radio.set_volume(radio.volume().saturating_sub(10)),
289+
KeyCode::Char(']') => radio.set_volume((radio.volume() + 10).min(100)),
272290
_ => {}
273291
}
274292
}

src/pomodoro.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ impl Pomodoro {
9090
thread::spawn(move || {
9191
#[cfg(target_os = "macos")]
9292
{
93-
let script = format!(
94-
"display notification \"{}\" with title \"{}\"",
95-
body, title
96-
);
93+
let script = format!("display notification \"{}\" with title \"{}\"", body, title);
9794
let _ = std::process::Command::new("osascript")
9895
.args(["-e", &script])
9996
.output();

src/radio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ impl Radio {
7272
self.volume.clone()
7373
}
7474

75+
pub fn volume(&self) -> u8 {
76+
self.volume.load(Ordering::SeqCst)
77+
}
78+
7579
pub fn station(&self) -> &Station {
7680
&STATIONS[self.current_station]
7781
}

0 commit comments

Comments
 (0)