Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/interpreter/flamegraph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::interpreter::clickhouse::Columns;
use crate::utils::open_url_command;
use anyhow::{Error, Result};
use crossterm::event::{self, Event as CrosstermEvent, KeyEventKind};
use flamelens::app::{App, AppResult};
Expand All @@ -9,7 +10,6 @@ use futures::channel::mpsc;
use ratatui::backend::CrosstermBackend;
use ratatui::Terminal;
use std::io;
use std::process::{Command, Stdio};
use tokio::time::{sleep, Duration};
use urlencoding::encode;
use warp::http::header::{HeaderMap, HeaderValue};
Expand Down Expand Up @@ -116,13 +116,11 @@ pub async fn open_in_speedscope(block: Columns) -> Result<()> {

// NOTE: here we need a webserver, since we cannot use localProfilePath due to browser
// policies
let mut child = Command::new("xdg-open")
.arg(format!(
"https://www.speedscope.app/#profileURL={}",
encode(&format!("http://{}/", bind_address))
))
.stderr(Stdio::null())
.stdout(Stdio::null())
let url = format!(
"https://www.speedscope.app/#profileURL={}",
encode(&format!("http://{}/", bind_address))
);
let mut child = open_url_command(&url)
.spawn()
.map_err(|e| Error::msg(format!("Cannot find/execute xdg-open ({})", e)))?;

Expand Down
34 changes: 24 additions & 10 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,30 @@ pub fn edit_query(query: &String, settings: &HashMap<String, String>) -> Result<
return Ok(query);
}

pub fn open_url_command(url: &str) -> Command {
let mut cmd = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
c.args(["/C", "start", "", url]); // "" to avoid stealing the first quoted argument as window title
c
} else if cfg!(target_os = "macos") {
let mut c = Command::new("open");
c.arg(url);
c
} else {
let mut c = Command::new("xdg-open");
c.arg(url);
c
};

cmd.stderr(Stdio::null()).stdout(Stdio::null());
cmd
}

pub fn open_graph_in_browser(graph: String) -> Result<()> {
let graph = encode(&graph);
Command::new("xdg-open")
.arg(format!(
"https://dreampuf.github.io/GraphvizOnline/#{}",
graph
))
// NOTE: avoid breaking of the chdig rendering (though this hides errors...)
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()?;
let url = format!(
"https://dreampuf.github.io/GraphvizOnline/#{}",
encode(&graph)
);
open_url_command(&url).status()?;
return Ok(());
}
Loading