Module: Cryptum::UI
- Defined in:
- lib/cryptum/ui.rb,
lib/cryptum/ui/ticker.rb,
lib/cryptum/ui/command.rb,
lib/cryptum/ui/portfolio.rb,
lib/cryptum/ui/order_plan.rb,
lib/cryptum/ui/order_timer.rb,
lib/cryptum/ui/market_trend.rb,
lib/cryptum/ui/signal_engine.rb,
lib/cryptum/ui/key_press_event.rb,
lib/cryptum/ui/order_execution.rb,
lib/cryptum/ui/terminal_window.rb
Overview
This plugin is used to Refresh the Cryptum console UI
Defined Under Namespace
Modules: Command, MarketTrend, OrderExecution, OrderPlan, OrderTimer, Portfolio, SignalEngine, Ticker Classes: KeyPressEvent, TerminalWindow
Class Method Summary collapse
-
.col_center(opts = {}) ⇒ Object
Jump to First Column.
- .col_first ⇒ Object
-
.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_center(opts = {}) ⇒ Object
Jump to First Column
212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/cryptum/ui.rb', line 212 public_class_method def self.col_center(opts = {}) str = opts[:str] str_divided_by_two = str.length / 2 (Curses.cols / 2) - str_divided_by_two rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.col_first ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/cryptum/ui.rb', line 226 public_class_method def self.col_first 0 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.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
262 263 264 265 266 267 268 269 270 271 |
# File 'lib/cryptum/ui.rb', line 262 public_class_method def self.col_fourth ((Curses.cols / 4) * 3) - 3 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.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
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/cryptum/ui.rb', line 238 public_class_method def self.col_second (Curses.cols / 8) + 5 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.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
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/cryptum/ui.rb', line 250 public_class_method def self.col_third ((Curses.cols / 8) * 3) + 2 rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.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
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 205 206 207 208 209 |
# File 'lib/cryptum/ui.rb', line 118 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 :blink font = Curses::A_BLINK when :bold font = Curses::A_BOLD when :highlight font = Curses::A_STANDOUT when :normal font = Curses::A_NORMAL when :reverse font = Curses::A_REVERSE 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 Cryptum.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
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/cryptum/ui.rb', line 273 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 'G' key_press_event.key_g = true 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 Cryptum.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
302 303 304 |
# File 'lib/cryptum/ui.rb', line 302 public_class_method def self.help constants.sort end |
.init ⇒ Object
Initialize the UI
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 59 |
# File 'lib/cryptum/ui.rb', line 22 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 Cryptum modules Cryptum::UI::TerminalWindow.new rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.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
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 |
# File 'lib/cryptum/ui.rb', line 87 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 Cryptum.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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cryptum/ui.rb', line 62 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 Cryptum.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |