diff --git a/README.md b/README.md index ea07187..547f4d1 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ the gophersphere. -o, --tor Use local Tor proxy to open all pages -S, -O Disable TLS or Tor + -m, --media PROGRAM Use to open media files. Default: mpv + -M, --no-media Just download media files, don't download + -r, --raw Print raw Gopher response only -p, --print Print rendered Gopher response only -l, --local Connect to 127.0.0.1:7070 diff --git a/doc/phetch.1.md b/doc/phetch.1.md index a73c02b..515f0d6 100644 --- a/doc/phetch.1.md +++ b/doc/phetch.1.md @@ -49,6 +49,14 @@ If no URL is given, however, *phetch* will launch and open its default *-O*, *--no-tor* Disable Tor. +*-m*, *--media* _PATH_ + Use program at _PATH_ to open media files (movies and sounds). + Default: mpv + +*-M*, *--no-media* + Don't try to open media files. Download them like regular binary + Gopher items. + *-c*, *--config* _FILE_ Use _FILE_ instead of _~/.config/phetch/phetch.conf_ @@ -169,7 +177,7 @@ If you create a _history.gph_ file in _~/.config/phetch/_, each Gopher URL you open will be stored there. New URLs are appended to the bottom, but loaded in reverse order, so -you'll see all the most recently visited pages first when you press +you'll see all the most recently visited pages first when you press the *a* key. Feel free to edit your history file directly, or share it with your @@ -199,6 +207,9 @@ tor no # Always start in wide mode. wide no +# Program to use to open media files. +media mpv + # Use emoji indicators for TLS & Tor. emoji no ``` diff --git a/src/config.rs b/src/config.rs index c51d3b2..43a4496 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,6 +16,9 @@ const CONFIG_FILE: &str = "phetch.conf"; /// Default start page. const DEFAULT_START: &str = "gopher://phetch/1/home"; +/// Default media player. +const DEFAULT_MEDIA_PLAYER: &str = "mpv"; + /// Example of what a default phetch.conf would be. pub const DEFAULT_CONFIG: &str = "## default config file for the phetch gopher client ## gopher://phkt.io/1/phetch @@ -32,6 +35,9 @@ tor no # Always start in wide mode. (--wide) wide no +# Program to use to open media files. +media mpv + # Use emoji indicators for TLS & Tor. (--emoji) emoji no "; @@ -51,6 +57,8 @@ pub struct Config { pub wide: bool, /// Render connection status as emoji pub emoji: bool, + /// Media player to use. + pub media: Option, /// UI mode. Can't be set in conf file. pub mode: ui::Mode, } @@ -63,6 +71,7 @@ impl Default for Config { tor: false, wide: false, emoji: false, + media: Some(DEFAULT_MEDIA_PLAYER.into()), mode: ui::Mode::default(), } } @@ -127,6 +136,12 @@ pub fn parse(text: &str) -> Result { "tls" => cfg.tls = to_bool(val)?, "tor" => cfg.tor = to_bool(val)?, "wide" => cfg.wide = to_bool(val)?, + "media" => { + cfg.media = match val.to_lowercase().as_ref() { + "false" | "none" => None, + _ => Some(val.into()), + } + } _ => return Err(error!("Unknown key on line {}: {}", linenum, key)), } keys.insert(key, true); @@ -157,6 +172,7 @@ mod tests { assert_eq!(config.wide, false); assert_eq!(config.emoji, false); assert_eq!(config.start, "gopher://phetch/1/home"); + assert_eq!(config.media, Some("mpv".to_string())); } #[test] @@ -185,6 +201,21 @@ mod tests { assert_eq!(cfg.wide, true); } + #[test] + fn test_media() { + let cfg = parse("media FALSE").unwrap(); + assert_eq!(cfg.media, None); + + let cfg = parse("media None").unwrap(); + assert_eq!(cfg.media, None); + + let cfg = parse("media /path/to/media-player").unwrap(); + assert_eq!(cfg.media, Some("/path/to/media-player".to_string())); + + let cfg = parse("media vlc").unwrap(); + assert_eq!(cfg.media, Some("vlc".to_string())); + } + #[test] fn test_no_or_false() { let cfg = parse("tls false\nwide no\ntor n").unwrap(); diff --git a/src/main.rs b/src/main.rs index 35be4ea..e0b5217 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,6 +77,9 @@ Options: -o, --tor Use local Tor proxy to open all pages -S, -O Disable TLS or Tor + -m, --media PROGRAM Use to open media files. Default: mpv + -M, --no-media Just download media files, don't download + -r, --raw Print raw Gopher response only -p, --print Print rendered Gopher response only -l, --local Connect to 127.0.0.1:7070