Terminal control/Dimensions: Difference between revisions

Content added Content deleted
m (Fix categories, move them to the top)
(→‎{{header|Ruby}}: Add curses.)
Line 233: Line 233:
=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>def winsize
<lang ruby>def winsize
# This requires Ruby 1.9.3.
# Ruby 1.9.3 added 'io/console' to the standard library.
require 'io/console'
require 'io/console'
IO.console.winsize
IO.console.winsize
Line 244: Line 244:
rows, cols = winsize
rows, cols = winsize
printf "%d rows by %d columns\n", rows, cols</lang>
printf "%d rows by %d columns\n", rows, cols</lang>

==={{libheader|curses}}===
<code>Curses.lines</code> and <code>Curses.cols</code> return the size of the terminal. The program ''must'' call <code>Curses.init_screen</code>, because without this call, Curses might report 0 lines and 0 columns. Beware that <code>Curses.init_screen</code> also switches the terminal to screen-oriented mode, and fails on those terminals that cannot support curses.

<lang ruby>require 'curses'

begin
Curses.init_screen

r, c = Curses.lines, Curses.cols

Curses.setpos r / 2, 0
Curses.addstr "#{r} rows by #{c} columns".center(c)
Curses.getch
ensure
Curses.close_screen
end</lang>


=={{header|Seed7}}==
=={{header|Seed7}}==