Calendar: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Need 1.8.7) |
(→{{header|Ruby}}: Try to require 'io/console' to guess the terminal's width.) |
||
Line 964: | Line 964: | ||
ARGV.length == 1 or |
ARGV.length == 1 or abort "usage: #{$0} year" |
||
# Guess width of terminal |
# Guess width of terminal. |
||
# 1. Obey environment variable COLUMNS. |
# 1. Obey environment variable COLUMNS. |
||
# 2. Try to |
# 2. Try to require 'io/console' from Ruby 1.9.3. |
||
# 3. |
# 3. Try to run `tput co`. |
||
# 4. Assume 80 columns. |
|||
columns = (Integer(ENV["COLUMNS"] || "") rescue |
|||
columns = begin Integer(ENV["COLUMNS"] || "") |
|||
rescue |
|||
begin require 'io/console'; IO.console.winsize[1] |
|||
rescue LoadError |
|||
begin Integer(`tput co`) |
|||
rescue |
|||
80; end; end; end |
|||
puts cal(Integer(ARGV[0]), columns)</lang> |
puts cal(Integer(ARGV[0]), columns)</lang> |