#scripting #dynamic-menu

bin+lib thqm

一个简单的 HTTP 服务器,用于通过网络为您的脚本提供动态菜单

5 个版本

0.1.6 2023 年 3 月 7 日
0.1.4 2022 年 2 月 16 日
0.1.3 2022 年 2 月 13 日
0.1.1 2022 年 2 月 8 日
0.1.0 2022 年 2 月 4 日

#423HTTP 服务器

MIT 许可证

1.5MB
5K SLoC

JavaScript 4K SLoC // 0.0% comments Rust 746 SLoC // 0.0% comments

thqm

一个简单的 HTTP 服务器,用于通过网络为您的脚本提供动态菜单。


thqm 的名字来源于阿拉伯语 تحكم,发音为 tahakoom,意为控制。

thqm 是一个小巧的 HTTP 服务器。它根据提供的 stdin 动态生成网页菜单,并将任何选择输出到 stdout。在某种程度上,它的功能类似于 dmenu/rofi,但作为 HTTP 服务器。

这使得它非常灵活,且易于脚本使用。

请参阅 示例脚本文件夹 中的示例脚本。

📦 安装

手动

要从此仓库手动编译和安装,您需要已安装 rust

编译二进制文件

$ git clone https://github.com/loiccoyle/thqm-rs
$ cd thqm-rs
$ cargo build --release

编译后的二进制文件将位于 ./target/release/thqm。只需将此二进制文件放置在您的 $PATH 中。

Cargo

$ cargo install thqm

Arch linux (AUR)

使用您喜欢的 AUR 辅助工具

$ paru -S thqm

📋 使用方法

CLI 选项

thqm 有一些命令行选项,如有疑问,请查看 --help

$thqm --help
thqm 0.1.6
Loic Coyle <loic.coyle@hotmail.fr>
Control your scripts over the network.

thqm generates a web page menu from standard input and outputs client selections to standard output.

See https://github.com/loiccoyle/thqm.rs/tree/main/examples for full scripts.

Basic usage:
$ echo 'Option 1\nOption 2' | thqm -U |
    while IFS= read -r sel; do
      case $sel in
      'Option 1') echo 'hello';;
      'Option 2') echo 'world';;
      *) echo "$sel";;
      esac
    done

USAGE:
    thqm [OPTIONS]

OPTIONS:
        --custom-input             Show custom input field.
    -h, --help                     Print help information
        --interface <interface>    Network interface to use to determine ip.
        --list-styles              List available page styles.
        --no-qrcode                Don't show the qrcode on the page.
        --no-shutdown              Don't allow the server to be shutdown from the page.
        --oneshot                  Shutdown server after first selection.
    -p, --port <port>              Set the server's port. [default: 8000]
    -P, --password <password>      Authentication password.
    -q, --show-qrcode              Show the qrcode in terminal.
    -s, --style <style>            Page style. [default: default] [possible values: base, default,
                                   fa-grid]
    -S, --separator <separator>    Entry separator. [default: \n]
        --save-qrcode <path>       Save the qrcode image to file.
    -t, --title <title>            Page title. [default: thqm]
    -u, --username <username>      Authentication username. [default: thqm]
    -U, --show-url                 Show the page url.
    -V, --version                  Print version information

脚本

thqm 将根据提供的 stdin 生成网页,所选条目将被打印到 stdout

为了使此行为真正有用,我们需要进行一些脚本编写。

一个典型的脚本看起来可能如下所示

#!/bin/sh

# define the handler function, i.e. what each option should do.
handler() {
  while IFS= read -r event; do
    case "$event" in
    "Option 1")
      # handle Option 1
      ;;
    "Option 2")
      # handle Option 2
      ;;
    *)
      # pass through
      echo "$event"
      ;;
    esac
  done
}

printf "Option 1\nOption 2" | thqm "$@" | handler
# ^                                 ^      ^ Pass user selections to the handler
# │                                 └ Forward script's options to thqm
# └ Provide the options to thqm through stdin

请参阅 示例脚本文件夹 中的示例脚本。

🎨 样式

thqm 内置了一些菜单样式,请参阅 styles 文件夹,它们将在 $XDG_DATA_DIR/thqm 中提取,当 thqm 首次运行时。

您可以遵循已包含的样式结构添加自己的样式。

注意:thqm 使用 tera 模板生成菜单。

依赖项

~26–42MB
~506K SLoC