Module: Coinbot::UI::Timer

Defined in:
lib/coinbot/ui/timer.rb

Overview

This plugin is used to Refresh the Coinbot Status Section UI

Class Method Summary collapse

Class Method Details

.helpObject

Display Usage for this Module



71
72
73
74
75
76
# File 'lib/coinbot/ui/timer.rb', line 71

public_class_method def self.help
  puts "USAGE:
   #{self}.refresh(
   )
  "
end

.refresh(opts = {}) ⇒ Object

Supported Method Parameters

Coinbot::UI::Timer.refresh( )



13
14
15
16
17
18
19
20
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
59
60
61
62
63
64
65
66
67
# File 'lib/coinbot/ui/timer.rb', line 13

public_class_method def self.refresh(opts = {})
  candle_duration = opts[:candle_duration]
  timer_win = opts[:timer_win]
  candle_begin_time = opts[:candle_begin_time]
  key_press_event = opts[:key_press_event]

  Coinbot::UI.detect_key_press_in_ui(
    key_press_event: key_press_event,
    ui_win: timer_win
  )

  casted_begin_time = Time.parse(candle_begin_time)
  candle_end_time = casted_begin_time + candle_duration
  candle_time_remaining = candle_end_time - Time.now
  candle_countdown = format('%0.4f', candle_time_remaining)
  clock = Time.now.strftime('%Y-%m-%d %H:%M:%S%z')

  # UI
  col_just3 = (Curses.cols - Coinbot::UI.col_third) - 1

  # ROW 1
  out_line_no = 0
  Coinbot::UI.line(
    ui_win: timer_win,
    out_line_no: out_line_no
  )

  # ROW 2
  out_line_no += 1
  timer_win.setpos(out_line_no, Coinbot::UI.col_first)
  timer_win.clrtoeol
  Coinbot::UI.colorize(
    ui_win: timer_win,
    color: :white,
    style: :bold,
    string: candle_countdown
  )

  timer_win.setpos(out_line_no, Coinbot::UI.col_third)
  Coinbot::UI.colorize(
    ui_win: timer_win,
    color: :white,
    style: :bold,
    string: clock.rjust(col_just3, "\s")
  )

  timer_win.refresh

  candle_countdown.to_f
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Coinbot.exit_gracefully(which_self: self)
rescue StandardError => e
  raise e
end