Class: TerminalCalendar::Selection::MonthYearDialog

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/terminal_calendar/selection/month_year_dialog.rb

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout, env: ENV, interrupt: :error, track_history: true, start_at: Date.today) ⇒ MonthYearDialog

Initializes a new MonthYearDialog instance.

Parameters:

  • start_at (Date) (defaults to: Date.today)

    the starting date for the dialog (default: Date.today)

  • input (IO) (defaults to: $stdin)

    the input stream to read user input from (default: $stdin)

  • output (IO) (defaults to: $stdout)

    the output stream to write messages to (default: $stdout)

  • env (Hash) (defaults to: ENV)

    the environment variables (default: ENV)

  • interrupt (Symbol) (defaults to: :error)

    the behavior when an interrupt signal is received (:error or :exit) (default: :error)

  • track_history (Boolean) (defaults to: true)

    whether to track user input history (default: true)



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/terminal_calendar/selection/month_year_dialog.rb', line 16

def initialize(input: $stdin, output: $stdout, env: ENV, interrupt: :error, track_history: true,
               start_at: Date.today)
  @output = output
  @reader = TTY::Reader.new(
    input: input,
    output: output,
    interrupt: interrupt,
    track_history: track_history,
    env: env
  )
  initialize_carousels(start_at)
  @cursor = TTY::Cursor
end

Instance Method Details

#redraw(amt = 2) ⇒ Object



45
46
47
48
# File 'lib/terminal_calendar/selection/month_year_dialog.rb', line 45

def redraw(amt=2)
  @output.print(cursor.clear_lines(amt))
  amt == 2 ? render : year_car.render
end

#renderObject

Renders the dialog for month and year to the output



31
32
33
34
35
# File 'lib/terminal_calendar/selection/month_year_dialog.rb', line 31

def render
  month_car.render
  @output.puts
  year_car.render
end

#selectObject



37
38
39
40
41
42
43
# File 'lib/terminal_calendar/selection/month_year_dialog.rb', line 37

def select
  cursor.invisible do
    render

    key_capture
  end
end