@x-all-in-one/coding-helper 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ {
2
+ "cli": {
3
+ "title": "Coding Tool Helper (chelper)",
4
+ "usage": "Usage: chelper <command> [options]",
5
+ "commands": "Commands:",
6
+ "examples": "Examples:",
7
+ "error_unknown": "Unknown command: {{command}}",
8
+ "error_general": "Error:"
9
+ },
10
+ "commands": {
11
+ "help": "Show help information",
12
+ "version": "Show version information",
13
+ "init": "Run interactive initialization wizard",
14
+ "lang": "Language management",
15
+ "auth": "API key management",
16
+ "doctor": "Health check",
17
+ "enter": "Configuration management",
18
+ "tool": "Tool management"
19
+ },
20
+ "lang": {
21
+ "current": "Current language",
22
+ "show_usage": "chelper lang show - Show current language",
23
+ "set_usage": "chelper lang set <zh_CN|en_US> - Set language",
24
+ "changed": "Language changed from {{from}} to {{to}}",
25
+ "invalid": "Unsupported language: {{lang}}",
26
+ "available": "Available languages"
27
+ },
28
+ "auth": {
29
+ "set_usage": "chelper auth <service> <token> - Set API key",
30
+ "service_prompt": "Select service type",
31
+ "token_prompt": "Enter API key",
32
+ "token_required": "API key cannot be empty",
33
+ "saved": "API key saved",
34
+ "revoke_confirm": "Are you sure you want to revoke the API key?",
35
+ "revoked": "API key revoked",
36
+ "not_revoked": "Revoke operation cancelled",
37
+ "get_api_key_hint": "To obtain API Key, please visit: {{url}}",
38
+ "reload_usage": "chelper auth reload <tool> - Reload configuration to the tool",
39
+ "reloading": "Reloading configuration to {{tool}}...",
40
+ "reloaded": "Configuration reloaded to {{tool}} successfully",
41
+ "reload_failed": "Failed to reload configuration",
42
+ "reload_missing_config": "Missing API key configuration. Please run 'chelper auth' first.",
43
+ "reload_tool_not_supported": "Tool '{{tool}}' is not supported for reload"
44
+ },
45
+ "wizard": {
46
+ "banner_subtitle": "Manage Your Claude Code and Other Coding Tools",
47
+ "welcome": "Welcome to Coding Tool Helper!",
48
+ "privacy_note": "We value your privacy. All configurations are stored locally only.",
49
+ "select_language": "Select interface language",
50
+ "input_api_key": "Enter API key",
51
+ "input_your_api_key": "Please input your API key here, Enter to confirm:",
52
+ "update_api_key": "Update API key",
53
+ "api_key_required": "API key cannot be empty",
54
+ "select_tool": "Select coding tool to configure",
55
+ "tool_not_installed": "{{tool}} is not installed",
56
+ "install_tool_confirm": "Install now?",
57
+ "installing_tool": "Installing tool...",
58
+ "tool_installed": "Tool installed successfully",
59
+ "install_failed": "Installation failed",
60
+ "install_skipped": "Installation skipped. You can install manually later.",
61
+ "menu_title": "Management Menu",
62
+ "select_action": "Select action",
63
+ "action_load_config": "Apply Configuration - (Apply your configuration to {{tool}})",
64
+ "action_unload_config": "Unload Configuration - (Remove configuration from {{tool}})",
65
+ "action_view_config": "Current Configuration",
66
+ "action_back": "Back",
67
+ "action_exit": "Exit",
68
+ "goodbye": "Goodbye!",
69
+ "loading_config": "Loading configuration...",
70
+ "config_loaded": "Configuration loaded successfully, you can now use {{tool}} for coding.",
71
+ "config_load_failed": "Failed to load configuration",
72
+ "confirm_unload_config": "Are you sure you want to unload configuration from {{tool}}?",
73
+ "unloading_config": "Unloading configuration...",
74
+ "config_unloaded": "Configuration unloaded successfully",
75
+ "config_unload_failed": "Failed to unload configuration",
76
+ "tool_not_supported": "This operation is not supported for this tool",
77
+ "missing_config": "Missing required configuration (API key or models)",
78
+ "installed": "Installed",
79
+ "not_installed": "Not installed",
80
+ "action_install": "Install",
81
+ "action_uninstall": "Uninstall",
82
+ "current_config": "Current Configuration",
83
+ "config_language": "Interface Language",
84
+ "config_api_key": "API Key",
85
+ "config_title": "Configuration",
86
+ "not_set": "Not set",
87
+ "press_enter": "Press Enter to continue",
88
+ "main_menu_title": "Main Menu",
89
+ "current_config_status": "Current Configuration Status:",
90
+ "api_key_set": "Set",
91
+ "api_key_get_hint": "To obtain API Key, please visit: {{url}}",
92
+ "menu_config_language": "Interface language",
93
+ "menu_config_api_key": "Configure API Key",
94
+ "menu_config_models": "Configure Models",
95
+ "menu_config_tool": "Configure Coding Tool",
96
+ "menu_exit": "Exit",
97
+ "select_operation": "Select operation:",
98
+ "goodbye_message": "Goodbye!",
99
+ "nav_return": "Return",
100
+ "nav_exit": "Exit",
101
+ "current_active": "Current",
102
+ "operation_hint": "Operation Hint",
103
+ "hint_navigate": "↑↓ Navigate",
104
+ "hint_confirm": "Enter Confirm",
105
+ "detected_config_title": "Claude Code Current Configuration",
106
+ "chelper_config_title": "Chelper Configuration",
107
+ "claude_code_config_title": "Claude Code Current Global Configuration",
108
+ "config_synced": "Configuration synchronized",
109
+ "config_out_of_sync": "Configuration out of sync, refresh recommended",
110
+ "config_not_loaded": "Claude Code configuration not loaded yet",
111
+ "action_refresh_config": "Configuration Refresh - (Update {{tool}}'s configuration)",
112
+ "global_config_warning": "⚠️ Warning: You are modifying the {{tool}} global configuration. Changes will affect all workspaces",
113
+ "global_label": "GLOBAL",
114
+ "set_success": "Set successfully",
115
+ "start_tool": "Start {{tool}} - (Recommendation: open a new terminal in your workspace and run {{shell}} to start it)",
116
+ "starting_tool": "Starting...",
117
+ "validating_api_key": "Validating API Key...",
118
+ "api_key_valid": "API Key is valid",
119
+ "api_key_invalid": "API Key is invalid or expired",
120
+ "api_key_network_error": "Network error, please check your connection",
121
+ "select_models": "Select Models",
122
+ "configure_models": "Configure Model Selection",
123
+ "select_haiku_model": "Select Haiku Model (Fast/Small)",
124
+ "select_sonnet_model": "Select Sonnet Model (Default)",
125
+ "select_opus_model": "Select Opus Model (Large/Powerful)",
126
+ "current_haiku_model": "Haiku Model",
127
+ "current_sonnet_model": "Sonnet Model",
128
+ "current_opus_model": "Opus Model",
129
+ "fetching_models": "Fetching available models...",
130
+ "fetch_models_failed": "Failed to fetch models, using defaults",
131
+ "saving_model_config": "Saving model configuration...",
132
+ "model_config_saved": "Model configuration saved successfully",
133
+ "model_config_failed": "Failed to save model configuration",
134
+ "no_models_available": "No models available. Please configure API Key first.",
135
+ "models_config_title": "Models Configuration"
136
+ },
137
+ "doctor": {
138
+ "checking": "Running health check...",
139
+ "check_path": "Checking PATH environment variable",
140
+ "check_api_key_network": "Checking API Key & Network",
141
+ "check_api_key": "Checking API key",
142
+ "check_tools": "Checking installed tools",
143
+ "check_config": "Checking configuration",
144
+ "all_good": "All checks passed!",
145
+ "tool_installed": "Installed",
146
+ "tool_not_found": "Tool not found: {{tool}}",
147
+ "network_error": "Network connection failed",
148
+ "api_key_invalid": "API Key is invalid or expired",
149
+ "api_key_network_ok": "API Key & Network verified",
150
+ "api_key_missing": "API key not configured",
151
+ "claude_code_installed": "Claude Code is installed",
152
+ "claude_code_not_installed": "Claude Code is not installed. Please install it from https://claude.ai/download",
153
+ "config_configured": "Configuration complete",
154
+ "config_not_configured": "Configuration incomplete. Run 'chelper init' to configure.",
155
+ "suggestions": "Suggestions",
156
+ "check_git_env": "Check Git environment",
157
+ "git_not_installed": "Git is not installed. Please install Git from https://git-scm.com/downloads"
158
+ },
159
+ "messages": {
160
+ "initializing": "Initializing...",
161
+ "args": "Args:",
162
+ "first_run": "First run detected. Starting initialization wizard...",
163
+ "config_saved": "Configuration saved"
164
+ },
165
+ "install": {
166
+ "permission_detected": "Permission issue detected, attempting to resolve...",
167
+ "trying_solution": "Trying solution {{num}}: {{desc}}...",
168
+ "permission_fixed": "Permission issue resolved!",
169
+ "auto_fix_failed": "Auto-fix failed.",
170
+ "windows_solutions": "Windows users, please try one of the following solutions:",
171
+ "windows_solution_1_title": "Solution 1 (Recommended): Run as Administrator",
172
+ "windows_solution_1_step1": "1. Right-click Command Prompt or PowerShell",
173
+ "windows_solution_1_step2": "2. Select \"Run as administrator\"",
174
+ "windows_solution_1_step3": "3. Re-run the installation command",
175
+ "windows_solution_2_title": "Solution 2: Use user-level installation (no admin required)",
176
+ "windows_solution_2_command": "Run in command line:",
177
+ "unix_solutions": "Please manually try one of the following solutions:",
178
+ "unix_solution_1_title": "Solution 1: Install with sudo",
179
+ "unix_solution_1_desc": "Run the following command in terminal (requires admin password):",
180
+ "unix_solution_2_title": "Solution 2 (Recommended): Use nvm to manage Node.js",
181
+ "unix_solution_2_desc": "Using nvm avoids permission issues and is recommended by npm official",
182
+ "path_warning": "Please add the following path to your PATH environment variable:",
183
+ "path_add_method": "How to add:",
184
+ "all_solutions_failed": "All auto-fix solutions failed.",
185
+ "using_sudo": "Installing with sudo privileges",
186
+ "using_user_install": "Using user-level installation (no sudo required)",
187
+ "using_force": "Retrying with --force flag",
188
+ "npm_docs_link": "npm Official Documentation",
189
+ "what_next": "What would you like to do next?",
190
+ "installed_continue": "✅ I've completed the installation, continue",
191
+ "cancel_install": "❌ Cancel installation",
192
+ "user_cancelled": "User cancelled the installation",
193
+ "still_not_installed": "{{tool}} still does not appear to be installed",
194
+ "install_failed_detail": "Installation failed with error:",
195
+ "skip_install_confirm": "Skip the installation and install manually?",
196
+ "skip_install_yes": "Skip, I will install manually",
197
+ "skip_install_no": "Go back",
198
+ "retry_check": "Would you like to check the installation status again?",
199
+ "verified_success": "{{tool}} installation verified successfully!"
200
+ }
201
+ }
@@ -0,0 +1,201 @@
1
+ {
2
+ "cli": {
3
+ "title": "Coding Tool Helper (chelper)",
4
+ "usage": "用法: chelper <命令> [选项]",
5
+ "commands": "命令:",
6
+ "examples": "示例:",
7
+ "error_unknown": "未知命令: {{command}}",
8
+ "error_general": "错误:"
9
+ },
10
+ "commands": {
11
+ "help": "显示帮助信息",
12
+ "version": "显示版本信息",
13
+ "init": "运行交互式初始化向导",
14
+ "lang": "语言管理",
15
+ "auth": "密钥管理",
16
+ "doctor": "健康检查",
17
+ "enter": "配置管理",
18
+ "tool": "工具管理"
19
+ },
20
+ "lang": {
21
+ "current": "当前语言",
22
+ "show_usage": "chelper lang show - 显示当前语言",
23
+ "set_usage": "chelper lang set <zh_CN|en_US> - 设置语言",
24
+ "changed": "语言已从 {{from}} 更改为 {{to}}",
25
+ "invalid": "不支持的语言: {{lang}}",
26
+ "available": "可用语言"
27
+ },
28
+ "auth": {
29
+ "set_usage": "chelper auth <service> <token> - 设置API密钥",
30
+ "service_prompt": "请选择服务类型",
31
+ "token_prompt": "请输入API密钥",
32
+ "token_required": "API密钥不能为空",
33
+ "saved": "API密钥已保存",
34
+ "revoke_confirm": "确认要删除已保存的API密钥吗?",
35
+ "revoked": "API密钥已删除",
36
+ "not_revoked": "取消删除操作",
37
+ "get_api_key_hint": "如需获取 API Key,请访问: {{url}}",
38
+ "reload_usage": "chelper auth reload <tool> - 重新加载配置到工具",
39
+ "reloading": "正在重新加载配置到 {{tool}}...",
40
+ "reloaded": "配置已成功重新加载到 {{tool}}",
41
+ "reload_failed": "重新加载配置失败",
42
+ "reload_missing_config": "缺少 API Key 配置,请先运行 'chelper auth' 进行配置",
43
+ "reload_tool_not_supported": "工具 '{{tool}}' 不支持 reload 操作"
44
+ },
45
+ "wizard": {
46
+ "banner_subtitle": "统一管理您的 Claude Code 等编码工具",
47
+ "welcome": "欢迎使用编码工具助手!",
48
+ "privacy_note": "我们重视您的隐私,所有配置信息仅保存在本地.",
49
+ "select_language": "请选择界面语言",
50
+ "input_api_key": "输入 API Key",
51
+ "input_your_api_key": "请在这里输入您的 API key, 回车键确认:",
52
+ "update_api_key": "更新 API Key",
53
+ "api_key_required": "API密钥不能为空",
54
+ "select_tool": "请选择要配置的编码工具",
55
+ "tool_not_installed": "{{tool}} 尚未安装",
56
+ "install_tool_confirm": "是否现在安装?",
57
+ "installing_tool": "正在安装工具...",
58
+ "tool_installed": "工具安装成功",
59
+ "install_failed": "安装失败",
60
+ "install_skipped": "已跳过安装,您可以稍后手动安装",
61
+ "menu_title": "管理菜单",
62
+ "select_action": "请选择操作",
63
+ "action_load_config": "配置装载 - (将您的配置应用到 {{tool}})",
64
+ "action_unload_config": "配置卸载 - (从 {{tool}} 中移除配置)",
65
+ "action_view_config": "当前配置",
66
+ "action_back": "返回",
67
+ "action_exit": "退出",
68
+ "goodbye": "再见!",
69
+ "loading_config": "正在装载配置...",
70
+ "config_loaded": "配置已成功装载,您现在可以使用 {{tool}} 进行编码了。",
71
+ "config_load_failed": "配置装载失败",
72
+ "confirm_unload_config": "确认要从 {{tool}} 中卸载配置吗?",
73
+ "unloading_config": "正在卸载配置...",
74
+ "config_unloaded": "配置已成功卸载",
75
+ "config_unload_failed": "配置卸载失败",
76
+ "tool_not_supported": "该工具不支持此操作",
77
+ "missing_config": "缺少必要配置(API密钥或模型)",
78
+ "installed": "已安装",
79
+ "not_installed": "未安装",
80
+ "action_install": "安装",
81
+ "action_uninstall": "卸载",
82
+ "current_config": "当前配置",
83
+ "config_language": "界面语言",
84
+ "config_api_key": "API Key",
85
+ "config_title": "配置",
86
+ "not_set": "未设置",
87
+ "press_enter": "按回车继续",
88
+ "main_menu_title": "主菜单",
89
+ "current_config_status": "当前配置状态:",
90
+ "api_key_set": "已设置",
91
+ "api_key_get_hint": "如需获取 API Key,请访问: {{url}}",
92
+ "menu_config_language": "界面语言",
93
+ "menu_config_api_key": "配置 API Key",
94
+ "menu_config_models": "配置模型",
95
+ "menu_config_tool": "配置编码工具",
96
+ "menu_exit": "退出",
97
+ "select_operation": "请选择操作:",
98
+ "goodbye_message": "再见!",
99
+ "nav_return": "返回",
100
+ "nav_exit": "退出",
101
+ "current_active": "当前",
102
+ "operation_hint": "操作提示",
103
+ "hint_navigate": "↑↓ 选择",
104
+ "hint_confirm": "Enter 确认",
105
+ "detected_config_title": "Claude Code 当前配置",
106
+ "chelper_config_title": "Chelper 配置",
107
+ "claude_code_config_title": "Claude Code 当前全局配置",
108
+ "config_synced": "配置已同步",
109
+ "config_out_of_sync": "配置不一致,建议刷新",
110
+ "config_not_loaded": "Claude Code 尚未装载配置",
111
+ "action_refresh_config": "配置刷新 - (更新 {{tool}} 的配置)",
112
+ "global_config_warning": "⚠️ 注意:您正在修改 {{tool}} 全局配置,更改将影响所有工作区",
113
+ "global_label": "全局",
114
+ "set_success": "设置成功",
115
+ "start_tool": "启动 {{tool}} - (建议在您的工作空间新开终端,执行 {{shell}} 启动)",
116
+ "starting_tool": "启动中...",
117
+ "validating_api_key": "正在验证 API Key...",
118
+ "api_key_valid": "API Key 验证通过",
119
+ "api_key_invalid": "API Key 无效或已过期",
120
+ "api_key_network_error": "网络错误,请检查网络连接",
121
+ "select_models": "选择模型",
122
+ "configure_models": "配置模型选择",
123
+ "select_haiku_model": "选择 Haiku 模型 (快速/小型)",
124
+ "select_sonnet_model": "选择 Sonnet 模型 (默认)",
125
+ "select_opus_model": "选择 Opus 模型 (大型/强大)",
126
+ "current_haiku_model": "Haiku 模型",
127
+ "current_sonnet_model": "Sonnet 模型",
128
+ "current_opus_model": "Opus 模型",
129
+ "fetching_models": "正在获取可用模型列表...",
130
+ "fetch_models_failed": "获取模型列表失败,使用默认值",
131
+ "saving_model_config": "正在保存模型配置...",
132
+ "model_config_saved": "模型配置保存成功",
133
+ "model_config_failed": "模型配置保存失败",
134
+ "no_models_available": "没有可用的模型,请先配置 API Key。",
135
+ "models_config_title": "模型配置"
136
+ },
137
+ "doctor": {
138
+ "checking": "正在进行健康检查...",
139
+ "check_path": "检查PATH环境变量",
140
+ "check_api_key_network": "检查 API Key 和网络连接",
141
+ "check_api_key": "检查API密钥",
142
+ "check_tools": "检查已安装的工具",
143
+ "check_config": "检查配置",
144
+ "all_good": "所有检查通过!",
145
+ "tool_installed": "已安装",
146
+ "tool_not_found": "工具未找到: {{tool}}",
147
+ "network_error": "网络连接失败",
148
+ "api_key_invalid": "API Key 无效或已过期",
149
+ "api_key_network_ok": "API Key 和网络验证通过",
150
+ "api_key_missing": "API密钥未配置",
151
+ "claude_code_installed": "Claude Code 已安装",
152
+ "claude_code_not_installed": "Claude Code 未安装。请从 https://claude.ai/download 下载安装",
153
+ "config_configured": "配置完成",
154
+ "config_not_configured": "配置未完成。请运行 'chelper init' 进行配置",
155
+ "suggestions": "建议",
156
+ "check_git_env": "检查 Git 环境",
157
+ "git_not_installed": "Git 未安装。请从 https://git-scm.com/downloads 下载安装"
158
+ },
159
+ "messages": {
160
+ "initializing": "正在初始化...",
161
+ "args": "参数:",
162
+ "first_run": "检测到首次运行,启动初始化向导...",
163
+ "config_saved": "配置已保存"
164
+ },
165
+ "install": {
166
+ "permission_detected": "检测到权限问题,正在尝试解决...",
167
+ "trying_solution": "尝试方案 {{num}}: {{desc}}...",
168
+ "permission_fixed": "权限问题已解决!",
169
+ "auto_fix_failed": "自动修复失败。",
170
+ "windows_solutions": "Windows 用户请尝试以下方案之一:",
171
+ "windows_solution_1_title": "方案 1(推荐): 以管理员身份运行",
172
+ "windows_solution_1_step1": "1. 右键点击命令提示符或 PowerShell",
173
+ "windows_solution_1_step2": "2. 选择 \"以管理员身份运行\"",
174
+ "windows_solution_1_step3": "3. 重新运行安装命令",
175
+ "windows_solution_2_title": "方案 2: 使用用户级安装(无需管理员权限)",
176
+ "windows_solution_2_command": "在命令行中运行:",
177
+ "unix_solutions": "请手动尝试以下方案之一:",
178
+ "unix_solution_1_title": "方案 1: 使用 sudo 安装",
179
+ "unix_solution_1_desc": "在终端中运行以下命令(需要输入管理员密码):",
180
+ "unix_solution_2_title": "方案 2(推荐): 使用 nvm 管理 Node.js",
181
+ "unix_solution_2_desc": "使用 nvm 可以避免权限问题,这是 npm 官方推荐的方案",
182
+ "path_warning": "请将以下路径添加到您的 PATH 环境变量中:",
183
+ "path_add_method": "添加方法:",
184
+ "all_solutions_failed": "所有自动修复方案均失败。",
185
+ "using_sudo": "使用 sudo 权限安装",
186
+ "using_user_install": "使用用户级安装(无需 sudo)",
187
+ "using_force": "使用 --force 参数重试",
188
+ "npm_docs_link": "npm 官方文档",
189
+ "what_next": "请选择下一步操作",
190
+ "installed_continue": "✅ 我已完成安装,继续",
191
+ "cancel_install": "❌ 取消安装",
192
+ "user_cancelled": "用户取消了安装",
193
+ "still_not_installed": "{{tool}} 似乎仍未安装成功",
194
+ "install_failed_detail": "安装失败,错误信息:",
195
+ "skip_install_confirm": "是否跳过安装过程,自行安装后继续?",
196
+ "skip_install_yes": "跳过,我将自行安装",
197
+ "skip_install_no": "返回",
198
+ "retry_check": "是否重新检查安装状态?",
199
+ "verified_success": "{{tool}} 安装验证成功!"
200
+ }
201
+ }
@@ -0,0 +1,17 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3
6
+ }
7
+ export declare class Logger {
8
+ private static instance;
9
+ private logLevel;
10
+ private constructor();
11
+ static getInstance(): Logger;
12
+ setLogLevel(level: LogLevel): void;
13
+ debug(message: string, ...args: any[]): void;
14
+ info(message: string, ...args: any[]): void;
15
+ warn(message: string, ...args: any[]): void;
16
+ error(message: string, ...args: any[]): void;
17
+ }
@@ -0,0 +1,41 @@
1
+ export var LogLevel;
2
+ (function (LogLevel) {
3
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
4
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
5
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
6
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
7
+ })(LogLevel || (LogLevel = {}));
8
+ export class Logger {
9
+ static instance;
10
+ logLevel = LogLevel.INFO;
11
+ constructor() { }
12
+ static getInstance() {
13
+ if (!Logger.instance) {
14
+ Logger.instance = new Logger();
15
+ }
16
+ return Logger.instance;
17
+ }
18
+ setLogLevel(level) {
19
+ this.logLevel = level;
20
+ }
21
+ debug(message, ...args) {
22
+ if (this.logLevel <= LogLevel.DEBUG) {
23
+ console.debug(`[DEBUG] ${message}`, ...args);
24
+ }
25
+ }
26
+ info(message, ...args) {
27
+ if (this.logLevel <= LogLevel.INFO) {
28
+ console.info(`[INFO] ${message}`, ...args);
29
+ }
30
+ }
31
+ warn(message, ...args) {
32
+ if (this.logLevel <= LogLevel.WARN) {
33
+ console.warn(`[WARN] ${message}`, ...args);
34
+ }
35
+ }
36
+ error(message, ...args) {
37
+ if (this.logLevel <= LogLevel.ERROR) {
38
+ console.error(`[ERROR] ${message}`, ...args);
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Calculate the visual display width of a string
3
+ * Handles emoji, CJK characters, and ANSI escape codes
4
+ */
5
+ /**
6
+ * Strip ANSI escape codes from a string
7
+ */
8
+ export declare function stripAnsi(str: string): string;
9
+ /**
10
+ * Calculate the visual display width of a string
11
+ * Strips ANSI codes and counts visual width of each character
12
+ */
13
+ export declare function stringWidth(str: string): number;
14
+ /**
15
+ * Pad a string to a specific visual width
16
+ * @param str - The string to pad
17
+ * @param targetWidth - The target visual width
18
+ * @param char - The character to use for padding (default: space)
19
+ * @param align - Alignment: 'left', 'right', or 'center' (default: 'left')
20
+ */
21
+ export declare function padString(str: string, targetWidth: number, char?: string, align?: 'left' | 'right' | 'center'): string;
22
+ /**
23
+ * Create a box border line
24
+ * @param leftChar - Left border character
25
+ * @param rightChar - Right border character
26
+ * @param fillChar - Fill character
27
+ * @param width - Total width including borders
28
+ */
29
+ export declare function createBorderLine(leftChar: string, rightChar: string, fillChar: string, width: number): string;
30
+ /**
31
+ * Create a box content line with borders
32
+ * @param content - The content to display
33
+ * @param leftChar - Left border character
34
+ * @param rightChar - Right border character
35
+ * @param width - Total width including borders
36
+ * @param align - Content alignment
37
+ */
38
+ export declare function createContentLine(content: string, leftChar: string, rightChar: string, width: number, align?: 'left' | 'right' | 'center'): string;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Calculate the visual display width of a string
3
+ * Handles emoji, CJK characters, and ANSI escape codes
4
+ */
5
+ /**
6
+ * Strip ANSI escape codes from a string
7
+ */
8
+ export function stripAnsi(str) {
9
+ // eslint-disable-next-line no-control-regex
10
+ return str.replace(/\u001b\[[0-9;]*m/g, '');
11
+ }
12
+ /**
13
+ * Calculate the visual width of a character
14
+ * - Emoji and wide characters (CJK): 2
15
+ * - Regular ASCII: 1
16
+ * - Zero-width characters: 0
17
+ */
18
+ function charWidth(char) {
19
+ const code = char.codePointAt(0);
20
+ if (!code)
21
+ return 0;
22
+ // Zero-width characters
23
+ if (code === 0x200b || // Zero-width space
24
+ code === 0x200c || // Zero-width non-joiner
25
+ code === 0x200d || // Zero-width joiner
26
+ code === 0xfeff || // Zero-width no-break space
27
+ (code >= 0xfe00 && code <= 0xfe0f) // Variation Selectors (emoji style selectors)
28
+ ) {
29
+ return 0;
30
+ }
31
+ // Emoji and symbols (rough approximation)
32
+ // Most emoji are in these ranges and display as 2 characters wide
33
+ if ((code >= 0x1f300 && code <= 0x1f9ff) || // Misc Symbols and Pictographs, Emoticons, etc.
34
+ (code >= 0x2600 && code <= 0x26ff) || // Misc symbols
35
+ (code >= 0x2700 && code <= 0x27bf) || // Dingbats
36
+ (code >= 0x1f000 && code <= 0x1f02f) || // Mahjong Tiles, Domino Tiles
37
+ (code >= 0x1f0a0 && code <= 0x1f0ff) // Playing Cards
38
+ ) {
39
+ return 2;
40
+ }
41
+ // CJK characters (Chinese, Japanese, Korean)
42
+ // These are typically displayed as 2 characters wide
43
+ if ((code >= 0x4e00 && code <= 0x9fff) || // CJK Unified Ideographs
44
+ (code >= 0x3400 && code <= 0x4dbf) || // CJK Unified Ideographs Extension A
45
+ (code >= 0x20000 && code <= 0x2a6df) || // CJK Unified Ideographs Extension B
46
+ (code >= 0x2a700 && code <= 0x2b73f) || // CJK Unified Ideographs Extension C
47
+ (code >= 0x2b740 && code <= 0x2b81f) || // CJK Unified Ideographs Extension D
48
+ (code >= 0x2b820 && code <= 0x2ceaf) || // CJK Unified Ideographs Extension E
49
+ (code >= 0xf900 && code <= 0xfaff) || // CJK Compatibility Ideographs
50
+ (code >= 0x2f800 && code <= 0x2fa1f) || // CJK Compatibility Ideographs Supplement
51
+ (code >= 0x3040 && code <= 0x309f) || // Hiragana
52
+ (code >= 0x30a0 && code <= 0x30ff) || // Katakana
53
+ (code >= 0xac00 && code <= 0xd7af) || // Hangul Syllables
54
+ (code >= 0x1100 && code <= 0x11ff) || // Hangul Jamo
55
+ (code >= 0x3130 && code <= 0x318f) || // Hangul Compatibility Jamo
56
+ (code >= 0xa960 && code <= 0xa97f) || // Hangul Jamo Extended-A
57
+ (code >= 0xd7b0 && code <= 0xd7ff) // Hangul Jamo Extended-B
58
+ ) {
59
+ return 2;
60
+ }
61
+ // Fullwidth characters
62
+ if (code >= 0xff00 && code <= 0xffef) {
63
+ return 2;
64
+ }
65
+ // Default to 1 for regular ASCII and other characters
66
+ return 1;
67
+ }
68
+ /**
69
+ * Calculate the visual display width of a string
70
+ * Strips ANSI codes and counts visual width of each character
71
+ */
72
+ export function stringWidth(str) {
73
+ const cleaned = stripAnsi(str);
74
+ let width = 0;
75
+ // Use Array.from to properly handle surrogate pairs
76
+ for (const char of Array.from(cleaned)) {
77
+ width += charWidth(char);
78
+ }
79
+ return width;
80
+ }
81
+ /**
82
+ * Pad a string to a specific visual width
83
+ * @param str - The string to pad
84
+ * @param targetWidth - The target visual width
85
+ * @param char - The character to use for padding (default: space)
86
+ * @param align - Alignment: 'left', 'right', or 'center' (default: 'left')
87
+ */
88
+ export function padString(str, targetWidth, char = ' ', align = 'left') {
89
+ const currentWidth = stringWidth(str);
90
+ const padWidth = Math.max(0, targetWidth - currentWidth);
91
+ if (padWidth === 0)
92
+ return str;
93
+ const padding = char.repeat(padWidth);
94
+ if (align === 'right') {
95
+ return padding + str;
96
+ }
97
+ else if (align === 'center') {
98
+ const leftPad = Math.floor(padWidth / 2);
99
+ const rightPad = padWidth - leftPad;
100
+ return char.repeat(leftPad) + str + char.repeat(rightPad);
101
+ }
102
+ else {
103
+ return str + padding;
104
+ }
105
+ }
106
+ /**
107
+ * Create a box border line
108
+ * @param leftChar - Left border character
109
+ * @param rightChar - Right border character
110
+ * @param fillChar - Fill character
111
+ * @param width - Total width including borders
112
+ */
113
+ export function createBorderLine(leftChar, rightChar, fillChar, width) {
114
+ const innerWidth = width - stringWidth(leftChar) - stringWidth(rightChar);
115
+ return leftChar + fillChar.repeat(Math.max(0, innerWidth)) + rightChar;
116
+ }
117
+ /**
118
+ * Create a box content line with borders
119
+ * @param content - The content to display
120
+ * @param leftChar - Left border character
121
+ * @param rightChar - Right border character
122
+ * @param width - Total width including borders
123
+ * @param align - Content alignment
124
+ */
125
+ export function createContentLine(content, leftChar, rightChar, width, align = 'left') {
126
+ const borderWidth = stringWidth(leftChar) + stringWidth(rightChar);
127
+ const innerWidth = width - borderWidth;
128
+ const paddedContent = padString(content, innerWidth, ' ', align);
129
+ return leftChar + paddedContent + rightChar;
130
+ }