From 9669c99f0c381e6ca52bab97e37fddae55c801ea Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sat, 4 May 2024 21:14:11 -0700 Subject: [PATCH] local_server: print the http URL even with --no-browser --- src/local_server.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/local_server.rs b/src/local_server.rs index aaa2b71..b06699b 100644 --- a/src/local_server.rs +++ b/src/local_server.rs @@ -163,18 +163,19 @@ pub async fn run_server( }; // Get the actual address we bound to. The primary reason to do this instead of - // using `port` is to find out what port number the OS picked if `cli.port==0`. + // using `port` is to find out what port number the OS picked if we ended up + // requesting port 0. let socket_addr = acceptor_to_socket_address(&acceptor)?; - // Now that the acceptor exists, the browser should be able to connect IIUC. - eprintln!("Listening at {socket_addr}."); + // Now that the acceptor exists, the browser should be able to connect. + let http_address = format!("http://{socket_addr}"); + eprintln!("Listening at {http_address}."); if open_browser { - let http_address = format!("http://{socket_addr}"); tokio::task::spawn_blocking(move || { // Use `spawn_blocking` since `webbrowser::open` may block (for text-mode // browsers. TODO: find out if it blocks when running a fresh instance of // `firefox` on Linux.) - eprintln!("Trying to launch a browser at {http_address}..."); - match open::that(&http_address) { + eprintln!("Trying to launch a browser..."); + match open::that(http_address) { Ok(_) => eprintln!("Successfully launched browser."), Err(err) => eprintln!("Failed to launch a browser: {err}"), }