@make-u-free/migi 0.5.2 → 0.5.3

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.
Files changed (2) hide show
  1. package/bin/migi.js +25 -2
  2. package/package.json +1 -1
package/bin/migi.js CHANGED
@@ -79,6 +79,29 @@ function sepWithLabel(label) {
79
79
  }
80
80
 
81
81
  // ---- チャット入力(Enter送信 / Shift+Enter改行)----
82
+ // 全角文字(日本語・絵文字など)は端末上で2カラム幅を占める
83
+ // string.length はコードポイント数なので、カーソル位置計算に使うと日本語入力でズレる
84
+ function displayWidth(str) {
85
+ let w = 0
86
+ for (const ch of str) {
87
+ const cp = ch.codePointAt(0)
88
+ const wide =
89
+ (cp >= 0x1100 && cp <= 0x115F) || // Hangul Jamo
90
+ (cp >= 0x2E80 && cp <= 0x303F) || // CJK Radicals
91
+ (cp >= 0x3040 && cp <= 0x33FF) || // Hiragana〜CJK Compat
92
+ (cp >= 0x3400 && cp <= 0x9FFF) || // CJK Unified
93
+ (cp >= 0xAC00 && cp <= 0xD7FF) || // Hangul Syllables
94
+ (cp >= 0xF900 && cp <= 0xFAFF) || // CJK Compat Ideographs
95
+ (cp >= 0xFE10 && cp <= 0xFE1F) || // Vertical Forms
96
+ (cp >= 0xFE30 && cp <= 0xFE6F) || // CJK Compat Forms
97
+ (cp >= 0xFF01 && cp <= 0xFF60) || // Fullwidth ASCII
98
+ (cp >= 0xFFE0 && cp <= 0xFFE6) || // Fullwidth Signs
99
+ (cp >= 0x1F300 && cp <= 0x1FAFF) // Emoji
100
+ w += wide ? 2 : 1
101
+ }
102
+ return w
103
+ }
104
+
82
105
  async function readChatInput() {
83
106
  return new Promise((resolve) => {
84
107
  const PFIRST = ' > '
@@ -132,9 +155,9 @@ async function readChatInput() {
132
155
  if (linesFromBottom > 0) buf += `\x1b[${linesFromBottom}A`
133
156
  buf += '\r'
134
157
 
135
- // ⑤ カーソルを入力内容の末尾へ
158
+ // ⑤ カーソルを入力内容の末尾へ(全角文字は2カラム幅なので displayWidth を使う)
136
159
  const prefix = curLine === 0 ? PFIRST : PCONT
137
- buf += `\x1b[${prefix.length + lines[curLine].length + 1}G`
160
+ buf += `\x1b[${prefix.length + displayWidth(lines[curLine]) + 1}G`
138
161
 
139
162
  cursorLine = curLine
140
163
  process.stdout.write(buf)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@make-u-free/migi",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Your AI right-hand agent. Works anywhere, with any LLM API.",
5
5
  "type": "module",
6
6
  "bin": {