From b249464549f5b97a1ac4983ef40ecc7245b53f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Wed, 14 Jan 2026 22:10:16 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat:=20=E6=B7=BB=E5=8A=A0=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 Linux、macOS 和 Windows 脚本中添加了终端窗口大小调整功能, 将窗口尺寸设置为 1024x768 以提供更好的用户体验。该功能会在脚本 启动时自动执行,并在不支持或调整失败时静默忽略,不影响主流程。 支持多种终端类型,包括 xterm、tmux、screen、iTerm2、Windows Terminal 等,并针对不同环境使用相应的调整方式。 ``` --- scripts/run/cursor_linux_id_modifier.sh | 40 ++++++++++++++++++++ scripts/run/cursor_mac_id_modifier.sh | 40 ++++++++++++++++++++ scripts/run/cursor_win_id_modifier.ps1 | 50 +++++++++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/scripts/run/cursor_linux_id_modifier.sh b/scripts/run/cursor_linux_id_modifier.sh index eff69aa..503a601 100755 --- a/scripts/run/cursor_linux_id_modifier.sh +++ b/scripts/run/cursor_linux_id_modifier.sh @@ -19,6 +19,43 @@ YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# 启动时尝试调整终端窗口大小为 1024x768(列x行);不支持/失败时静默忽略,避免影响脚本主流程 +try_resize_terminal_window() { + local target_cols=1024 + local target_rows=768 + + # 仅在交互终端中尝试,避免输出被重定向时出现乱码 + if [ ! -t 1 ]; then + return 0 + fi + + case "${TERM:-}" in + ""|dumb) + return 0 + ;; + esac + + # 终端类型检测:仅对常见 xterm 体系终端尝试窗口调整(GNOME Terminal/Konsole/xterm/Terminator 等通常为 xterm*) + case "${TERM:-}" in + xterm*|screen*|tmux*|rxvt*|alacritty*|kitty*|foot*|wezterm*) + ;; + *) + return 0 + ;; + esac + + # 优先通过 xterm 窗口控制序列调整;在 tmux/screen 下需要 passthrough 包装 + if [ -n "${TMUX:-}" ]; then + printf '\033Ptmux;\033\033[8;%d;%dt\033\\' "$target_rows" "$target_cols" 2>/dev/null || true + elif [ -n "${STY:-}" ]; then + printf '\033P\033[8;%d;%dt\033\\' "$target_rows" "$target_cols" 2>/dev/null || true + else + printf '\033[8;%d;%dt' "$target_rows" "$target_cols" 2>/dev/null || true + fi + + return 0 +} + # 日志函数 - 同时输出到终端和日志文件 log_info() { echo -e "${GREEN}[INFO]${NC} $1" @@ -1687,6 +1724,9 @@ cursor_initialize_cleanup() { # 主函数 main() { + # 在显示菜单/流程说明前调整终端窗口大小;不支持则静默忽略 + try_resize_terminal_window + # 初始化日志文件 initialize_log log_info "脚本启动..." diff --git a/scripts/run/cursor_mac_id_modifier.sh b/scripts/run/cursor_mac_id_modifier.sh index 2d54e07..73d97dc 100644 --- a/scripts/run/cursor_mac_id_modifier.sh +++ b/scripts/run/cursor_mac_id_modifier.sh @@ -37,6 +37,43 @@ YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# 启动时尝试调整终端窗口大小为 1024x768(列x行);不支持/失败时静默忽略,避免影响脚本主流程 +try_resize_terminal_window() { + local target_cols=1024 + local target_rows=768 + + # 仅在交互终端中尝试,避免输出被重定向时出现乱码 + if [ ! -t 1 ]; then + return 0 + fi + + case "${TERM:-}" in + ""|dumb) + return 0 + ;; + esac + + # 终端类型检测:仅对常见 xterm 体系终端尝试窗口调整(Terminal.app/iTerm2 以及常见终端通常为 xterm*) + case "${TERM:-}" in + xterm*|screen*|tmux*|rxvt*|alacritty*|kitty*|foot*|wezterm*) + ;; + *) + return 0 + ;; + esac + + # 优先通过 xterm 窗口控制序列调整;在 tmux/screen 下需要 passthrough 包装 + if [ -n "${TMUX:-}" ]; then + printf '\033Ptmux;\033\033[8;%d;%dt\033\\' "$target_rows" "$target_cols" 2>/dev/null || true + elif [ -n "${STY:-}" ]; then + printf '\033P\033[8;%d;%dt\033\\' "$target_rows" "$target_cols" 2>/dev/null || true + else + printf '\033[8;%d;%dt' "$target_rows" "$target_cols" 2>/dev/null || true + fi + + return 0 +} + # 日志函数 - 同时输出到终端和日志文件 log_info() { echo -e "${GREEN}[INFO]${NC} $1" @@ -2925,6 +2962,9 @@ select_menu_option() { # 主函数 main() { + # 在显示菜单/流程说明前调整终端窗口大小;不支持则静默忽略 + try_resize_terminal_window + # 初始化日志文件 initialize_log log_info "脚本启动..." diff --git a/scripts/run/cursor_win_id_modifier.ps1 b/scripts/run/cursor_win_id_modifier.ps1 index e5b276d..acc0120 100644 --- a/scripts/run/cursor_win_id_modifier.ps1 +++ b/scripts/run/cursor_win_id_modifier.ps1 @@ -10,6 +10,56 @@ $YELLOW = "$ESC[33m" $BLUE = "$ESC[34m" $NC = "$ESC[0m" +# 启动时尝试调整终端窗口大小为 1024x768(列x行);不支持/失败时静默忽略,避免影响脚本主流程 +function Try-ResizeTerminalWindow { + param( + [int]$Columns = 1024, + [int]$Rows = 768 + ) + + # 方式1:通过 PowerShell Host RawUI 调整(传统控制台、ConEmu 等可能支持) + try { + $rawUi = $null + if ($Host -and $Host.UI -and $Host.UI.RawUI) { + $rawUi = $Host.UI.RawUI + } + + if ($rawUi) { + try { + # BufferSize 必须 >= WindowSize,否则会抛异常 + $bufferSize = $rawUi.BufferSize + $newBufferSize = New-Object System.Management.Automation.Host.Size ( + ([Math]::Max($bufferSize.Width, $Columns)), + ([Math]::Max($bufferSize.Height, $Rows)) + ) + $rawUi.BufferSize = $newBufferSize + } catch { + # 静默忽略 + } + + try { + $rawUi.WindowSize = New-Object System.Management.Automation.Host.Size ($Columns, $Rows) + } catch { + # 静默忽略 + } + } + } catch { + # 静默忽略 + } + + # 方式2:通过 ANSI 转义序列再尝试一次(Windows Terminal 等可能支持) + try { + if (-not [Console]::IsOutputRedirected) { + $escChar = [char]27 + [Console]::Out.Write("$escChar[8;${Rows};${Columns}t") + } + } catch { + # 静默忽略 + } +} + +Try-ResizeTerminalWindow -Columns 1024 -Rows 768 + # 路径解析:优先使用 .NET 获取系统目录,避免环境变量缺失导致路径异常 function Get-FolderPathSafe { param(