Skip to content

Commit 26e1dea

Browse files
authored
Merge pull request #233 from wnlen/dev
fix(ui): restore utf-8 encoding and remove mojibake in select output
2 parents 5162269 + 659ac55 commit 26e1dea

7 files changed

Lines changed: 119 additions & 57 deletions

File tree

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
8+
[*.{sh,yaml,yml,env,md}]
9+
charset = utf-8

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*.sh text eol=lf
1+
*.sh text eol=lf working-tree-encoding=UTF-8
22
*.yaml text eol=lf
33
*.yml text eol=lf
44
*.env text eol=lf
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
export LANG=C.UTF-8
5+
export LC_ALL=C.UTF-8
6+
7+
if grep -R -n '馃\|鑺\|绛\|閫\|璇\|摝\|殌' scripts/; then
8+
echo "Detected mojibake text in scripts/" >&2
9+
exit 1
10+
fi
11+
12+
python3 - <<'PY'
13+
from pathlib import Path
14+
import sys
15+
16+
bad = []
17+
for path in Path("scripts").rglob("*.sh"):
18+
data = path.read_bytes()
19+
if data.startswith(b"\xef\xbb\xbf"):
20+
bad.append(f"{path}: UTF-8 BOM is not allowed")
21+
continue
22+
try:
23+
data.decode("utf-8")
24+
except UnicodeDecodeError as exc:
25+
bad.append(f"{path}: invalid UTF-8 ({exc})")
26+
27+
if bad:
28+
print("\n".join(bad), file=sys.stderr)
29+
sys.exit(1)
30+
PY
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Text Encoding
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
utf8:
12+
runs-on: ubuntu-latest
13+
env:
14+
LANG: C.UTF-8
15+
LC_ALL: C.UTF-8
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Check mojibake and UTF-8 encoding
19+
run: bash .github/scripts/check-text-encoding.sh

scripts/core/clashctl.sh

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6962,13 +6962,13 @@ print_select_feedback() {
69626962

69636963
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
69646964

6965-
ui_title "馃殌 鑺傜偣鍒囨崲瀹屾垚"
6965+
ui_title "🚀 节点切换完成"
69666966

69676967
if [ -n "${group:-}" ]; then
6968-
ui_kv "馃摝" "宸插垏鎹㈢瓥鐣ョ粍" "$group"
6968+
ui_kv "📦" "已切换策略组" "$group"
69696969
fi
69706970

6971-
ui_kv "馃殌" "褰撳墠鑺傜偣" "${current:-<unknown>}"
6971+
ui_kv "🚀" "当前节点" "${current:-<unknown>}"
69726972

69736973
main_feedback_runtime_state
69746974
ui_next "clashctl status"
@@ -6986,12 +6986,12 @@ status_current_proxy_brief() {
69866986
return 0
69876987
fi
69886988

6989-
echo "鏈惎鍔?"
6989+
echo "未启动"
69906990
return 0
69916991
fi
69926992

69936993
if ! proxy_controller_reachable 2>/dev/null; then
6994-
echo "鎺у埗鍣ㄤ笉鍙闂?"
6994+
echo "控制器不可访问"
69956995
return 0
69966996
fi
69976997

@@ -7009,7 +7009,7 @@ status_current_proxy_brief() {
70097009
return 0
70107010
fi
70117011

7012-
echo "鏆傛棤鍙垏鎹㈢瓥鐣ョ粍"
7012+
echo "暂无可切换策略组"
70137013
}
70147014

70157015
cmd_proxy_groups() {
@@ -7018,25 +7018,25 @@ cmd_proxy_groups() {
70187018
prepare
70197019

70207020
if ! status_is_running; then
7021-
die_state "浠g悊鍐呮牳鏈繍琛?" "clashon"
7021+
die_state "代理内核未运行" "clashon"
70227022
fi
70237023

70247024
if ! proxy_controller_reachable 2>/dev/null; then
7025-
die_state "鎺у埗鍣ㄤ笉鍙闂?" "clashctl doctor"
7025+
die_state "控制器不可访问" "clashctl doctor"
70267026
fi
70277027

7028-
ui_title "馃摝 绛栫暐缁勫垪琛?"
7029-
echo " 馃摝 鍚嶇О 绫诲瀷 褰撳墠鑺傜偣"
7028+
ui_title "📦 策略组列表"
7029+
echo " 📦 名称 类型 当前节点"
70307030
while IFS= read -r group; do
70317031
[ -n "${group:-}" ] || continue
70327032
found="true"
70337033
type="$(proxy_group_type "$group" 2>/dev/null || echo "unknown")"
70347034
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
7035-
printf ' 馃摝 %-20s %-12s %s\n' "$group" "$type" "${current:-<unknown>}"
7035+
printf ' 📦 %-20s %-12s %s\n' "$group" "$type" "${current:-<unknown>}"
70367036
done < <(proxy_group_list)
70377037

70387038
if [ "$found" != "true" ]; then
7039-
echo " 馃摥 鏆傛棤鍙垏鎹㈢瓥鐣ョ粍"
7039+
echo " 📭 暂无可切换策略组"
70407040
fi
70417041

70427042
ui_blank
@@ -7050,33 +7050,33 @@ cmd_proxy_current() {
70507050
prepare
70517051

70527052
if ! status_is_running; then
7053-
die_state "浠g悊鍐呮牳鏈繍琛?" "clashon"
7053+
die_state "代理内核未运行" "clashon"
70547054
fi
70557055

70567056
if ! proxy_controller_reachable 2>/dev/null; then
7057-
die_state "鎺у埗鍣ㄤ笉鍙闂?" "clashctl doctor"
7057+
die_state "控制器不可访问" "clashctl doctor"
70587058
fi
70597059

70607060
if [ -n "${1:-}" ]; then
70617061
group="$1"
70627062
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
7063-
ui_title "馃殌 褰撳墠鑺傜偣"
7064-
ui_kv "馃摝" "绛栫暐缁?" "$group"
7065-
ui_kv "馃殌" "褰撳墠鑺傜偣" "${current:-<unknown>}"
7063+
ui_title "🚀 当前节点"
7064+
ui_kv "📦" "策略组" "$group"
7065+
ui_kv "🚀" "当前节点" "${current:-<unknown>}"
70667066
ui_blank
70677067
return 0
70687068
fi
70697069

7070-
ui_title "馃殌 褰撳墠鑺傜偣鎬昏"
7070+
ui_title "🚀 当前节点总览"
70717071
while IFS= read -r group; do
70727072
[ -n "${group:-}" ] || continue
70737073
found="true"
70747074
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
7075-
printf ' 馃殌 %-20s %s\n' "$group" "${current:-<unknown>}"
7075+
printf ' 🚀 %-20s %s\n' "$group" "${current:-<unknown>}"
70767076
done < <(proxy_group_list)
70777077

70787078
if [ "$found" != "true" ]; then
7079-
echo " 馃摥 鏆傛棤鍙垏鎹㈢瓥鐣ョ粍"
7079+
echo " 📭 暂无可切换策略组"
70807080
fi
70817081

70827082
ui_blank
@@ -7087,35 +7087,35 @@ cmd_proxy_nodes() {
70877087
local current node found="false"
70887088

70897089
prepare
7090-
[ -n "${group:-}" ] || die "璇蜂娇鐢?clashctl select 鍒囨崲鑺傜偣"
7090+
[ -n "${group:-}" ] || die "请使用 clashctl select 切换节点"
70917091

70927092
if ! status_is_running; then
7093-
die_state "浠g悊鍐呮牳鏈繍琛?" "clashon"
7093+
die_state "代理内核未运行" "clashon"
70947094
fi
70957095

70967096
if ! proxy_controller_reachable 2>/dev/null; then
7097-
die_state "鎺у埗鍣ㄤ笉鍙闂?" "clashctl doctor"
7097+
die_state "控制器不可访问" "clashctl doctor"
70987098
fi
70997099

71007100
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
71017101

7102-
ui_title "馃殌 鍊欓€夎妭鐐瑰垪琛?"
7103-
ui_kv "馃摝" "绛栫暐缁?" "$group"
7104-
ui_kv "馃殌" "褰撳墠鑺傜偣" "${current:-<unknown>}"
7102+
ui_title "🚀 候选节点列表"
7103+
ui_kv "📦" "策略组" "$group"
7104+
ui_kv "🚀" "当前节点" "${current:-<unknown>}"
71057105
ui_blank
71067106

71077107
while IFS= read -r node; do
71087108
[ -n "${node:-}" ] || continue
71097109
found="true"
71107110
if [ "$node" = "$current" ]; then
7111-
printf ' * 馃殌 %s\n' "$node"
7111+
printf ' * 🚀 %s\n' "$node"
71127112
else
7113-
printf ' 馃殌 %s\n' "$node"
7113+
printf ' 🚀 %s\n' "$node"
71147114
fi
71157115
done < <(proxy_group_selectable_nodes "$group")
71167116

71177117
if [ "$found" != "true" ]; then
7118-
echo " 馃摥 该策略组暂无可切换真实节点"
7118+
echo " 📭 该策略组暂无可切换真实节点"
71197119
fi
71207120

71217121
ui_blank
@@ -7133,15 +7133,15 @@ proxy_pick_group_for_select() {
71337133
groups+=("$group")
71347134
done < <(proxy_group_display_list)
71357135

7136-
for group in "鑺傜偣閫夋嫨" "鑷姩閫夋嫨"; do
7136+
for group in "节点选择" "自动选择"; do
71377137
if printf '%s\n' "${groups[@]}" | grep -Fxq "$group"; then
71387138
ordered_groups+=("$group")
71397139
fi
71407140
done
71417141

71427142
for group in "${groups[@]}"; do
71437143
case "$group" in
7144-
鑺傜偣閫夋嫨|鑷姩閫夋嫨)
7144+
节点选择|自动选择)
71457145
continue
71467146
;;
71477147
esac
@@ -7151,18 +7151,18 @@ proxy_pick_group_for_select() {
71517151
groups=("${ordered_groups[@]}")
71527152

71537153
count="${#groups[@]}"
7154-
[ "$count" -gt 0 ] || die "馃摥 鏆傛棤鍙垏鎹㈢瓥鐣ョ粍"
7154+
[ "$count" -gt 0 ] || die "📭 暂无可切换策略组"
71557155

7156-
echo "馃摝 璇烽€夋嫨绛栫暐缁勶細" >&2
7157-
echo "馃挕 閫氬父浼樺厛閫夋嫨锛氳妭鐐归€夋嫨" >&2
7156+
echo "📦 请选择策略组:" >&2
7157+
echo "💡 通常优先选择:节点选择" >&2
71587158
idx=1
71597159
for group in "${groups[@]}"; do
71607160
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
71617161
type="$(proxy_group_type_label "$group" 2>/dev/null || echo "unknown")"
7162-
printf ' %s) 馃摝 %s [%s] -> 馃殌 %s\n' "$idx" "$group" "$type" "${current:-<unknown>}" >&2
7162+
printf ' %s) 📦 %s [%s] -> 🚀 %s\n' "$idx" "$group" "$type" "${current:-<unknown>}" >&2
71637163
idx=$((idx + 1))
71647164
done
7165-
echo " q) 閫€鍑?" >&2
7165+
echo " q) 退出" >&2
71667166
echo >&2
71677167

71687168
idx="$(proxy_pick_index "$count")" || return 1
@@ -7178,15 +7178,15 @@ proxy_select_interactive_guarded() {
71787178
prepare
71797179

71807180
if ! status_is_running; then
7181-
die_state "浠g悊鍐呮牳鏈繍琛?" "clashon"
7181+
die_state "代理内核未运行" "clashon"
71827182
fi
71837183

71847184
if ! proxy_controller_reachable 2>/dev/null; then
7185-
die_state "鎺у埗鍣ㄤ笉鍙闂?" "clashctl doctor"
7185+
die_state "控制器不可访问" "clashctl doctor"
71867186
fi
71877187

71887188
if [ -z "${group:-}" ]; then
7189-
ui_title "馃殌 鑺傜偣鍒囨崲"
7189+
ui_title "🚀 节点切换"
71907190
choose_group="true"
71917191
fi
71927192

@@ -7195,7 +7195,7 @@ proxy_select_interactive_guarded() {
71957195
group="$(proxy_pick_group_for_select)" || return 0
71967196
fi
71977197

7198-
proxy_group_exists "$group" || die "绛栫暐缁勪笉瀛樺湪锛?group"
7198+
proxy_group_exists "$group" || die "策略组不存在:$group"
71997199

72007200
current="$(proxy_group_current_display "$group" 2>/dev/null || true)"
72017201
nodes=()
@@ -7207,8 +7207,8 @@ proxy_select_interactive_guarded() {
72077207
count="${#nodes[@]}"
72087208
if [ "$count" -le 0 ]; then
72097209
ui_warn "该策略组暂无可切换真实节点"
7210-
ui_kv "馃摝" "绛栫暐缁?" "$group"
7211-
ui_kv "馃殌" "褰撳墠鑺傜偣" "${current:-<unknown>}"
7210+
ui_kv "📦" "策略组" "$group"
7211+
ui_kv "🚀" "当前节点" "${current:-<unknown>}"
72127212
ui_blank
72137213
if [ "$choose_group" = "true" ]; then
72147214
group=""
@@ -7220,25 +7220,25 @@ proxy_select_interactive_guarded() {
72207220
total_count="$(select_total_node_count 2>/dev/null || true)"
72217221

72227222
echo
7223-
echo "馃摝 褰撳墠绛栫暐缁勶細$group"
7224-
echo "馃殌 褰撳墠鑺傜偣锛?${current:-<unknown>}"
7225-
echo "馃摝 褰撳墠绛栫暐缁勫€欓€夋暟锛?count"
7226-
[ -n "${total_count:-}" ] && echo "馃敘 鍏ㄩ儴鑺傜偣鎬绘暟锛?total_count"
7227-
echo "鈩癸笍 浠ヤ笅浠呮樉绀哄綋鍓嶇瓥鐣ョ粍鍙垏鎹㈣妭鐐?"
7223+
echo "📦 当前策略组:$group"
7224+
echo "🚀 当前节点:${current:-<unknown>}"
7225+
echo "📦 当前策略组候选数:$count"
7226+
[ -n "${total_count:-}" ] && echo "🔢 全部节点总数:$total_count"
7227+
echo "ℹ️ 以下仅显示当前策略组可切换节点"
72287228
echo
7229-
echo "馃殌 璇烽€夋嫨鑺傜偣锛?"
7229+
echo "🚀 请选择节点:"
72307230

72317231
idx=1
72327232
for node in "${nodes[@]}"; do
72337233
if [ "$node" = "$current" ]; then
7234-
printf ' %s) 馃殌 %s [褰撳墠]\n' "$idx" "$node"
7234+
printf ' %s) 🚀 %s [当前]\n' "$idx" "$node"
72357235
else
7236-
printf ' %s) 馃殌 %s\n' "$idx" "$node"
7236+
printf ' %s) 🚀 %s\n' "$idx" "$node"
72377237
fi
72387238
idx=$((idx + 1))
72397239
done
72407240

7241-
echo " q) 閫€鍑?"
7241+
echo " q) 退出"
72427242
echo
72437243

72447244
idx="$(proxy_pick_index "$count")" || return 0

scripts/core/proxy.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,10 @@ proxy_group_select() {
849849
local code response_file response_body
850850
local available_node found
851851

852-
[ -n "${group:-}" ] || die "绛栫暐缁勫悕绉颁笉鑳戒负绌?"
853-
[ -n "${node:-}" ] || die "鑺傜偣鍚嶇О涓嶈兘涓虹┖"
852+
[ -n "${group:-}" ] || die "策略组名称不能为空"
853+
[ -n "${node:-}" ] || die "节点名称不能为空"
854854

855-
proxy_group_exists "$group" || die "绛栫暐缁勪笉瀛樺湪锛?group"
855+
proxy_group_exists "$group" || die "策略组不存在:$group"
856856
proxy_group_can_show_candidates "$group" || die "$(proxy_group_manual_pick_error_message "$group")"
857857
proxy_node_is_selectable_candidate "$node" || die "节点不是可切换节点:$node"
858858

@@ -866,7 +866,7 @@ proxy_group_select() {
866866
done < <(proxy_group_selectable_nodes "$group")
867867

868868
if [ "$found" != "true" ]; then
869-
die "鑺傜偣涓嶅瓨鍦ㄤ簬绛栫暐缁勪腑锛?group -> $node"
869+
die "节点不存在于策略组中:$group -> $node"
870870
fi
871871

872872
base="$(controller_api_base)"
@@ -886,7 +886,7 @@ proxy_group_select() {
886886
if [ -n "${response_body:-}" ]; then
887887
die "controller 原始错误:$response_body"
888888
fi
889-
die "鑺傜偣鍒囨崲澶辫触锛歝ontroller 杩斿洖 HTTP $code"
889+
die "节点切换失败:controller 返回 HTTP $code"
890890
fi
891891

892892
rm -f "$response_file" 2>/dev/null || true

scripts/dev/check-text-encoding.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
exec bash .github/scripts/check-text-encoding.sh "$@"

0 commit comments

Comments
 (0)