hyprshell-launcher-lib 4.10.8

A modern GTK4-based window switcher and application launcher for Hyprland
Documentation
use crate::plugin::{PluginItem, PluginReturn};
use core_lib::WarnWithDetails;
use core_lib::transfer::{Identifier, PluginName};
use exec_lib::run::run_program;
use relm4::adw::gtk::gdk::Key;
use std::path::PathBuf;
use tracing::debug;

pub fn get_static_options(default_terminal: Option<&str>) -> Vec<PluginItem> {
    vec![PluginItem {
        iden: Identifier::plugin(PluginName::Terminal),
        key: 't',
        text: Box::from("Terminal"),
        details: Box::from("Run a command in a terminal"),
        icon: Some(
            PathBuf::from(default_terminal.map_or("system-run", |term| match term {
                // random fix for alacritty icon
                "alacritty" => "Alacritty",
                other => other,
            }))
            .into_boxed_path(),
        ),
    }]
}

pub fn launch_option(text: &str, default_terminal: Option<&str>) -> PluginReturn {
    if text.is_empty() {
        debug!("No text to run in terminal");
        return PluginReturn {
            show_animation: false,
        };
    }
    run_program(
        // exec shell to prevent needing 2 exits
        // echo to make the shell look better and show the executed command
        &format!("$SHELL -c \"echo '> {text}';{text};echo;exec $SHELL\""),
        None,
        true,
        default_terminal,
    )
    .warn_details("Failed to run program");
    PluginReturn {
        show_animation: true,
    }
}

pub fn get_chars() -> Vec<Key> {
    vec![Key::t]
}