Class: TerminalCalendar::DatePicker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month, input: $stdin, output: $stdout, env: ENV, interrupt: :error, track_history: true) ⇒ DatePicker

Returns a new instance of DatePicker.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/terminal_calendar/date_picker.rb', line 17

def initialize(month, input: $stdin, output: $stdout, env: ENV, interrupt: :error,
               track_history: true)
  @current_page = Selection::MonthPage.build(month)
  @month_pages = [[month, @current_page]].to_h
  @reader = TTY::Reader.new(
    input: input,
    output: output,
    interrupt: interrupt,
    track_history: track_history,
    env: env
  )
  @output = output
  @cursor = TTY::Cursor
  @pastel = Pastel.new
end

Instance Attribute Details

#cursorObject (readonly)

Returns the value of attribute cursor.



11
12
13
# File 'lib/terminal_calendar/date_picker.rb', line 11

def cursor
  @cursor
end

#monthObject (readonly)

Returns the value of attribute month.



11
12
13
# File 'lib/terminal_calendar/date_picker.rb', line 11

def month
  @month
end

#readerObject (readonly)

Returns the value of attribute reader.



11
12
13
# File 'lib/terminal_calendar/date_picker.rb', line 11

def reader
  @reader
end

#selectorTerminalCalendar::Selection::Selector (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/terminal_calendar/date_picker.rb', line 15

def selector
  @selector
end

Class Method Details

.pick(month: TerminalCalendar::Month.this_month) ⇒ Object



7
8
9
# File 'lib/terminal_calendar/date_picker.rb', line 7

def self.pick(month: TerminalCalendar::Month.this_month)
  new(month).pick
end

Instance Method Details

#pickObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/terminal_calendar/date_picker.rb', line 33

def pick
  @output.print(@cursor.hide)
  render

  selection_loop

  month_pages.values.flat_map { |p| p.selection_grid.selected_cells.map(&:date) }
ensure
  @output.print(@cursor.show)
end

#renderObject



44
45
46
# File 'lib/terminal_calendar/date_picker.rb', line 44

def render
  @output.print(current_page.render)
end