Class: Wassup::Pane
- Inherits:
-
Object
- Object
- Wassup::Pane
- Defined in:
- lib/wassup/pane.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#alert_level ⇒ Object
Returns the value of attribute alert_level.
-
#caught_error ⇒ Object
Returns the value of attribute caught_error.
-
#content_block ⇒ Object
Returns the value of attribute content_block.
-
#content_thread ⇒ Object
Returns the value of attribute content_thread.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#description ⇒ Object
Returns the value of attribute description.
-
#focus_handler ⇒ Object
Returns the value of attribute focus_handler.
-
#focus_number ⇒ Object
Returns the value of attribute focus_number.
-
#focused ⇒ Object
Returns the value of attribute focused.
-
#highlight ⇒ Object
Returns the value of attribute highlight.
-
#highlighted_line ⇒ Object
Returns the value of attribute highlighted_line.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#last_content_hash ⇒ Object
Performance optimization attributes.
-
#last_focused_state ⇒ Object
Performance optimization attributes.
-
#last_highlighted_line ⇒ Object
Performance optimization attributes.
-
#last_refresh_char_at ⇒ Object
Returns the value of attribute last_refresh_char_at.
-
#last_refreshed ⇒ Object
Returns the value of attribute last_refreshed.
-
#parsed_lines_cache ⇒ Object
Performance optimization attributes.
-
#port ⇒ Object
Returns the value of attribute port.
-
#refresh_char_count ⇒ Object
Returns the value of attribute refresh_char_count.
-
#selected_view_index ⇒ Object
Returns the value of attribute selected_view_index.
-
#selection_blocks ⇒ Object
Returns the value of attribute selection_blocks.
-
#selection_blocks_description ⇒ Object
Returns the value of attribute selection_blocks_description.
-
#should_box ⇒ Object
Returns the value of attribute should_box.
-
#show_refresh ⇒ Object
Returns the value of attribute show_refresh.
-
#subwin ⇒ Object
Returns the value of attribute subwin.
-
#title ⇒ Object
Returns the value of attribute title.
-
#top ⇒ Object
Returns the value of attribute top.
-
#virtual_scroll ⇒ Object
Returns the value of attribute virtual_scroll.
-
#win ⇒ Object
Returns the value of attribute win.
-
#win_height ⇒ Object
Returns the value of attribute win_height.
-
#win_left ⇒ Object
Returns the value of attribute win_left.
-
#win_top ⇒ Object
Returns the value of attribute win_top.
-
#win_width ⇒ Object
Returns the value of attribute win_width.
Instance Method Summary collapse
- #alert_count ⇒ Object
- #close ⇒ Object
- #data_lines ⇒ Object
- #handle_keyboard ⇒ Object
- #highlight_scroll_padding ⇒ Object
-
#initialize(height, width, top, left, title: nil, description: nil, alert_level: nil, highlight: true, focus_number: nil, interval:, show_refresh:, content_block:, selection_blocks:, selection_blocks_description:, port: nil, debug: false) ⇒ Pane
constructor
A new instance of Pane.
- #load_current_view ⇒ Object
-
#load_thing ⇒ Object
Load the file into memory and put the first part on the curses display.
- #needs_refresh? ⇒ Boolean
-
#parse_line_colors(line) ⇒ Object
Cache color parsing results to avoid redundant regex operations.
- #redraw ⇒ Object
- #refresh(force: false) ⇒ Object
- #refresh_char ⇒ Object
- #refresh_content(contents) ⇒ Object
- #refreshing? ⇒ Boolean
-
#scroll_down ⇒ Object
Scroll the display down by one line.
- #scroll_left ⇒ Object
- #scroll_right ⇒ Object
-
#scroll_up ⇒ Object
Scroll the display up by one line.
- #send_to_socket ⇒ Object
- #setup_subwin ⇒ Object
- #update_box ⇒ Object
- #update_highlight(inc) ⇒ Object
- #update_refresh ⇒ Object
- #update_title ⇒ Object
- #virtual_reload ⇒ Object
- #virtual_scroll_down ⇒ Object
- #virtual_scroll_up ⇒ Object
Constructor Details
#initialize(height, width, top, left, title: nil, description: nil, alert_level: nil, highlight: true, focus_number: nil, interval:, show_refresh:, content_block:, selection_blocks:, selection_blocks_description:, port: nil, debug: false) ⇒ Pane
Returns a new instance of Pane.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/wassup/pane.rb', line 77 def initialize(height, width, top, left, title: nil, description: nil, alert_level: nil, highlight: true, focus_number: nil, interval:, show_refresh:, content_block:, selection_blocks:, selection_blocks_description:, port: nil, debug: false) self.port = port if !debug self.win_height = Curses.lines * height self.win_width = Curses.cols * width self.win_top = Curses.lines * top self.win_left = Curses.cols * left self.win = Curses::Window.new(self.win_height, self.win_width, self.win_top, self.win_left) self.setup_subwin() end self.focused = false self.focus_number = focus_number self.highlight = highlight self.virtual_scroll = true self.top = 0 self.contents = [] self.show_refresh = show_refresh self.selected_view_index = 0 # Initialize performance optimization attributes self.last_content_hash = nil self.last_highlighted_line = nil self.last_focused_state = nil self.parsed_lines_cache = {} if !debug self.win.refresh self.subwin.refresh end self.title = title self.description = description self.alert_level = alert_level self.interval = interval self.content_block = content_block self.selection_blocks = selection_blocks || {} self.selection_blocks_description = selection_blocks_description || {} end |
Instance Attribute Details
#alert_level ⇒ Object
Returns the value of attribute alert_level.
17 18 19 |
# File 'lib/wassup/pane.rb', line 17 def alert_level @alert_level end |
#caught_error ⇒ Object
Returns the value of attribute caught_error.
37 38 39 |
# File 'lib/wassup/pane.rb', line 37 def caught_error @caught_error end |
#content_block ⇒ Object
Returns the value of attribute content_block.
33 34 35 |
# File 'lib/wassup/pane.rb', line 33 def content_block @content_block end |
#content_thread ⇒ Object
Returns the value of attribute content_thread.
39 40 41 |
# File 'lib/wassup/pane.rb', line 39 def content_thread @content_thread end |
#contents ⇒ Object
Returns the value of attribute contents.
12 13 14 |
# File 'lib/wassup/pane.rb', line 12 def contents @contents end |
#description ⇒ Object
Returns the value of attribute description.
15 16 17 |
# File 'lib/wassup/pane.rb', line 15 def description @description end |
#focus_handler ⇒ Object
Returns the value of attribute focus_handler.
29 30 31 |
# File 'lib/wassup/pane.rb', line 29 def focus_handler @focus_handler end |
#focus_number ⇒ Object
Returns the value of attribute focus_number.
20 21 22 |
# File 'lib/wassup/pane.rb', line 20 def focus_number @focus_number end |
#focused ⇒ Object
Returns the value of attribute focused.
19 20 21 |
# File 'lib/wassup/pane.rb', line 19 def focused @focused end |
#highlight ⇒ Object
Returns the value of attribute highlight.
26 27 28 |
# File 'lib/wassup/pane.rb', line 26 def highlight @highlight end |
#highlighted_line ⇒ Object
Returns the value of attribute highlighted_line.
24 25 26 |
# File 'lib/wassup/pane.rb', line 24 def highlighted_line @highlighted_line end |
#interval ⇒ Object
Returns the value of attribute interval.
31 32 33 |
# File 'lib/wassup/pane.rb', line 31 def interval @interval end |
#last_content_hash ⇒ Object
Performance optimization attributes
49 50 51 |
# File 'lib/wassup/pane.rb', line 49 def last_content_hash @last_content_hash end |
#last_focused_state ⇒ Object
Performance optimization attributes
49 50 51 |
# File 'lib/wassup/pane.rb', line 49 def last_focused_state @last_focused_state end |
#last_highlighted_line ⇒ Object
Performance optimization attributes
49 50 51 |
# File 'lib/wassup/pane.rb', line 49 def last_highlighted_line @last_highlighted_line end |
#last_refresh_char_at ⇒ Object
Returns the value of attribute last_refresh_char_at.
330 331 332 |
# File 'lib/wassup/pane.rb', line 330 def last_refresh_char_at @last_refresh_char_at end |
#last_refreshed ⇒ Object
Returns the value of attribute last_refreshed.
32 33 34 |
# File 'lib/wassup/pane.rb', line 32 def last_refreshed @last_refreshed end |
#parsed_lines_cache ⇒ Object
Performance optimization attributes
49 50 51 |
# File 'lib/wassup/pane.rb', line 49 def parsed_lines_cache @parsed_lines_cache end |
#port ⇒ Object
Returns the value of attribute port.
46 47 48 |
# File 'lib/wassup/pane.rb', line 46 def port @port end |
#refresh_char_count ⇒ Object
Returns the value of attribute refresh_char_count.
307 308 309 |
# File 'lib/wassup/pane.rb', line 307 def refresh_char_count @refresh_char_count end |
#selected_view_index ⇒ Object
Returns the value of attribute selected_view_index.
42 43 44 |
# File 'lib/wassup/pane.rb', line 42 def selected_view_index @selected_view_index end |
#selection_blocks ⇒ Object
Returns the value of attribute selection_blocks.
34 35 36 |
# File 'lib/wassup/pane.rb', line 34 def selection_blocks @selection_blocks end |
#selection_blocks_description ⇒ Object
Returns the value of attribute selection_blocks_description.
35 36 37 |
# File 'lib/wassup/pane.rb', line 35 def selection_blocks_description @selection_blocks_description end |
#should_box ⇒ Object
Returns the value of attribute should_box.
22 23 24 |
# File 'lib/wassup/pane.rb', line 22 def should_box @should_box end |
#show_refresh ⇒ Object
Returns the value of attribute show_refresh.
40 41 42 |
# File 'lib/wassup/pane.rb', line 40 def show_refresh @show_refresh end |
#subwin ⇒ Object
Returns the value of attribute subwin.
9 10 11 |
# File 'lib/wassup/pane.rb', line 9 def subwin @subwin end |
#title ⇒ Object
Returns the value of attribute title.
14 15 16 |
# File 'lib/wassup/pane.rb', line 14 def title @title end |
#top ⇒ Object
Returns the value of attribute top.
10 11 12 |
# File 'lib/wassup/pane.rb', line 10 def top @top end |
#virtual_scroll ⇒ Object
Returns the value of attribute virtual_scroll.
27 28 29 |
# File 'lib/wassup/pane.rb', line 27 def virtual_scroll @virtual_scroll end |
#win ⇒ Object
Returns the value of attribute win.
8 9 10 |
# File 'lib/wassup/pane.rb', line 8 def win @win end |
#win_height ⇒ Object
Returns the value of attribute win_height.
44 45 46 |
# File 'lib/wassup/pane.rb', line 44 def win_height @win_height end |
#win_left ⇒ Object
Returns the value of attribute win_left.
44 45 46 |
# File 'lib/wassup/pane.rb', line 44 def win_left @win_left end |
#win_top ⇒ Object
Returns the value of attribute win_top.
44 45 46 |
# File 'lib/wassup/pane.rb', line 44 def win_top @win_top end |
#win_width ⇒ Object
Returns the value of attribute win_width.
44 45 46 |
# File 'lib/wassup/pane.rb', line 44 def win_width @win_width end |
Instance Method Details
#alert_count ⇒ Object
361 362 363 364 365 366 367 368 |
# File 'lib/wassup/pane.rb', line 361 def alert_count alert_count = 0 if self.contents alert_count = self.contents.map { |c| c.data.size }.inject(0, :+) end return alert_count end |
#close ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/wassup/pane.rb', line 164 def close unless self.subwin.nil? self.subwin.clear self.subwin.close end self.win.clear self.win.close end |
#data_lines ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/wassup/pane.rb', line 188 def data_lines return [] if self.selected_view_index.nil? content = (self.contents || [])[self.selected_view_index] if content.nil? return [] else content.data.map(&:display) end end |
#handle_keyboard ⇒ Object
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/wassup/pane.rb', line 656 def handle_keyboard input = self.subwin.getch unless focus_handler.nil? handled = focus_handler.call(input) return if handled end if input == "j" if virtual_scroll self.virtual_scroll_down else scroll_down end elsif input == "k" if virtual_scroll self.virtual_scroll_up else scroll_up end elsif input == "h" self.scroll_left elsif input == "l" self.scroll_right elsif input == "r" self.refresh(force: true) elsif input == "c" if !self.caught_error.nil? text = self.caught_error.backtrace.join("\n") if RUBY_PLATFORM.downcase =~ /win32/ IO.popen('clip', 'w') { |pipe| pipe.puts text } else IO.popen('pbcopy', 'w') { |pipe| pipe.puts text } end end else selection_block = self.selection_blocks[input] if !selection_block.nil? && !self.highlighted_line.nil? content = self.contents[self.selected_view_index] row = content.data[self.highlighted_line] data = row.object || row.display selection_block.call(data) end end end |
#highlight_scroll_padding ⇒ Object
564 565 566 |
# File 'lib/wassup/pane.rb', line 564 def highlight_scroll_padding return (self.subwin.maxy * 0.3).to_i end |
#load_current_view ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/wassup/pane.rb', line 286 def load_current_view self.setup_subwin() # this might be bad self.highlighted_line = nil self.virtual_reload() end |
#load_thing ⇒ Object
Load the file into memory and put the first part on the curses display.
442 443 444 445 446 447 448 449 |
# File 'lib/wassup/pane.rb', line 442 def load_thing self.data_lines[0..self.subwin.maxy-1].each_with_index do |line, idx| self.subwin.setpos(idx, 0) self.subwin.addstr(line) end self.subwin.setpos(0, 0) self.subwin.refresh end |
#needs_refresh? ⇒ Boolean
174 175 176 177 178 179 |
# File 'lib/wassup/pane.rb', line 174 def needs_refresh? return false if self.content_block.nil? return false if self.interval.nil? return true if self.last_refreshed.nil? return Time.now - self.interval > self.last_refreshed end |
#parse_line_colors(line) ⇒ Object
Cache color parsing results to avoid redundant regex operations
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/wassup/pane.rb', line 452 def parse_line_colors(line) return self.parsed_lines_cache[line] if self.parsed_lines_cache.key?(line) splits = line.split(/\[.*?\]/) # returns ["hey something", "other thing", "okay"] scans = line.scan(/\[.*?\]/) #returns ["red", "white"] scans = scans.map do |str| if str.start_with?('[fg=') str = str.gsub('[fg=', '').gsub(']','') Wassup::Color.new(str) else str end end all_parts = splits.zip(scans).flatten.compact # Cache the result self.parsed_lines_cache[line] = all_parts # Limit cache size to prevent memory bloat if self.parsed_lines_cache.size > 1000 # Remove oldest entries (keep most recent 500) self.parsed_lines_cache = self.parsed_lines_cache.to_a.last(500).to_h end all_parts end |
#redraw ⇒ Object
203 204 205 206 207 |
# File 'lib/wassup/pane.rb', line 203 def redraw self.update_box self.update_title self.load_current_view() end |
#refresh(force: false) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/wassup/pane.rb', line 209 def refresh(force: false) if force self.last_refreshed = nil end if !needs_refresh? return end thread = self.content_thread if !thread.nil? if thread.status == "sleep" || thread.status == "run" || thread.status == "aborting" self.update_refresh return elsif thread.status == nil return elsif thread.status == false rtn = thread.value if rtn.is_a?(Ope) self.caught_error = rtn.error content = Wassup::Pane::Content.new("Overview") content.add_row("[fg=red]#{rtn.error.}[fg=while]") content.add_row("") content.add_row("[fg=gray]Error at #{Time.now}[fg=while]") content_directions = Wassup::Pane::Content.new("Directions") content_directions.add_row("1. Press 'c' to copy the stacktrace") content_directions.add_row("2. Debug pane content block with:") content_directions.add_row(" $: wassup --debug") content_directions.add_row("3. Stacktrace viewable in next page") content_stacktrace = Wassup::Pane::Content.new("Stacktrace") rtn.error.backtrace.each do |line| content_stacktrace.add_row(line) end self.refresh_content([content, content_directions, content_stacktrace]) elsif rtn.is_a?(Wassup::PaneBuilder::ContentBuilder) self.caught_error = nil self.refresh_content(rtn.contents) end self.update_box self.update_title self.send_to_socket else # This shouldn't happen # TODO: also fix this return end else the_block = self.content_block self.content_thread = Thread.new { begin builder = Wassup::PaneBuilder::ContentBuilder.new(self.contents) content = the_block.call(builder) builder rescue => ex next Ope.new(ex) end } self.update_box self.update_title end end |
#refresh_char ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/wassup/pane.rb', line 308 def refresh_char return "" unless self.show_refresh if self.refresh_char_count.nil? self.refresh_char_count = 0 end if self.refreshing? array = ['\\', '|', '/', '|'] rtn = array[self.refresh_char_count] self.refresh_char_count += 1 if self.refresh_char_count >= array.size self.refresh_char_count = 0 end return rtn else return "" end end |
#refresh_content(contents) ⇒ Object
277 278 279 280 281 282 283 284 |
# File 'lib/wassup/pane.rb', line 277 def refresh_content(contents) self.contents = contents self.load_current_view() self.last_refreshed = Time.now self.content_thread = nil end |
#refreshing? ⇒ Boolean
199 200 201 |
# File 'lib/wassup/pane.rb', line 199 def refreshing? return !self.content_thread.nil? end |
#scroll_down ⇒ Object
Scroll the display down by one line.
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/wassup/pane.rb', line 639 def scroll_down if self.top + self.subwin.maxy < self.data_lines.length self.subwin.scrl(1) self.top += 1 str = self.data_lines[self.top + self.subwin.maxy - 1] if str self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) self.subwin.setpos(self.subwin.maxy - 1, 0) self.subwin.addstr(str) self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) end return true else return false end end |
#scroll_left ⇒ Object
604 605 606 607 608 609 610 611 |
# File 'lib/wassup/pane.rb', line 604 def scroll_left self.selected_view_index -= 1 if self.selected_view_index < 0 self.selected_view_index = self.contents.size - 1 end self.load_current_view end |
#scroll_right ⇒ Object
613 614 615 616 617 618 619 620 |
# File 'lib/wassup/pane.rb', line 613 def scroll_right self.selected_view_index += 1 if self.selected_view_index >= self.contents.size self.selected_view_index = 0 end self.load_current_view end |
#scroll_up ⇒ Object
Scroll the display up by one line.
623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/wassup/pane.rb', line 623 def scroll_up if self.top > 0 self.subwin.scrl(-1) self.top -= 1 str = self.data_lines[top] if str self.subwin.setpos(0, 0) self.subwin.addstr(str) end return true else return false end end |
#send_to_socket ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/wassup/pane.rb', line 345 def send_to_socket return if self.port.nil? return if self.port.to_i == 0 data = { title: self.title, description: self.description, alert_level: self.alert_level, alert_count: self.alert_count } sock = TCPSocket.new('127.0.0.1', self.port) sock.write(data.to_json) sock.close end |
#setup_subwin ⇒ Object
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 |
# File 'lib/wassup/pane.rb', line 126 def setup_subwin top_bump = 0 unless self.subwin.nil? self.subwin.clear() self.subwin.close() self.subwin = nil end if (self.contents || []).size > 1 top_bump = 4 view_title = self.contents[self.selected_view_index].title || "<No Title>" view_title += " " * 100 self.win.setpos(2, 2) self.win.addstr(view_title[0...self.win.maxx()-3]) subtitle = "(#{self.selected_view_index + 1} out of #{self.contents.size})" subtitle += " " * 100 self.win.setpos(3, 2) self.win.addstr(subtitle[0...self.win.maxx()-3]) self.win.refresh end if self.win_height == 0 self.should_box = false self.subwin = self.win.subwin(0, 0, 0, 0) else self.should_box = true self.subwin = self.win.subwin(self.win_height - 2 - top_bump, self.win_width - 4, self.win_top + 1 + top_bump, self.win_left + 2) end self.subwin.nodelay=true self.subwin.idlok(true) self.subwin.scrollok(true) end |
#update_box ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/wassup/pane.rb', line 424 def update_box return unless self.should_box show_focused = self.focused if self.focus_number.nil? show_focused = true end self.win.attrset(show_focused ? Curses.color_pair(Wassup::Color::Pair::BORDER_FOCUS) : Curses.color_pair(Wassup::Color::Pair::BORDER)) self.win.box() self.win.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) self.win.refresh end |
#update_highlight(inc) ⇒ Object
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/wassup/pane.rb', line 581 def update_highlight(inc) return unless self.highlight prev = self.highlighted_line new = nil if prev.nil? new = 0 elsif inc.nil? new = nil elsif !inc.nil? new = prev + inc end if new < 0 || new >= self.data_lines.size new = prev end self.highlighted_line = new return new end |
#update_refresh ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/wassup/pane.rb', line 331 def update_refresh return unless self.should_box self.last_refresh_char_at ||= Time.now if Time.now - self.last_refresh_char_at >= 0.25 self.win.setpos(0, 1) self.win.addstr(self.refresh_char) self.win.refresh self.last_refresh_char_at = Time.now end end |
#update_title ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/wassup/pane.rb', line 370 def update_title return unless self.should_box title = self.title || "<No Title>" if self.focus_number.nil? full_title = title else full_title = "#{self.focus_number} - #{title}" end full_title += " " self.win.setpos(0, 3) self.win.addstr(full_title) self.win.setpos(0, 3 + full_title.size) alert = "" alert_count = self.alert_count case self.alert_level when AlertLevel::HIGH self.win.attrset(Curses.color_pair(Wassup::Color::Pair::RED)) if alert_count == 1 alert += "(#{alert_count} HIGH ALERT)" elsif alert_count > 0 alert += "(#{alert_count} HIGH ALERTS)" end when AlertLevel::MEDIUM self.win.attrset(Curses.color_pair(Wassup::Color::Pair::YELLOW)) if alert_count == 1 alert += "(#{alert_count} MEDIUM ALERT)" elsif alert_count > 0 alert += "(#{alert_count} MEDIUM ALERTS)" end when AlertLevel::LOW self.win.attrset(Curses.color_pair(Wassup::Color::Pair::CYAN)) if alert_count == 1 alert += "(#{alert_count} LOW ALERT)" elsif alert_count > 0 alert += "(#{alert_count} LOW ALERTS)" end end self.win.addstr(alert) self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) self.win.refresh end |
#virtual_reload ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/wassup/pane.rb', line 480 def virtual_reload return if self.data_lines.nil? || self.data_lines.empty? # Skip optimization for first-time loads or if optimization attributes aren't initialized if self.last_content_hash.nil? || self.last_highlighted_line.nil? || self.last_focused_state.nil? # Initialize on first run and force redraw self.last_content_hash = self.data_lines.hash self.last_highlighted_line = self.highlighted_line self.last_focused_state = self.focused else # Check if content has changed to avoid unnecessary redraws current_content_hash = self.data_lines.hash highlight_changed = self.last_highlighted_line != self.highlighted_line focus_changed = self.last_focused_state != self.focused if current_content_hash == self.last_content_hash && !highlight_changed && !focus_changed return # No changes, skip redraw end # Track what changed for next time self.last_content_hash = current_content_hash self.last_highlighted_line = self.highlighted_line self.last_focused_state = self.focused end # TODO: This errored out but might be because thread stuff??? self.data_lines[self.top..(self.top+self.subwin.maxy-1)].each_with_index do |line, idx| write_full_line = false should_highlight = self.focused && self.highlight && (idx + self.top) == self.highlighted_line max_char = self.subwin.maxx()-3 self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) # Use cached color parsing instead of expensive regex operations all_parts = parse_line_colors(line) char_count = 0 if should_highlight self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::HIGHLIGHT)) end all_parts.each do |part| if part.is_a?(Wassup::Color) #color = Curses.color_pair([1,2,3,4].sample) if !should_highlight self.subwin.attrset(Curses.color_pair(part.color_pair)) end else new_char_count = char_count + part.size if new_char_count >= max_char part = part[0...(max_char - char_count)] end self.subwin.setpos(idx, char_count) self.subwin.addstr(part) char_count += part.size end end self.subwin.attrset(Curses.color_pair(Wassup::Color::Pair::NORMAL)) self.subwin.clrtoeol() end self.subwin.refresh end |
#virtual_scroll_down ⇒ Object
550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/wassup/pane.rb', line 550 def virtual_scroll_down self.update_highlight(1) bottom = self.top + self.subwin.maxy if bottom < self.data_lines.size # only move highlight and dont scroll if near top if !self.highlight || self.highlighted_line > highlight_scroll_padding self.top += 1 end end self.virtual_reload end |
#virtual_scroll_up ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/wassup/pane.rb', line 568 def virtual_scroll_up self.update_highlight(-1) if self.top > 0 # only move highlight and dont scroll if near bottom if !self.highlight || (self.data_lines.size - self.highlighted_line) >= highlight_scroll_padding self.top -= 1 end end self.virtual_reload end |