Method: Ruvi::EditorApp#do_command

Defined in:
lib/front.rb

#do_command(buffer, c) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
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
# File 'lib/front.rb', line 138

def do_command buffer, c
    number_char = nil
    char_string = (c > 256) ? @curses_key_translators[c] : c.chr
    @current_command_binding_state = @stored_command_bindings if @current_command_binding_state.nil?
    if (c > 256) or !@current_command_binding_state[c].nil?
        if @command_context.nil?
            @command_context = Struct.new(:input).new
            @command_context.input = ""
        end
        char_string.each_byte {
          |c|
          options = @current_command_binding_state[c]
          if options.is_a? Hash
              @current_command_binding_state = options
              @command_context.input << c.chr
          else
              @command_context.input << c.chr
              case options.arity
              when 2
                  options.call c, @command_context
              else
                  options.call c
              end
              @current_command_binding_state = nil
              @command_context = nil
          end
        }
    else
        @command_context = nil
        @current_command_binding_state = nil
        case c
        when ?0..?9
            number_char = c
        else
            raise "[unknown key `#{Curses.keyname(c)}'=#{c}]" if $test_case
            status_bar_edit_line "[unknown key `#{Curses.keyname(c)}'=#{c}] "
        end
        # what a freaking haccckk :(
        if number_char.nil?
            unless @number.nil? or !@command.nil?
                @number = nil
                status_bar_edit_line "number ended..."
            end
        else
            if @number.nil? and number_char == ?0
                buffer.move_to_x 0
            else
                @number = "" if @number.nil?
                @number << number_char.chr
            end
        end
    end
    if    !@selection.nil? and (@selection.mode == :selc_normal || @selection.mode == :selc_boxed)
        @selection.e = Point.new(buffer.x, buffer.y)
    elsif !@selection.nil? and @selection.mode == :selc_lined
        @selection.e = Point.new(buffer.lines[buffer.y].length, buffer.y)
    end
    @da_command << c.chr unless @mode_stack.last == :command or !@changed or c > 255
    if @command.empty? and @mode_stack.last == :normal and !@da_command.empty? and @changed
        @changed = false
        @last_command = @da_command
        @da_command = ""
    end
    buffer.dlog.flush
    update_selection buffer
    @status_bar.invalidate
end