From 69dd2a7a23d1d71c50a91f5779db6f0480106cd8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 7 May 2017 14:14:17 +0200 Subject: open_stream(): Remove hard-coded browser & port Instead get these from function arguments, which in turn get fed from the command line arguments passed by the user. --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e6e7f61..60780fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,10 @@ use std::process::Command; const DEFAULT_PORT: u16 = 37705; -fn open_stream() -> io::Result<()> { - let listener = TcpListener::bind("127.0.0.1:34254")?; +fn open_stream(browser: String, port: u16) -> io::Result<()> { + let listener = TcpListener::bind( + format!("127.0.0.1:{}", port) + )?; for stream in listener.incoming() { match stream { @@ -21,7 +23,7 @@ fn open_stream() -> io::Result<()> { Command::new("open") .arg("-a") - .arg("Opera") + .arg(&browser) // Trim the trailing newline, otherwise this doesn't // work @@ -73,7 +75,7 @@ fn main() { None => DEFAULT_PORT, }; - open_stream().unwrap_or_else(|e| { + open_stream(browser, port).unwrap_or_else(|e| { writeln!(io::stderr(), "{}", e) .expect("Failed printing to stderr"); }); -- cgit v1.2.3