Class: LogBench::App::State
- Inherits:
-
Object
- Object
- LogBench::App::State
- Defined in:
- lib/log_bench/app/state.rb
Instance Attribute Summary collapse
-
#auto_scroll ⇒ Object
Returns the value of attribute auto_scroll.
-
#detail_filter ⇒ Object
readonly
Returns the value of attribute detail_filter.
-
#detail_scroll_offset ⇒ Object
Returns the value of attribute detail_scroll_offset.
-
#main_filter ⇒ Object
readonly
Returns the value of attribute main_filter.
-
#requests ⇒ Object
Returns the value of attribute requests.
-
#scroll_offset ⇒ Object
Returns the value of attribute scroll_offset.
-
#selected ⇒ Object
Returns the value of attribute selected.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
-
#text_selection_mode ⇒ Object
Returns the value of attribute text_selection_mode.
-
#update_available ⇒ Object
Returns the value of attribute update_available.
-
#update_version ⇒ Object
Returns the value of attribute update_version.
Instance Method Summary collapse
- #add_to_filter(char) ⇒ Object
- #adjust_auto_scroll(visible_height) ⇒ Object
- #adjust_scroll_bounds(visible_height) ⇒ Object
- #adjust_scroll_for_selection(visible_height) ⇒ Object
- #backspace_filter ⇒ Object
- #clear_detail_filter ⇒ Object
- #clear_filter ⇒ Object
- #current_request ⇒ Object
- #cycle_sort_mode ⇒ Object
- #detail_filter_mode ⇒ Object
- #dismiss_update_notification ⇒ Object
- #enter_filter_mode ⇒ Object
- #exit_filter_mode ⇒ Object
- #filter_mode ⇒ Object
- #filtered_requests ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #left_pane_focused? ⇒ Boolean
- #navigate_down ⇒ Object
- #navigate_up ⇒ Object
- #right_pane_focused? ⇒ Boolean
- #running? ⇒ Boolean
- #set_update_available(version) ⇒ Object
- #stop! ⇒ Object
- #switch_to_left_pane ⇒ Object
- #switch_to_right_pane ⇒ Object
- #text_selection_mode? ⇒ Boolean
- #toggle_auto_scroll ⇒ Object
- #toggle_text_selection_mode ⇒ Object
- #update_available? ⇒ Boolean
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/log_bench/app/state.rb', line 9 def initialize self.requests = [] self.selected = 0 self.scroll_offset = 0 self.auto_scroll = true self.running = true self.focused_pane = :left self.detail_scroll_offset = 0 self.text_selection_mode = false self.main_filter = Filter.new self.detail_filter = Filter.new self.sort = Sort.new self.update_available = false self.update_version = nil end |
Instance Attribute Details
#auto_scroll ⇒ Object
Returns the value of attribute auto_scroll.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def auto_scroll @auto_scroll end |
#detail_filter ⇒ Object
Returns the value of attribute detail_filter.
6 7 8 |
# File 'lib/log_bench/app/state.rb', line 6 def detail_filter @detail_filter end |
#detail_scroll_offset ⇒ Object
Returns the value of attribute detail_scroll_offset.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def detail_scroll_offset @detail_scroll_offset end |
#main_filter ⇒ Object
Returns the value of attribute main_filter.
6 7 8 |
# File 'lib/log_bench/app/state.rb', line 6 def main_filter @main_filter end |
#requests ⇒ Object
Returns the value of attribute requests.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def requests @requests end |
#scroll_offset ⇒ Object
Returns the value of attribute scroll_offset.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def scroll_offset @scroll_offset end |
#selected ⇒ Object
Returns the value of attribute selected.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def selected @selected end |
#sort ⇒ Object
Returns the value of attribute sort.
6 7 8 |
# File 'lib/log_bench/app/state.rb', line 6 def sort @sort end |
#text_selection_mode ⇒ Object
Returns the value of attribute text_selection_mode.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def text_selection_mode @text_selection_mode end |
#update_available ⇒ Object
Returns the value of attribute update_available.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def update_available @update_available end |
#update_version ⇒ Object
Returns the value of attribute update_version.
7 8 9 |
# File 'lib/log_bench/app/state.rb', line 7 def update_version @update_version end |
Instance Method Details
#add_to_filter(char) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/log_bench/app/state.rb', line 103 def add_to_filter(char) if main_filter.active? main_filter.add_character(char) elsif detail_filter.active? detail_filter.add_character(char) end end |
#adjust_auto_scroll(visible_height) ⇒ Object
180 181 182 183 184 185 |
# File 'lib/log_bench/app/state.rb', line 180 def adjust_auto_scroll(visible_height) return unless auto_scroll && !filtered_requests.empty? self.selected = filtered_requests.size - 1 self.scroll_offset = [selected - visible_height + 1, 0].max end |
#adjust_scroll_bounds(visible_height) ⇒ Object
187 188 189 190 191 |
# File 'lib/log_bench/app/state.rb', line 187 def adjust_scroll_bounds(visible_height) filtered = filtered_requests max_offset = [filtered.size - visible_height, 0].max self.scroll_offset = scroll_offset.clamp(0, max_offset) end |
#adjust_scroll_for_selection(visible_height) ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/log_bench/app/state.rb', line 170 def adjust_scroll_for_selection(visible_height) return unless left_pane_focused? if selected < scroll_offset self.scroll_offset = selected elsif selected >= scroll_offset + visible_height self.scroll_offset = selected - visible_height + 1 end end |
#backspace_filter ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/log_bench/app/state.rb', line 111 def backspace_filter if main_filter.active? main_filter.remove_character elsif detail_filter.active? detail_filter.remove_character end end |
#clear_detail_filter ⇒ Object
65 66 67 68 |
# File 'lib/log_bench/app/state.rb', line 65 def clear_detail_filter detail_filter.clear self.detail_scroll_offset = 0 end |
#clear_filter ⇒ Object
59 60 61 62 63 |
# File 'lib/log_bench/app/state.rb', line 59 def clear_filter main_filter.clear self.selected = 0 self.scroll_offset = 0 end |
#current_request ⇒ Object
144 145 146 147 148 149 |
# File 'lib/log_bench/app/state.rb', line 144 def current_request filtered = filtered_requests return nil if selected >= filtered.size || filtered.empty? filtered[selected] end |
#cycle_sort_mode ⇒ Object
70 71 72 |
# File 'lib/log_bench/app/state.rb', line 70 def cycle_sort_mode sort.cycle end |
#detail_filter_mode ⇒ Object
123 124 125 |
# File 'lib/log_bench/app/state.rb', line 123 def detail_filter_mode detail_filter.active? end |
#dismiss_update_notification ⇒ Object
50 51 52 53 |
# File 'lib/log_bench/app/state.rb', line 50 def dismiss_update_notification self.update_available = false self.update_version = nil end |
#enter_filter_mode ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/log_bench/app/state.rb', line 90 def enter_filter_mode if left_pane_focused? main_filter.enter_mode else detail_filter.enter_mode end end |
#exit_filter_mode ⇒ Object
98 99 100 101 |
# File 'lib/log_bench/app/state.rb', line 98 def exit_filter_mode main_filter.exit_mode detail_filter.exit_mode end |
#filter_mode ⇒ Object
119 120 121 |
# File 'lib/log_bench/app/state.rb', line 119 def filter_mode main_filter.active? end |
#filtered_requests ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/log_bench/app/state.rb', line 127 def filtered_requests filtered = if main_filter.present? requests.select do |req| main_filter.matches?(req.path) || main_filter.matches?(req.method) || main_filter.matches?(req.controller) || main_filter.matches?(req.action) || main_filter.matches?(req.status) || main_filter.matches?(req.request_id) end else requests end sort.sort_requests(filtered) end |
#left_pane_focused? ⇒ Boolean
82 83 84 |
# File 'lib/log_bench/app/state.rb', line 82 def left_pane_focused? focused_pane == :left end |
#navigate_down ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/log_bench/app/state.rb', line 160 def navigate_down if left_pane_focused? max_index = filtered_requests.size - 1 self.selected = [selected + 1, max_index].min self.auto_scroll = false else self.detail_scroll_offset += 1 end end |
#navigate_up ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/log_bench/app/state.rb', line 151 def navigate_up if left_pane_focused? self.selected = [selected - 1, 0].max self.auto_scroll = false else self.detail_scroll_offset = [detail_scroll_offset - 1, 0].max end end |
#right_pane_focused? ⇒ Boolean
86 87 88 |
# File 'lib/log_bench/app/state.rb', line 86 def right_pane_focused? focused_pane == :right end |
#running? ⇒ Boolean
25 26 27 |
# File 'lib/log_bench/app/state.rb', line 25 def running? running end |
#set_update_available(version) ⇒ Object
45 46 47 48 |
# File 'lib/log_bench/app/state.rb', line 45 def set_update_available(version) self.update_available = true self.update_version = version end |
#stop! ⇒ Object
29 30 31 |
# File 'lib/log_bench/app/state.rb', line 29 def stop! self.running = false end |
#switch_to_left_pane ⇒ Object
74 75 76 |
# File 'lib/log_bench/app/state.rb', line 74 def switch_to_left_pane self.focused_pane = :left end |
#switch_to_right_pane ⇒ Object
78 79 80 |
# File 'lib/log_bench/app/state.rb', line 78 def switch_to_right_pane self.focused_pane = :right end |
#text_selection_mode? ⇒ Boolean
41 42 43 |
# File 'lib/log_bench/app/state.rb', line 41 def text_selection_mode? text_selection_mode end |
#toggle_auto_scroll ⇒ Object
33 34 35 |
# File 'lib/log_bench/app/state.rb', line 33 def toggle_auto_scroll self.auto_scroll = !auto_scroll end |
#toggle_text_selection_mode ⇒ Object
37 38 39 |
# File 'lib/log_bench/app/state.rb', line 37 def toggle_text_selection_mode self.text_selection_mode = !text_selection_mode end |
#update_available? ⇒ Boolean
55 56 57 |
# File 'lib/log_bench/app/state.rb', line 55 def update_available? update_available end |