Method: CDK::DIALOG#inject

Defined in:
lib/cdk/components/dialog.rb

#inject(input) ⇒ Object

This injects a single character into the dialog widget



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/cdk/components/dialog.rb', line 150

def inject(input)
  first_button = 0
  last_button = @button_count - 1
  pp_return = 1
  ret = -1
  @complete = false

  # Set the exit type.
  self.setExitType(0)

  # Check if there is a pre-process function to be called.
  unless @pre_process_func.nil?
    pp_return = @pre_process_func.call(:DIALOG, self,
        @pre_process_data, input)
  end

  # Should we continue?
  if pp_return != 0
    # Check for a key binding.
    if self.checkBind(:DIALOG, input)
      @complete = true
    else
      case input
      when Ncurses::KEY_LEFT, Ncurses::KEY_BTAB, Ncurses::KEY_BACKSPACE
        if @current_button == first_button
          @current_button = last_button
        else
          @current_button -= 1
        end
      when Ncurses::KEY_RIGHT, CDK::KEY_TAB, ' '.ord
        if @current_button == last_button
          @current_button = first_button
        else
          @current_button += 1
        end
      when Ncurses::KEY_UP, Ncurses::KEY_DOWN
        CDK.Beep
      when CDK::REFRESH
        @screen.erase
        @screen.refresh
      when CDK::KEY_ESC
        self.setExitType(input)
        @complete = true
      when Ncurses::ERR
        self.setExitType(input)
      when Ncurses::KEY_ENTER, CDK::KEY_RETURN
        self.setExitType(input)
        ret = @current_button
        @complete = true
      end
    end

    # Should we call a post_process?
    if !@complete && !(@post_process_func.nil?)
      @post_process_func.call(:DIALOG, self,
          @post_process_data, input)
    end
  end

  unless @complete
    self.drawButtons
    wrefresh(@win)
    self.setExitType(0)
  end

  @result_data = ret
  return ret
end