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,
lib/cryptum/ui/order_plan_details.rb,
lib/cryptum/ui/order_execute_details.rb
Overview
This plugin is used to Refresh the Cryptum console UI
Defined Under Namespace
Modules: Command, MarketTrend, OrderExecuteDetails, OrderExecution, OrderPlan, OrderPlanDetails, 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
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/cryptum/ui.rb', line 213 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
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/cryptum/ui.rb', line 227 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
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/cryptum/ui.rb', line 263 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
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/cryptum/ui.rb', line 239 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
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/cryptum/ui.rb', line 251 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
115 116 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 205 206 207 208 209 210 |
# File 'lib/cryptum/ui.rb', line 115 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 # It's more Gray than Black # color_id = 0 # color_fg = Curses::COLOR_BLACK color_id = 256 Curses.init_color(color_id, 0, 0, 500) color_fg = color_id 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
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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/cryptum/ui.rb', line 274 public_class_method def self.detect_key_press_in_ui(opts = {}) key_press_event = opts[:key_press_event] ui_win = opts[:ui_win] key_press = ui_win.get_char # Useful for detecting and logging actual key presses to file # unless key_press.nil? # File.open('/tmp/detect_key_press_in_ui-cryptum.txt', 'a') do |f| # f.puts key_press.class # f.print key_press.inspect # f.puts "\n\n\n" # end # end case key_press when 'C' key_press_event.key_c = true 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 when "\e" key_press_event.key_esc = true when "\n" key_press_event.key_enter = true when "\t" key_press_event.key_tab = true end # What a hack to detect special keys (-.-) if key_press_event.key_esc key_press_event.key_ansi = true if key_press == '[' if key_press_event.key_ansi key_press_event.key_up_arrow = true if key_press == 'A' key_press_event.key_down_arrow = true if key_press == 'B' # NOTE: the ~ at the end of these keys are ignored # which may result in other keys working in place of them # e.g. home is \e[1~ but we know it's home as soon as # \e[1 is detected. key_press_event.key_page_up = true if key_press == '5' key_press_event.key_page_down = true if key_press == '6' key_press_event.key_home = true if key_press == '1' key_press_event.key_end = true if key_press == '4' end 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
339 340 341 |
# File 'lib/cryptum/ui.rb', line 339 public_class_method def self.help constants.sort end |
.init ⇒ Object
Initialize the UI
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 60 61 |
# File 'lib/cryptum/ui.rb', line 24 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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cryptum/ui.rb', line 89 public_class_method def self.line(opts = {}) ui_win = opts[:ui_win] out_line_no = opts[:out_line_no].to_i color = opts[:color] color ||= :white style = :normal style = :bold unless color == :white ui_win.setpos(out_line_no, 0) colorize( ui_win: ui_win, color: color, style: style, string: "\u2500" * Curses.cols ) 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cryptum/ui.rb', line 64 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 |