Class: RubyJard::ScreenManager
- Inherits:
-
Object
- Object
- RubyJard::ScreenManager
- Extended by:
- Forwardable
- Defined in:
- lib/ruby_jard/screen_manager.rb
Overview
This class acts as a coordinator, in which it combines the data and screen layout template, triggers each screen to draw on the terminal.
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#output_storage ⇒ Object
readonly
Returns the value of attribute output_storage.
Class Method Summary collapse
Instance Method Summary collapse
- #click ⇒ Object
- #draw_error(exception, height = 0) ⇒ Object
- #draw_screens ⇒ Object
-
#initialize(output: RubyJard::Console.output) ⇒ ScreenManager
constructor
A new instance of ScreenManager.
- #scroll ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #updating? ⇒ Boolean
Constructor Details
#initialize(output: RubyJard::Console.output) ⇒ ScreenManager
Returns a new instance of ScreenManager.
41 42 43 44 45 46 |
# File 'lib/ruby_jard/screen_manager.rb', line 41 def initialize(output: RubyJard::Console.output) @output = output @screens = {} @started = false @updating = false end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
39 40 41 |
# File 'lib/ruby_jard/screen_manager.rb', line 39 def output @output end |
#output_storage ⇒ Object (readonly)
Returns the value of attribute output_storage.
39 40 41 |
# File 'lib/ruby_jard/screen_manager.rb', line 39 def output_storage @output_storage end |
Class Method Details
.instance ⇒ Object
34 35 36 |
# File 'lib/ruby_jard/screen_manager.rb', line 34 def instance @instance ||= new end |
Instance Method Details
#click ⇒ Object
113 |
# File 'lib/ruby_jard/screen_manager.rb', line 113 def click; end |
#draw_error(exception, height = 0) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ruby_jard/screen_manager.rb', line 115 def draw_error(exception, height = 0) @output.print RubyJard::Decorators::ColorDecorator::CSI_RESET @output.puts '--- Error ---' @output.puts "Internal error from Jard. I'm sorry to mess up your debugging experience." @output.puts 'It would be great if you can submit an issue in https://github.com/nguyenquangminh0711/ruby_jard/issues' @output.puts '' @output.puts exception if height == 0 @output.puts exception.backtrace else @output.puts exception.backtrace.first(10) end @output.puts '-------------' RubyJard.error(exception) end |
#draw_screens ⇒ Object
76 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 |
# File 'lib/ruby_jard/screen_manager.rb', line 76 def draw_screens start unless started? @updating = true RubyJard::Console.clear_screen(@output) RubyJard::Console.disable_cursor!(@output) width, height = RubyJard::Console.screen_size(@output) @layouts = calculate_layouts(width, height) @screens = build_screens(@layouts) RubyJard::Console.move_to(@output, 0, 0) draw_box(@screens) @screens.each do |screen| RubyJard::ScreenDrawer.new( output: @output, screen: screen, color_scheme: pick_color_scheme ).draw end RubyJard::Console.move_to(@output, 0, total_screen_height(@layouts) + 1) RubyJard::Console.clear_screen_to_end(@output) rescue StandardError => e RubyJard::Console.clear_screen(@output) draw_error(e, height) ensure # You don't want to mess up previous user TTY no matter happens RubyJard::Console.cooked!(@output) RubyJard::Console.enable_echo!(@output) RubyJard::Console.enable_cursor!(@output) @updating = false end |
#scroll ⇒ Object
111 |
# File 'lib/ruby_jard/screen_manager.rb', line 111 def scroll; end |
#start ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby_jard/screen_manager.rb', line 48 def start return if started? # Load configurations RubyJard.config RubyJard::Console.clear_screen(@output) @started = true end |
#started? ⇒ Boolean
58 59 60 |
# File 'lib/ruby_jard/screen_manager.rb', line 58 def started? @started == true end |
#stop ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_jard/screen_manager.rb', line 66 def stop return unless started? @started = false RubyJard::Console.cooked!(@output) RubyJard::Console.enable_echo!(@output) RubyJard::Console.enable_cursor!(@output) end |
#updating? ⇒ Boolean
62 63 64 |
# File 'lib/ruby_jard/screen_manager.rb', line 62 def updating? @updating == true end |