Class: UI::Input

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

Constant Summary collapse

KEYMAP_WORKAROUND =
{
   13  => ICurses::KEY_ENTER,
   127 => ICurses::KEY_BACKSPACE,
}

Class Method Summary collapse

Class Method Details

.readline(*args, **opts, &block) ⇒ Object



148
149
150
151
152
# File 'lib/ektoplayer/ui.rb', line 148

def self.readline(*args, **opts, &block)
   (@@readline_obj ||= ReadlineWindow.new).readline(*args, **opts) do |result|
      Canvas.class_variable_get('@@updating').synchronize { yield result }
   end
end

.start_loopObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ektoplayer/ui.rb', line 82

def self.start_loop
   @@readline_obj ||= ReadlineWindow.new

   loop do
      unless @@readline_obj.active?
         ICurses.stdscr.keypad(true)
         ICurses.curs_set(0)
         ICurses.nonl

         until @@readline_obj.active?
            c = EscapeSequenceTranslator.to_curses(s = STDIN.readpartial(10))
            #Ektoplayer::Application.log(self, s)

            if c.is_a? ICurses::IMouseEvent
               UI::Canvas.widget.mouse_click(c)
            elsif c
               UI::Canvas.widget.key_press(c)
            end

            inactivity_count = 0
            until @@readline_obj.active? or inactivity_count > 10
               if (c = (ICurses.stdscr.getch1(1000).ord rescue -1)) > -1
                  inactivity_count = 0

                  if c == ICurses::KEY_MOUSE
                     if (c = ICurses.getmouse)
                        UI::Canvas.widget.mouse_click(c)
                     end
                  else
                     UI::Canvas.widget.key_press(KEYMAP_WORKAROUND[c])
                  end
               else
                  inactivity_count += 1
                  GC.start
               end
            end
         end
      else
         ICurses.stdscr.keypad(false)
         ICurses.curs_set(1)
         ICurses.nl

         begin
            @@readline_obj.redraw
            next unless (c = (ICurses.stdscr.getch1(100).ord rescue -1)) > -1

            if c == 10 or c == 4
               @@readline_obj.feed(?\n.ord)
            else
               @@readline_obj.feed(c)

               if c == 27 # pass 3-character escape sequence
                  ICurses.stdscr.timeout(5)
                  if (c = (ICurses.stdscr.getch.ord rescue -1)) > -1
                     @@readline_obj.feed(c)
                     if (c = (ICurses.stdscr.getch.ord rescue -1)) > -1
                        @@readline_obj.feed(c)
                     end
                  end
               end
            end
         end while @@readline_obj.active?
      end
   end
end