カレンダー改修途中
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
|
#!/usr/bin/ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
## 年月の初期設定(現在の年月)
|
|
||||||
year = Date.today.year
|
year = Date.today.year
|
||||||
month = Date.today.month
|
month = Date.today.month
|
||||||
|
week = %w[日 月 火 水 木 金 土]
|
||||||
|
|
||||||
## コマンドラインオプション指定で年月を置き換える
|
|
||||||
opt = OptionParser.new
|
opt = OptionParser.new
|
||||||
opt.on('-m month') { |v| month = v.to_i }
|
opt.on('-m month') { |v| month = v.to_i }
|
||||||
opt.on('-y year') { |v| year = v.to_i }
|
opt.on('-y year') { |v| year = v.to_i }
|
||||||
opt.parse(ARGV)
|
opt.parse(ARGV)
|
||||||
|
|
||||||
## 月初日の曜日、当該月の総日数、週の配列
|
first_day = Date.new(year, month, 1)
|
||||||
startwday = Date.new(year, month, 1).wday
|
last_day = Date.new(year, month, -1)
|
||||||
totaldate = Date.new(year, month, -1).day
|
puts "#{month.to_s.rjust(7)}月\s#{year}"
|
||||||
week = %w[日 月 火 水 木 金 土]
|
|
||||||
|
|
||||||
## カレンダーを出力する
|
|
||||||
puts month.to_s.rjust(7) + '月 ' + year.to_s
|
|
||||||
puts week.join(' ')
|
puts week.join(' ')
|
||||||
print ' ' * startwday
|
print "\s\s\s" * first_day.wday
|
||||||
days = startwday
|
|
||||||
(1..totaldate).each do |day|
|
(first_day..last_day).each do |date|
|
||||||
print day.to_s.rjust(2) + ' '
|
day_string = date.day.to_s.rjust(2, ' ')
|
||||||
days += 1
|
day_string = "\e[7m#{day_string}\e[0m" if date == Date.today
|
||||||
print "\n" if days % 7 == 0
|
print day_string
|
||||||
if day == Date.today.day - 1 && ARGV == []
|
puts if date.saturday?
|
||||||
print "\e[30m\e[47m"
|
|
||||||
else
|
|
||||||
print "\e[0m"
|
|
||||||
end
|
|
||||||
end
|
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