Skip to content

Commit ee0f8d1

Browse files
author
Xiang Li
committed
feat(tui): add optional interactive dashboard
1 parent 25bdb43 commit ee0f8d1

3 files changed

Lines changed: 1425 additions & 0 deletions

File tree

scripts/core/clashctl.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source "$PROJECT_DIR/scripts/core/runtime.sh"
99
source "$PROJECT_DIR/scripts/core/config.sh"
1010
source "$PROJECT_DIR/scripts/core/proxy.sh"
1111
source "$PROJECT_DIR/scripts/core/update.sh"
12+
source "$PROJECT_DIR/scripts/core/tui.sh"
1213
source "$PROJECT_DIR/scripts/init/systemd.sh"
1314
source "$PROJECT_DIR/scripts/init/systemd-user.sh"
1415
source "$PROJECT_DIR/scripts/init/script.sh"
@@ -33,6 +34,7 @@ Usage:
3334
ls 📡 查看订阅列表
3435
3536
🕹️ Control:
37+
tui 🖥️ TUI 交互式控制台(需要 gum)
3638
clashui 🕹️ 查看 Web 控制台
3739
secret 🔑 查看或设置 Web 密钥
3840
clashsecret 🔑 查看或设置 Web 密钥
@@ -7196,6 +7198,7 @@ case "$cmd" in
71967198
proxy) cmd_proxy "$@" ;;
71977199
upgrade) cmd_upgrade "$@" ;;
71987200
update) cmd_update "$@" ;;
7201+
tui) cmd_tui "$@" ;;
71997202
start-direct) cmd_start_direct "$@" ;;
72007203
stop-direct) cmd_stop_direct "$@" ;;
72017204
restart-direct) cmd_restart_direct "$@" ;;

scripts/core/proxy.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,53 @@ print_proxy_groups_summary() {
757757
done < <(proxy_group_list)
758758
}
759759

760+
clash_mode_get() {
761+
controller_curl GET "/configs" 2>/dev/null \
762+
| "$(yq_bin)" -p=json eval '.mode // "rule"' - 2>/dev/null \
763+
| head -n 1
764+
}
765+
766+
clash_mode_set() {
767+
local mode="$1"
768+
769+
case "$mode" in
770+
global|rule|direct) ;;
771+
*) die "不支持的代理模式:$mode(只允许 global / rule / direct)" ;;
772+
esac
773+
774+
controller_curl PATCH "/configs" "{\"mode\":\"$mode\"}" >/dev/null
775+
}
776+
777+
connections_json() {
778+
controller_curl GET "/connections"
779+
}
780+
781+
connections_count() {
782+
connections_json 2>/dev/null \
783+
| "$(yq_bin)" -p=json eval '.connections | length' - 2>/dev/null \
784+
| head -n 1 \
785+
|| echo "0"
786+
}
787+
788+
connections_format_rows() {
789+
local limit="${1:-100}"
790+
791+
connections_json 2>/dev/null \
792+
| "$(yq_bin)" -p=json eval "
793+
.connections[0:${limit}][] |
794+
[
795+
((.metadata.host // .metadata.destinationIP // \"-\") | .[0:36]),
796+
((.metadata.type // .metadata.network // \"-\")),
797+
((.chains // []) | reverse | join(\"\") | .[0:28]),
798+
(.rule // \"-\"),
799+
(
800+
(((.download // 0) / 1024 | tostring | split(\".\")[0]) + \"K↓\") + \" \" +
801+
(((.upload // 0) / 1024 | tostring | split(\".\")[0]) + \"K↑\")
802+
)
803+
] | join(\"\t\")
804+
" - 2>/dev/null
805+
}
806+
760807
proxy_node_test_delay() {
761808
local node="$1"
762809
local url="${2:-http://www.gstatic.com/generate_204}"

0 commit comments

Comments
 (0)