Module: Dispel::Util

Included in:
Flumtter::Window::Base
Defined in:
lib/flumtter/app/core/curses.rb

Instance Method Summary collapse

Instance Method Details

#add_multiline_str(win, str) ⇒ Object



31
32
33
34
35
# File 'lib/flumtter/app/core/curses.rb', line 31

def add_multiline_str(win, str)
  str.each_line do |line|
    addstr(win, line.chomp)
  end
end

#addstr(win, str) ⇒ Object



26
27
28
29
# File 'lib/flumtter/app/core/curses.rb', line 26

def addstr(win, str)
  win.setpos(win.cury+1, 1)
  win.addstr str
end

#getstr(win, ex = []) ⇒ Object



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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/flumtter/app/core/curses.rb', line 37

def getstr(win, ex=[])
  buf = ""
  x = win.curx
  loop do
    input = Dispel::Keyboard.translate_key_to_code(win.getch)
    ex.each do |k|
      return input if input == k
    end

    case input
    when :"Ctrl+c"
      raise CloseWindow
    when :enter
      return buf
    when :escape
      raise CloseWindow
    when :left
      if win.curx > x
        win.setpos(win.cury, win.curx-1)
      end
    when :right
      if win.curx <= buf.size
        win.setpos(win.cury, win.curx+1)
      end
      # TODO: 文字移動して削除入力
    when :backspace
      buf.chop!
      while win.curx > x
        win.setpos(win.cury, win.curx-1)
        win.delch()
        win.insch(" ")
      end
      win.addstr(buf)
    when String
      buf << input.force_encoding("utf-8")
      win.setpos(win.cury, win.curx)
      win.addstr(input)
    else
      p input
    end
  end
rescue NoMethodError => e
  if e.backtrace.shift =~ /keyboard.rb:210/
    raise Dispel::Recall
  else
    raise e
  end
end