From f7cc81ef359e8d9ecb7e4ce3b34e43d9d94e2071 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 13 Apr 2017 02:53:53 +0200 Subject: main.rs: Open the stream input in Opera Use the Mac OS X `open` command to open Opera and pass in the contents of the TCP stream as an argument, assuming it to be a URL that should be opened in the browser. Only dealing with the `open` command for now. Will be extending this to support user-customisable browsers, so that any GUI browser that can be opened with `open` can be used. --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index fcd9cfd..09dc892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::io::{self, Write}; use std::io::prelude::*; use std::net::TcpListener; +use std::process::Command; fn open_stream() -> io::Result<()> { let listener = TcpListener::bind("127.0.0.1:34254")?; @@ -11,7 +12,14 @@ fn open_stream() -> io::Result<()> { let mut url = String::new(); stream.read_to_string(&mut url)?; - println!("{}", url); + Command::new("open") + .arg("-a") + .arg("Opera") + + // Trim the trailing newline, otherwise this doesn't + // work + .arg(&url.trim_right()) + .spawn()?; } Err(e) => { write!(io::stderr(), "{}", e)?; -- cgit v1.2.3