端末サイズ取得例 (dttermの端末サイズ問い合わせを使用)

形式
Ruby
投稿日時
2017-08-08 21:14
公開期間
無期限
  1. #!/usr/bin/ruby
  2. #encoding: ascii-8bit
  3. require 'io/console'
  4. resp = ""
  5. STDIN.raw do |stdin|
  6. STDERR.print "\e[18t" # query terminal size
  7. resp = ""
  8. while (c = stdin.getc)
  9. resp << c.chr
  10. break unless /[\[\x1b\x9c;0-9]/ =~ c
  11. end
  12. end
  13. if /(?:\x9c|\x1b\[)8;(\d+);(\d+)t/ =~ resp # check response of cursor position query
  14. rows = $1.to_i
  15. cols = $2.to_i
  16. puts "COLUMNS=#{cols}"
  17. puts "ROWS=#{rows}"
  18. else
  19. STDERR.puts "Invalid response"
  20. end
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト