Method: Canis::App#get_command_from_user

Defined in:
lib/canis/core/util/app.rb

#get_command_from_user(choices = ["quit","help", "suspend", "shell_output"]) ⇒ Object

prompts user for a command. we need to get this back to the calling app or have some block stuff TODO Actually, this is naive, you would want to pass some values in like current data value or lines ?? Also may want command completion, or help so all commands can be displayed NOTE: This is gonna change very soon - 2012-01-8



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/canis/core/util/app.rb', line 317

def get_command_from_user choices=["quit","help", "suspend", "shell_output"]
  @_command_history ||= Array.new
  str = rb_gets("Cmd: ", choices) { |q| q.default = @_previous_command; q.history = @_command_history }
          @_command_history << str unless @_command_history.include? str
  # shell the command
  if str =~ /^!/
    str = str[1..-1]
    suspend(false) { 
      #system(str); 
      $log.debug "XXX STR #{str}  " if $log.debug? 

      output=`#{str}`
      system("echo ' ' ");
      $log.debug "XXX output #{output} " if $log.debug? 
      system("echo '#{output}' ");
      system("echo Press Enter to continue.");
      system("read"); 
    }
    return nil # i think
  else
    # TODO
    # here's where we can take internal commands
    #alert "[#{str}] string did not match :!"
    str = str.to_s #= str[1..-1]
    cmdline = str.split
    cmd = cmdline.shift #.to_sym
    return unless cmd # added 2011-09-11 FFI
    f = @form.get_current_field
    if respond_to?(cmd, true)
      if cmd == "close"
        throw :close # other seg faults in del_panel window.destroy executes 2x
      else
        res = send cmd, *cmdline
      end
    elsif f.respond_to?(cmd, true)
      res = f.send(cmd, *cmdline)
    else
      alert "App: #{self.class} does not respond to #{cmd} "
      ret = false
      # what is this execute_this: some kind of general routine for all apps ?
      ret = execute_this(cmd, *cmdline) if respond_to?(:execute_this, true)
      rb_puts("#{self.class} does not respond to #{cmd} ", :color_pair => $promptcolor) unless ret
      # should be able to say in red as error
    end
  end
end