Class: Totpc::Window

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/totpc/window.rb

Overview

curses window to show codes

Instance Method Summary collapse

Instance Method Details

#closeObject



43
44
45
# File 'lib/totpc/window.rb', line 43

def close
  close_screen
end

#getchObject



39
40
41
# File 'lib/totpc/window.rb', line 39

def getch
  Curses.getch
end

#init_cursesObject



7
8
9
10
11
# File 'lib/totpc/window.rb', line 7

def init_curses
  init_screen
  Curses.timeout = 1000
  crmode
end

#show_curses(secrets, totp) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/totpc/window.rb', line 13

def show_curses(secrets, totp)
  show_header_footer
  ypos = 2
  secrets.each do |secret|
    show_message(ypos, 0, secret[:id] + ' : ' +
                 totp[secret[:id]].now)
    ypos += 1
  end
  refresh
end


24
25
26
27
# File 'lib/totpc/window.rb', line 24

def show_header_footer
  show_message(lines - 1, cols - 20, 'Hit any key to quit')
  show_remaining
end

#show_message(x, y, message) ⇒ Object



29
30
31
32
# File 'lib/totpc/window.rb', line 29

def show_message(x, y, message)
  setpos(x, y)
  addstr(message)
end

#show_remainingObject



34
35
36
37
# File 'lib/totpc/window.rb', line 34

def show_remaining
  count = 30 - Time.now.to_i % 30
  show_message(0, 0, 'remaining ' + format('%02d', count))
end