Class: Soundcloud9000::UI::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/soundcloud9000/ui/input.rb

Overview

handles getting input from the user

Constant Summary collapse

MAPPING =
{
  Curses::KEY_LEFT => :left,
  Curses::KEY_RIGHT => :right,
  Curses::KEY_DOWN => :down,
  Curses::KEY_UP => :up,
  Curses::KEY_CTRL_J => :enter,
  Curses::KEY_ENTER => :enter,
  ' ' => :space,
  'j' => :j,
  'k' => :k,
  's' => :s,
  'u' => :u,
  '1' => :one,
  '2' => :two,
  '3' => :three,
  '4' => :four,
  '5' => :five,
  '6' => :six,
  '7' => :seven,
  '8' => :eight,
  '9' => :nine,
  'f' => :f,
  'm' => :m,
  'h' => :h,
  'o' => :o
}.freeze

Class Method Summary collapse

Class Method Details

.error(output) ⇒ Object



58
59
60
61
62
# File 'lib/soundcloud9000/ui/input.rb', line 58

def self.error(output)
  Curses.setpos(Curses.lines - 1, 0)
  Curses.clrtoeol
  Curses.attron(Color.get(:red)) { Curses.addstr(output) }
end

.get(delay = 0) ⇒ Object



35
36
37
38
# File 'lib/soundcloud9000/ui/input.rb', line 35

def self.get(delay = 0)
  Curses.timeout = delay
  MAPPING[Curses.getch]
end

.getstr(prompt) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/soundcloud9000/ui/input.rb', line 40

def self.getstr(prompt)
  Curses.setpos(Curses.lines - 1, 0)
  Curses.clrtoeol
  Curses.addstr(prompt)
  Curses.echo
  result = Curses.getstr
  Curses.noecho
  Curses.setpos(Curses.lines - 1, 0)
  Curses.addstr(''.ljust(Curses.cols))
  result
end


64
65
66
# File 'lib/soundcloud9000/ui/input.rb', line 64

def self.menu(_options)
  p 'menu????'
end

.message(output) ⇒ Object



52
53
54
55
56
# File 'lib/soundcloud9000/ui/input.rb', line 52

def self.message(output)
  Curses.setpos(Curses.lines - 1, 0)
  Curses.clrtoeol
  Curses.addstr(output)
end