0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TUIってIME認識できないんだっけ?

Posted at

Gemini CLIが日本語入力時のカーソルを全然認識せずに、カーソルがあさってのところに行っちゃう。そういやTUIアプリを作ったことないので、cursesをラップしたruby gemで試しに作ってみて、TUIアプリって日本語入力が苦手なのかどうかを試してみた。

サンプルソース

cursessample.rb
require 'curses'

Curses.init_screen
begin
  Curses.clear
  Curses.timeout = -1       # ブロッキング入力
  Curses.echo               # エコーONでgetstrを使える
  Curses.curs_set(1)        # カーソル表示

  height = Curses.lines
  width = Curses.cols
  msg = "日本語で入力してください: "
  y = height / 2
  x = (width - msg.bytesize) / 2

  Curses.setpos(y, x)
  Curses.addstr(msg)
  Curses.refresh

  # getstrで文字列(複数バイト文字)入力を受け取る
  str = Curses.getstr

  result = "入力: #{str.inspect}"
  Curses.setpos(y + 2, (width - result.bytesize) / 2)
  Curses.addstr(result)
  Curses.refresh

  Curses.getch  # 終了待ち
ensure
  Curses.close_screen
end

実行結果

image.png

全然できるやんけ!

素直にcursesでTUIアプリを作っておけばいいものを…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?