# frozen_string_literal: true module Cryptum # Cryptum::Event Namespace module Event # This Module is used to Scroll through # Order Plan and Order History Window Panes module Scroll # Supported Method Parameters:: # Cryptum::Event::Scroll.up( # ) public_class_method def self.up(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_up_arrow = false if event_history.order_plan_win_active event_history.order_plan_row_to_select -= 1 event_history.order_plan_index_offset -= 1 if event_history.order_plan_row_to_select.negative? event_history.order_plan_index_offset = 0 if event_history.order_plan_index_offset.negative? event_history.order_plan_row_to_select = 0 if event_history.order_plan_row_to_select.negative? end if event_history.order_execute_win_active event_history.order_execute_row_to_select -= 1 event_history.order_execute_index_offset -= 1 if event_history.order_execute_row_to_select.negative? event_history.order_execute_index_offset = 0 if event_history.order_execute_index_offset.negative? event_history.order_execute_row_to_select = 0 if event_history.order_execute_row_to_select.negative? end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Supported Method Parameters:: # Cryptum::Event::Scroll.down( # ) public_class_method def self.down(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_down_arrow = false order_book = event_history.order_book if event_history.order_plan_win_active order_plan_length = order_book[:order_plan].length last_row = order_plan_length - 1 event_history.order_plan_max_records_available_to_display = last_row if last_row < event_history.order_plan_max_rows_to_display event_history.order_plan_row_to_select += 1 event_history.order_plan_index_offset += 1 if event_history.order_plan_row_to_select > event_history.order_plan_max_records_available_to_display event_history.order_plan_row_to_select = event_history.order_plan_max_records_available_to_display if event_history.order_plan_row_to_select > event_history.order_plan_max_records_available_to_display end if event_history.order_execute_win_active order_history_meta_length = order_book[:order_history_meta].length last_row = order_history_meta_length - 1 event_history.order_execute_max_records_available_to_display = last_row if last_row < event_history.order_execute_max_rows_to_display event_history.order_execute_row_to_select += 1 event_history.order_execute_index_offset += 1 if event_history.order_execute_row_to_select > event_history.order_execute_max_records_available_to_display event_history.order_execute_row_to_select = event_history.order_execute_max_records_available_to_display if event_history.order_execute_row_to_select > event_history.order_execute_max_records_available_to_display end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Supported Method Parameters:: # Cryptum::Event::Scroll.page_up( # ) public_class_method def self.page_up(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_page_up = false if event_history.order_plan_win_active event_history.order_plan_row_to_select = 0 event_history.order_plan_index_offset -= event_history.order_plan_max_rows_to_display + 1 event_history.order_plan_index_offset = 0 if event_history.order_plan_index_offset.negative? event_history.order_plan_row_to_select = 0 if event_history.order_plan_row_to_select.negative? end if event_history.order_execute_win_active event_history.order_execute_row_to_select = 0 event_history.order_execute_index_offset -= event_history.order_execute_max_rows_to_display + 1 event_history.order_execute_index_offset = 0 if event_history.order_execute_index_offset.negative? event_history.order_execute_row_to_select = 0 if event_history.order_execute_row_to_select.negative? end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Supported Method Parameters:: # Cryptum::Event::Scroll.page_down( # ) public_class_method def self.page_down(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_page_down = false order_book = event_history.order_book if event_history.order_plan_win_active order_plan_length = order_book[:order_plan].length event_history.order_plan_row_to_select = 0 event_history.order_plan_index_offset += event_history.order_plan_max_rows_to_display + 1 unless event_history.order_plan_index_offset > order_plan_length end if event_history.order_execute_win_active order_history_meta_length = order_book[:order_history_meta].length event_history.order_execute_row_to_select = 0 event_history.order_execute_index_offset += event_history.order_execute_max_rows_to_display + 1 unless event_history.order_execute_index_offset > order_history_meta_length end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Supported Method Parameters:: # Cryptum::Event::Scroll.top( # ) public_class_method def self.top(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_home = false if event_history.order_plan_win_active event_history.order_plan_row_to_select = 0 event_history.order_plan_index_offset = 0 end if event_history.order_execute_win_active event_history.order_execute_row_to_select = 0 event_history.order_execute_index_offset = 0 end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Supported Method Parameters:: # Cryptum::Event::Scroll.bottom( # ) public_class_method def self.bottom(opts = {}) terminal_win = opts[:terminal_win] event_history = opts[:event_history] terminal_win.key_press_event.key_ansi = false terminal_win.key_press_event.key_esc = false terminal_win.key_press_event.key_end = false order_book = event_history.order_book if event_history.order_plan_win_active order_plan_length = order_book[:order_plan].length last_row = order_plan_length - 1 event_history.order_plan_max_records_available_to_display = last_row if last_row < event_history.order_plan_max_rows_to_display event_history.order_plan_row_to_select = event_history.order_plan_max_records_available_to_display event_history.order_plan_index_offset = order_plan_length - event_history.order_plan_max_records_available_to_display end if event_history.order_execute_win_active order_history_meta_length = order_book[:order_history_meta].length last_row = order_history_meta_length - 1 event_history.order_execute_max_records_available_to_display = last_row if last_row < event_history.order_execute_max_rows_to_display event_history.order_execute_row_to_select = event_history.order_execute_max_records_available_to_display event_history.order_execute_index_offset = order_history_meta_length - event_history.order_execute_max_records_available_to_display end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end # Display Usage for this Module public_class_method def self.help puts "USAGE: #{self}.up() #{self}.down() #{self}.page_up() #{self}.page_down() #{self}.top() #{self}.bottom() " end end end end