Krolyxon
Commit 255687b

rmptui255687b

use environment variable for MPD_PORT and MPD_HOST

Author
krolxon
Date
2024-04-27 11:38 +0530
Parent
59eed99
Commit
255687be7cb6e6314f2c6f56c098d5113c1c091a

+8 −40

2 files changed

  1. M src/handler.rs +4 −39
  2. M src/main.rs +4 −1
M src/handler.rs View
@@ -177,14 +177,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
177177
178178 // Playback controls
179179 // Toggle Pause
180− KeyCode::Char('p') => {
181− app.conn.toggle_pause();
182− }
180+ KeyCode::Char('p') => app.conn.toggle_pause(),
183181
184182 // Pause
185− KeyCode::Char('s') => {
186− app.conn.pause();
187− }
183+ KeyCode::Char('s') => app.conn.pause(),
188184
189185 // Toggle rpeat
190186 KeyCode::Char('r') => {
@@ -199,41 +195,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
199195 }
200196
201197 // Dmenu prompt
202− KeyCode::Char('D') => {
203− app.conn.play_dmenu()?;
204− }
198+ KeyCode::Char('D') => app.conn.play_dmenu()?,
205199
206200 // add to queue
207− KeyCode::Char('a') => {
208− // let list = app
209− // .conn
210− // .songs_filenames
211− // .iter()
212− // .map(|f| f.as_str())
213− // .collect::<Vec<&str>>();
214− //
215− // let files: Vec<String> = app
216− // .browser
217− // .filetree
218− // .clone()
219− // .into_iter()
220− // .map(|(_, f)| f)
221− // .collect();
222− //
223− // let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(
224− // &files.get(app.browser.selected).unwrap(),
225− // &list,
226− // )
227− // .get(0)
228− // .unwrap()
229− // .clone();
230− //
231− // let song = app.conn.get_song_with_only_filename(filename);
232− //
233− // app.conn.conn.push(&song)?;
234−
235− app.playlist_popup = true;
236− }
201+ KeyCode::Char('a') => app.playlist_popup = true,
237202
238203 KeyCode::Right => {
239204 app.conn
M src/main.rs View
@@ -11,6 +11,7 @@ use rmptui::event::EventHandler;
1111 use rmptui::handler;
1212 use rmptui::song::RSong;
1313 use rmptui::tui;
14+use std::env;
1415 use std::io;
1516
1617 use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
@@ -25,7 +26,9 @@ pub type Error = Box<dyn std::error::Error>;
2526
2627 fn main() -> AppResult<()> {
2728 let args = Args::parse();
28− let mut app = App::builder("127.0.0.1:6600")?;
29+ let env_host = env::var("MPD_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
30+ let env_port = env::var("MPD_PORT").unwrap_or_else(|_| "6600".to_string());
31+ let mut app = App::builder(format!("{}:{}", env_host, env_port).as_str())?;
2932
3033 if !args.tui {
3134 handle_tui(&mut app)?;