Class: DatePicker

Inherits:
Object
  • Object
show all
Includes:
Rcurses::Input
Defined in:
lib/datepick.rb

Constant Summary collapse

CONFIG_FILE =
File.expand_path('~/.datepick')
DEFAULT_CONFIG =
{
  'date_format' => '%Y-%m-%d',
  'months_before' => 1,
  'months_after' => 1,
  'week_starts_monday' => true,
  'highlight_weekends' => true,
  'colors' => {
    'year' => 14,      # cyan
    'month' => 10,     # green
    'day' => 15,       # white
    'selected' => 11,  # yellow
    'today' => 13,     # magenta
    'weekend' => 9     # red
  }
}.freeze
DATE_FORMATS =

Common date formats for quick selection

{
  '1' => '%Y-%m-%d',        # ISO format
  '2' => '%d/%m/%Y',        # European
  '3' => '%m/%d/%Y',        # US format
  '4' => '%B %d, %Y',       # Long format
  '5' => '%b %d, %Y',       # Abbreviated
  '6' => '%Y%m%d',          # Compact
  '7' => '%d-%b-%Y',        # DD-Mon-YYYY
  '8' => '%A, %B %d, %Y'    # Full with weekday
}

Instance Method Summary collapse

Constructor Details

#initializeDatePicker

Returns a new instance of DatePicker.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datepick.rb', line 38

def initialize
  @config = load_config
  @selected_date = Date.today
  @current_month = Date.today
  @config_mode = false
  @config_selected = 0
  @screen_w = `tput cols`.to_i
  @screen_h = `tput lines`.to_i
  
  # Initialize panes
  @main_pane = Rcurses::Pane.new(1, 1, @screen_w, @screen_h - 4, nil, nil)
  @main_pane.border = false
  
  @help_pane = Rcurses::Pane.new(1, @screen_h - 3, @screen_w, 1, nil, nil)
  @help_pane.border = false
  
  @status_pane = Rcurses::Pane.new(1, @screen_h - 1, @screen_w, 1, nil, nil)
  @status_pane.border = false
  
  @prev_content = ""
end

Instance Method Details

#runObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/datepick.rb', line 60

def run
  Rcurses.init!
  Rcurses::Cursor.hide
  
  begin
    # Initial display
    render
    
    loop do
      input = handle_input
      break if input == :exit
      render
    end
  rescue Interrupt
    # Exit cleanly on Ctrl-C
  ensure
    Rcurses.cleanup!
  end
end