Class: Minder::Application
- Inherits:
-
Object
- Object
- Minder::Application
- Defined in:
- lib/minder/application.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#filter_frame ⇒ Object
Returns the value of attribute filter_frame.
-
#help_frame ⇒ Object
Returns the value of attribute help_frame.
-
#message_frame ⇒ Object
Returns the value of attribute message_frame.
-
#pomodoro_frame ⇒ Object
Returns the value of attribute pomodoro_frame.
-
#quick_add_frame ⇒ Object
Returns the value of attribute quick_add_frame.
-
#scene ⇒ Object
Returns the value of attribute scene.
-
#search_frame ⇒ Object
Returns the value of attribute search_frame.
Instance Method Summary collapse
- #config_location ⇒ Object
- #handle_event(event, data = {}) ⇒ Object
-
#initialize(config: Minder::Config.new(CONFIG_LOCATION), database: Database.new) ⇒ Application
constructor
A new instance of Application.
- #pomodoro_runner ⇒ Object
- #run ⇒ Object
- #task_manager ⇒ Object
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
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/minder/application.rb', line 10 def config @config end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
19 20 21 |
# File 'lib/minder/application.rb', line 19 def database @database end |
#filter_frame ⇒ Object
Returns the value of attribute filter_frame.
10 11 12 |
# File 'lib/minder/application.rb', line 10 def filter_frame @filter_frame end |
#help_frame ⇒ Object
Returns the value of attribute help_frame.
10 11 12 |
# File 'lib/minder/application.rb', line 10 def help_frame @help_frame end |
#message_frame ⇒ Object
Returns the value of attribute message_frame.
10 11 12 |
# File 'lib/minder/application.rb', line 10 def @message_frame end |
#pomodoro_frame ⇒ Object
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_frame ⇒ Object
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 |
#scene ⇒ Object
Returns the value of attribute scene.
10 11 12 |
# File 'lib/minder/application.rb', line 10 def scene @scene end |
#search_frame ⇒ Object
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_location ⇒ Object
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 .minimize when :completed_work .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 .hide help_frame.unhide scene.focus_frame(help_frame) when :hide_help help_frame.hide .unhide scene.focus_frame() when :open_filter filter_frame.unhide scene.focus_frame(filter_frame) when :submit_filter filter_frame.hide if data[:text] == '' scene.focus_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() 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() end scene.redraw scene.redraw end |
#pomodoro_runner ⇒ Object
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 |
#run ⇒ Object
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 = { pomodoro_runner: pomodoro_runner, task_manager: task_manager } self.pomodoro_frame = PomodoroFrame.new() self.help_frame = HelpFrame.new() help_frame.hide self.filter_frame = FilterFrame.new() filter_frame.hide self.search_frame = SearchFrame.new() search_frame.hide self. = MessageFrame.new() self.quick_add_frame = QuickAddFrame.new() quick_add_frame.focus scene.frames << pomodoro_frame scene.frames << 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_manager ⇒ Object
101 102 103 |
# File 'lib/minder/application.rb', line 101 def task_manager @task_manager ||= TaskManager.new(database: database) end |