Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ pub struct Cli {
#[clap(global = true, long = "force-terminal-output", short = 't')]
terminal_output: Option<bool>,

/// Overrides whether or not to wait for the handler childprocess
// NOTE: `handlr --sync open a b ...` is equivalent to `handlr --sync launch a ; handlr --sync launch b ; ...`)
#[clap(global = true, long = "sync", short = 'S', action = ArgAction::SetTrue)]
pub wait_for_handler_exit: Option<bool>,

#[command(flatten)]
pub verbosity: Verbosity<WarnLevel>,
}

#[cfg(executable)]
impl Cli {
pub fn wait_for_handler_exit(&self) -> bool {
self.wait_for_handler_exit.unwrap_or(false)
}

pub fn terminal_output(&self) -> bool {
self.terminal_output
.unwrap_or(std::io::stdout().is_terminal())
Expand Down Expand Up @@ -106,7 +115,7 @@ pub enum Cmd {
/// When using `--json` with `--all`, output will be in the form
///
/// {
/// "added_associations": [ ... ],
/// "added_associations": [ ... ],
/// "default_apps": [ ... ],
/// "system_apps": [ ... ]
/// }
Expand Down Expand Up @@ -349,6 +358,7 @@ mod tests {
},
enable_notifications: Some(true),
terminal_output: Some(false),
wait_for_handler_exit: Some(false),
verbosity: Verbosity::default(),
};

Expand Down
4 changes: 3 additions & 1 deletion src/common/desktop_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl DesktopEntry {

let mut cmd = execute::command(cmd);

if self.terminal && config.terminal_output {
if config.wait_for_handler_exit
|| (self.terminal && config.terminal_output)
{
cmd.spawn()?.wait()?;
} else {
cmd.stdout(Stdio::null()).stderr(Stdio::null()).spawn()?;
Expand Down
8 changes: 7 additions & 1 deletion src/config/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct Config {
pub config: ConfigFile,
/// Whether or not stdout is a terminal
pub terminal_output: bool,
/// Whether or not to wait for handlers to exit
pub wait_for_handler_exit: bool,
/// Configured languages
pub languages: Vec<String>,
}
Expand Down Expand Up @@ -65,7 +67,10 @@ pub fn get_languages() -> Languages {

impl Config {
/// Create a new instance of AppsConfig
pub fn new(terminal_output: bool) -> Result<Self> {
pub fn new(
terminal_output: bool,
wait_for_handler_exit: bool,
) -> Result<Self> {
let config = ConfigFile::load();
let languages = get_languages();

Expand All @@ -75,6 +80,7 @@ impl Config {
system_apps: SystemApps::populate(&languages)?,
config: config?,
terminal_output,
wait_for_handler_exit,
languages,
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ fn main() -> ExitCode {
/// Run main program logic
#[mutants::skip] // Cannot test directly at the moment
fn run(cli: Cli) -> Result<()> {
let mut config = Config::new(cli.terminal_output())?;
let mut config =
Config::new(cli.terminal_output(), cli.wait_for_handler_exit())?;

let mut stdout = std::io::stdout().lock();

Expand Down