Class: Minder::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/minder/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Minder::Config.new(CONFIG_LOCATION), database: Database.new) ⇒ Application

Returns a new instance of Application.



21
22
23
24
25
26
27
28
29
# File 'lib/minder/application.rb', line 21

def initialize(config: Minder::Config.new(CONFIG_LOCATION),
               database: Database.new)
  @database = database
  self.config = config
  config.load
  FileUtils.mkdir_p(File.join(ENV['HOME'], '.minder'))
  FileUtils.touch(DOING_FILE)
  FileUtils.touch(DONE_FILE)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/minder/application.rb', line 10

def config
  @config
end

#databaseObject (readonly)

Returns the value of attribute database.



19
20
21
# File 'lib/minder/application.rb', line 19

def database
  @database
end

#filter_frameObject

Returns the value of attribute filter_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def filter_frame
  @filter_frame
end

#help_frameObject

Returns the value of attribute help_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def help_frame
  @help_frame
end

#message_frameObject

Returns the value of attribute message_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def message_frame
  @message_frame
end

#pomodoro_frameObject

Returns the value of attribute pomodoro_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def pomodoro_frame
  @pomodoro_frame
end

#quick_add_frameObject

Returns the value of attribute quick_add_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def quick_add_frame
  @quick_add_frame
end

#sceneObject

Returns the value of attribute scene.



10
11
12
# File 'lib/minder/application.rb', line 10

def scene
  @scene
end

#search_frameObject

Returns the value of attribute search_frame.



10
11
12
# File 'lib/minder/application.rb', line 10

def search_frame
  @search_frame
end

Instance Method Details

#config_locationObject



31
32
33
# File 'lib/minder/application.rb', line 31

def config_location
  config.location
end

#handle_event(event, data = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/minder/application.rb', line 105

def handle_event(event, data = {})
  return unless event

  case event
  when :started_work
    message_frame.minimize
  when :completed_work
    message_frame.unminimize
  when :continue
    pomodoro_runner.continue
  when :editor
    `$EDITOR ~/.minder/doing.txt`
    task_manager.reload
  when :add_task
    task_manager.add_task(data[:task])
  when :switch_focus
    scene.switch_focus
  when :select_next_task
    task_manager.select_next_task
  when :select_previous_task
    task_manager.select_previous_task
  when :delete_task
    task_manager.delete_task
  when :complete_task
    task_manager.complete_task
  when :start_task
    task_manager.start_task
  when :unstart_task
    task_manager.unstart_task
  when :select_last_task
    task_manager.select_last_task
  when :select_first_task
    task_manager.select_first_task
  when :help
    message_frame.hide
    help_frame.unhide
    scene.focus_frame(help_frame)
  when :hide_help
    help_frame.hide
    message_frame.unhide
    scene.focus_frame(message_frame)
  when :open_filter
    filter_frame.unhide
    scene.focus_frame(filter_frame)
  when :submit_filter
    filter_frame.hide if data[:text] == ''
    scene.focus_frame(message_frame)
  when :update_filter
    task_manager.filter(data[:text])
  when :search
    search_frame.unhide
    search_frame.begin_search
    scene.focus_frame(search_frame)
  when :submit_search
    search_frame.hide
    scene.focus_frame(message_frame)
    task_manager.search(data[:text])
    task_manager.select_search_result
  when :next_search
    task_manager.next_search
  when :previous_search
    task_manager.previous_search
  when :escape_search
    search_frame.hide
    scene.focus_frame(message_frame)
  end

  scene.redraw
  scene.redraw
end

#pomodoro_runnerObject



93
94
95
96
97
98
99
# File 'lib/minder/application.rb', line 93

def pomodoro_runner
  @runner ||= PomodoroRunner.new(
    work_duration: config.work_duration,
    short_break_duration: config.short_break_duration,
    long_break_duration: config.long_break_duration,
    database: database)
end

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/minder/application.rb', line 35

def run
  pomodoro_runner.add_observer(self, :handle_event)

  self.scene = Scene.new
  scene.setup

  options = { pomodoro_runner: pomodoro_runner, task_manager: task_manager  }

  self.pomodoro_frame = PomodoroFrame.new(options)
  self.help_frame = HelpFrame.new(options)
  help_frame.hide
  self.filter_frame = FilterFrame.new(options)
  filter_frame.hide
  self.search_frame = SearchFrame.new(options)
  search_frame.hide
  self.message_frame = MessageFrame.new(options)
  self.quick_add_frame = QuickAddFrame.new(options)
  quick_add_frame.focus

  scene.frames << pomodoro_frame
  scene.frames << message_frame
  scene.frames << help_frame
  scene.frames << filter_frame
  scene.frames << search_frame
  scene.frames << quick_add_frame

  scene.frames.each do |frame|
    frame.add_observer(self, :handle_event)
  end

  # TODO: Eww, gross
  scene.redraw
  scene.redraw

  old_dimensions = [Curses.lines, Curses.cols]
  loop do
    scene.frames.each do |frame|
      next unless frame.focused?
      frame.listen
    end
    pomodoro_runner.tick
    pomodoro_frame.refresh
    scene.focused_frame.set_cursor_position
    scene.focused_frame.window_refresh

    new_dimensions = [Curses.lines, Curses.cols]
    if new_dimensions != old_dimensions
      scene.redraw
      scene.redraw
      old_dimensions = new_dimensions
    end

    sleep(0.01)
  end

  scene.close
end

#task_managerObject



101
102
103
# File 'lib/minder/application.rb', line 101

def task_manager
  @task_manager ||= TaskManager.new(database: database)
end