カレンダー改修途中
This commit is contained in:
parent
de6463a825
commit
b5e339c51a
1 changed files with 23 additions and 20 deletions
43
cal.rb
43
cal.rb
|
@ -1,34 +1,37 @@
|
|||
#!/usr/bin/ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'date'
|
||||
require 'optparse'
|
||||
|
||||
## 年月の初期設定(現在の年月)
|
||||
year = Date.today.year
|
||||
month = Date.today.month
|
||||
week = %w[日 月 火 水 木 金 土]
|
||||
|
||||
## コマンドラインオプション指定で年月を置き換える
|
||||
opt = OptionParser.new
|
||||
opt.on('-m month') { |v| month = v.to_i }
|
||||
opt.on('-y year') { |v| year = v.to_i }
|
||||
opt.parse(ARGV)
|
||||
|
||||
## 月初日の曜日、当該月の総日数、週の配列
|
||||
startwday = Date.new(year, month, 1).wday
|
||||
totaldate = Date.new(year, month, -1).day
|
||||
week = %w[日 月 火 水 木 金 土]
|
||||
|
||||
## カレンダーを出力する
|
||||
puts month.to_s.rjust(7) + '月 ' + year.to_s
|
||||
first_day = Date.new(year, month, 1)
|
||||
last_day = Date.new(year, month, -1)
|
||||
puts "#{month.to_s.rjust(7)}月\s#{year}"
|
||||
puts week.join(' ')
|
||||
print ' ' * startwday
|
||||
days = startwday
|
||||
(1..totaldate).each do |day|
|
||||
print day.to_s.rjust(2) + ' '
|
||||
days += 1
|
||||
print "\n" if days % 7 == 0
|
||||
if day == Date.today.day - 1 && ARGV == []
|
||||
print "\e[30m\e[47m"
|
||||
else
|
||||
print "\e[0m"
|
||||
end
|
||||
print "\s\s\s" * first_day.wday
|
||||
|
||||
(first_day..last_day).each do |date|
|
||||
day_string = date.day.to_s.rjust(2, ' ')
|
||||
day_string = "\e[7m#{day_string}\e[0m" if date == Date.today
|
||||
print day_string
|
||||
puts if date.saturday?
|
||||
end
|
||||
puts
|
||||
|
||||
# print "#{date.day.to_s.rjust(2)}\s"
|
||||
# date += 1
|
||||
# print "\n" if date.sunday?
|
||||
# if date == Date.today && ARGV == [] # 引数なしなら現在日をハイライトする
|
||||
# print "\e[7m\e[7m"
|
||||
# else
|
||||
# print "\e[0m"
|
||||
# end
|
||||
|
|
Loading…
Reference in a new issue