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 raise "usage: #{$0} year"
ARGV.length == 1 or abort "usage: #{$0} year"


# Guess width of terminal device.
# Guess width of terminal.
# 1. Obey environment variable COLUMNS.
# 1. Obey environment variable COLUMNS.
# 2. Try to run `tput co`.
# 2. Try to require 'io/console' from Ruby 1.9.3.
# 3. Assume 80 columns.
# 3. Try to run `tput co`.
# 4. Assume 80 columns.
columns = (Integer(ENV["COLUMNS"] || "") rescue
Integer(`tput co`) rescue
columns = begin Integer(ENV["COLUMNS"] || "")
80)
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>