Module: Coinbot::UI
- Defined in:
- lib/coinbot/ui.rb,
lib/coinbot/ui/timer.rb,
lib/coinbot/ui/candle.rb,
lib/coinbot/ui/status.rb,
lib/coinbot/ui/ticker.rb,
lib/coinbot/ui/command.rb,
lib/coinbot/ui/summary.rb,
lib/coinbot/ui/portfolio.rb,
lib/coinbot/ui/key_press_event.rb,
lib/coinbot/ui/terminal_window.rb,
lib/coinbot/ui/action_probability.rb
Overview
This plugin is used to Refresh the Coinbot console UI
Defined Under Namespace
Modules: ActionProbability, Candle, Command, Portfolio, Status, Summary, Ticker, Timer Classes: KeyPressEvent, TerminalWindow
Class Method Summary collapse
-
.col_first ⇒ Object
Jump to First Column.
-
.col_fourth ⇒ Object
Jump to Fourth Column.
-
.col_second ⇒ Object
Jump to Second Column.
-
.col_third ⇒ Object
Jump to Third Column.
-
.colorize(opts = {}) ⇒ Object
Jump to First Column.
- .detect_key_press_in_ui(opts = {}) ⇒ Object
-
.help ⇒ Object
Display a List of Every UI Module.
-
.init ⇒ Object
Initialize the UI.
-
.line(opts = {}) ⇒ Object
Draw a Box Around a Window.
-
.window(opts = {}) ⇒ Object
Create New Curses Window.
Class Method Details
.col_first ⇒ Object
Jump to First Column
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/coinbot/ui.rb', line 207 public_class_method def self.col_first 0 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.col_fourth ⇒ Object
Jump to Fourth Column
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/coinbot/ui.rb', line 243 public_class_method def self.col_fourth ((Curses.cols / 4) * 3) - 3 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.col_second ⇒ Object
Jump to Second Column
219 220 221 222 223 224 225 226 227 228 |
# File 'lib/coinbot/ui.rb', line 219 public_class_method def self.col_second (Curses.cols / 8) + 5 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.col_third ⇒ Object
Jump to Third Column
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/coinbot/ui.rb', line 231 public_class_method def self.col_third ((Curses.cols / 8) * 3) + 2 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.colorize(opts = {}) ⇒ Object
Jump to First Column
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/coinbot/ui.rb', line 117 public_class_method def self.colorize(opts = {}) ui_win = opts[:ui_win] color = opts[:color].to_s.to_sym red = opts[:red].to_i green = opts[:green].to_i blue = opts[:blue].to_i style = opts[:style].to_s.to_sym style = :normal if opts[:style].nil? bg = opts[:bg].to_i bg = -1 if opts[:bg].nil? string = opts[:string] case color when :black color_id = 0 color_fg = Curses::COLOR_BLACK color_bg = bg when :red color_id = 1 color_fg = Curses::COLOR_RED color_bg = bg when :green color_id = 2 color_fg = Curses::COLOR_GREEN color_bg = bg when :yellow color_id = 3 color_fg = Curses::COLOR_YELLOW color_bg = bg when :blue color_id = 4 color_fg = Curses::COLOR_BLUE color_bg = bg when :magenta color_id = 5 color_fg = Curses::COLOR_MAGENTA color_bg = bg when :cyan color_id = 6 color_fg = Curses::COLOR_CYAN color_bg = bg when :white color_id = 7 color_fg = Curses::COLOR_WHITE color_bg = bg when :rainbow color_id = 254 red = Random.rand(0..1000) green = Random.rand(0..1000) blue = Random.rand(0..1000) Curses.init_color(color_id, red, green, blue) color_fg = color_id color_bg = bg when :custom color_id = 255 Curses.init_color(color_id, red, green, blue) color_fg = color_id color_bg = bg else raise "Color Not Implemented for this Method: #{color}" end case style when :bold font = Curses::A_BOLD when :reverse font = Curses::A_REVERSE when :normal font = Curses::A_NORMAL else raise "Font Style Not Implemented for this Method: #{style}" end Curses.init_pair(color_id, color_fg, color_bg) ui_win.attron(Curses.color_pair(color_id) | font) do ui_win.addstr(string) end rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.detect_key_press_in_ui(opts = {}) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/coinbot/ui.rb', line 254 public_class_method def self.detect_key_press_in_ui(opts = {}) key_press_event = opts[:key_press_event] ui_win = opts[:ui_win] case ui_win.getch when 'r' key_press_event.key_r = true when 'u' key_press_event.key_u = true when 'w' key_press_event.key_w = true when 'x' key_press_event.key_x = true end key_press_event rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.help ⇒ Object
Display a List of Every UI Module
281 282 283 |
# File 'lib/coinbot/ui.rb', line 281 public_class_method def self.help constants.sort end |
.init ⇒ Object
Initialize the UI
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/coinbot/ui.rb', line 21 public_class_method def self.init # Initialize curses Screen Curses.init_screen # Ensure the cursor is invisible Curses.curs_set(0) # Do not echo keystrokes back to the UI Curses.noecho # Used to immediately evaluate characters submitted # without pressing ENTER (e.g. b, r, & w key events) Curses.crmode # Curses.nocrmode # Curses.raw # NO # Curses.noraw # Disable Line Buffering Curses.ESCDELAY = 0 # Start Color! Curses.start_color # This is important to ensure -1 maintains # the original background color in the terminal # when defining color pairs Curses.use_default_colors # This object is used to pass all of the UI sections # around to various Coinbot modules Coinbot::UI::TerminalWindow.new rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.line(opts = {}) ⇒ Object
Draw a Box Around a Window
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 |
# File 'lib/coinbot/ui.rb', line 86 public_class_method def self.line(opts = {}) ui_win = opts[:ui_win] out_line_no = opts[:out_line_no].to_i ui_win.setpos(out_line_no, 0) if Curses.can_change_color? colorize( ui_win: ui_win, color: :custom, red: 192, green: 192, blue: 192, string: "\u2500" * Curses.cols ) else colorize( ui_win: ui_win, color: :white, string: "\u2500" * Curses.cols ) end rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.window(opts = {}) ⇒ Object
Create New Curses Window
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/coinbot/ui.rb', line 61 public_class_method def self.window(opts = {}) height = opts[:height].to_i width = opts[:width].to_i top = opts[:top].to_i left = opts[:left].to_i window = Curses::Window.new( height, width, top, left ) window.nodelay = true window rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |