チケット #37429

Readback Height & Width

登録: 2017-08-08 14:01 最終更新: 2018-12-07 14:04

報告者:
担当者:
チケットの種類:
状況:
完了
コンポーネント:
(未割り当て)
マイルストーン:
(未割り当て)
優先度:
5 - 中
重要度:
5 - 中
解決法:
直さない
ファイル:
なし
投票
点数: 0
No votes
0.0% (0/0)
0.0% (0/0)

詳細

I need to read the terminal height and width (as displayed in the setup menu) from the computer on the serial line.

チケットの履歴 (4 件中 3 件表示)

2017-08-08 14:01 更新者: jacotton
  • 新しいチケット "Readback Height & Width" が作成されました
2017-08-08 15:29 更新者: doda
コメント

It can do with the combination of standard control sequences as follows.

  • CUP: move cursor.
  • CPR: get cursor position.
  • DECSC: save cursor position.
  • DECRC: restore cursor position.

cf. https://ttssh2.osdn.jp/manual/en/about/ctrlseq.html

here is the sample ruby script.

  1. #!/usr/bin/ruby
  2. #encoding: ascii-8bit
  3. require 'io/console'
  4. resp = ""
  5. STDIN.raw do |stdin|
  6. STDERR.print "\e7" # save cursor position
  7. STDERR.print "\e[999;999H" # move cursor to 999, 999
  8. STDERR.print "\e[6n" # query cursor position
  9. STDERR.print "\e8" # restore cursor position
  10. resp = ""
  11. while (c = stdin.getc)
  12. resp << c.chr
  13. break unless /[\[\x1b\x9c;0-9]/ =~ c
  14. end
  15. end
  16. if /(?:\x9c|\x1b\[)(\d+);(\d+)R/ =~ resp # check response of cursor position query
  17. rows = $1.to_i
  18. cols = $2.to_i
  19. puts "COLUMNS=#{cols}"
  20. puts "ROWS=#{rows}"
  21. else
  22. STDERR.puts "Invalid response"
  23. end

2017-08-09 16:53 更新者: doda
コメント

Another way, using the dtterm's window manipulation sequence.

Here is the sample bash script.

  1. #!/bin/bash
  2. die() {
  3. echo "$@"
  4. exit 1
  5. }
  6. printf "\e[18t"
  7. read -r -t 1 -n 3 resp
  8. [ $? -ne 0 ] && die "No response"
  9. CSI=$(printf "\x9b")
  10. ESC=$(printf "\e")
  11. case $resp in
  12. ${CSI}8\;) : ;;
  13. ${ESC}\[8)
  14. read -r -t 1 -n 1 resp
  15. [ $? -ne 0 -o "$resp" != ";" ] && die "Invalid Response";;
  16. *) die "Invalid Response";;
  17. esac
  18. state=0
  19. cols=0
  20. rows=0
  21. while [ $state -lt 3 ]; do
  22. read -r -t 1 -n 1 resp
  23. [ $? -ne 0 ] && die "Invalid Response"
  24. case $resp in
  25. [0-9])
  26. if [ $state -eq 0 ]; then
  27. rows=$((rows * 10 + resp))
  28. elif [ $state -eq 1 ]; then
  29. cols=$((cols * 10 + resp))
  30. fi;;
  31. \;) [ $state -lt 2 ] && state=$((++state));;
  32. t) state=3;;
  33. *) die "Invalid response";;
  34. esac
  35. done
  36. echo "COLUMNS=$cols"
  37. echo "ROWS=$rows"

2018-12-07 14:04 更新者: doda
  • 詳細が更新されました
  • 解決法なし から 直さない に更新されました
  • 担当者(未割り当て) から doda に更新されました
  • 状況オープン から 完了 に更新されました

添付ファイルリスト

添付ファイルはありません

編集

ログインしていません。ログインしていない状態では、コメントに記載者の記録が残りません。 » ログインする