Class: Redwood::ConsoleMode

Inherits:
LogMode show all
Defined in:
lib/sup/modes/console_mode.rb

Instance Attribute Summary

Attributes inherited from TextMode

#text

Attributes inherited from ScrollMode

#botline, #leftcol, #status, #topline

Attributes inherited from Mode

#buffer

Instance Method Summary collapse

Methods inherited from LogMode

#<<, #cleanup, #on_kill, #status, #toggle_follow

Methods inherited from TextMode

#<<, #[], #lines, #pipe, #save_to_disk

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_jump, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_goto_pos, #search_in_buffer, #search_start_line

Methods inherited from Mode

#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, keymap, keymaps, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #status, #unsaved?

Constructor Details

#initializeConsoleMode

Returns a new instance of ConsoleMode.



84
85
86
87
88
# File 'lib/sup/modes/console_mode.rb', line 84

def initialize
  super "console"
  @console = Console.new self
  @binding = @console.instance_eval { binding }
end

Instance Method Details

#execute(cmd) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sup/modes/console_mode.rb', line 90

def execute cmd
  begin
    self << ">> #{cmd}\n"
    ret = eval cmd, @binding
    self << "=> #{ret.pretty_inspect}\n"
  rescue Exception
    self << "#{$!.class}: #{$!.message}\n"
    clean_backtrace = []
    $!.backtrace.each { |l| break if l =~ /console-mode/; clean_backtrace << l }
    clean_backtrace.each { |l| self << "#{l}\n" }
  end
end

#promptObject



103
104
105
# File 'lib/sup/modes/console_mode.rb', line 103

def prompt
  BufferManager.ask :console, ">> "
end

#runObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sup/modes/console_mode.rb', line 107

def run
  self << <<EOS
Sup v#{VERSION} console session started.
Available extra commands: #{(@console.special_methods) * ", "}
Ctrl-G stops evaluation; 'e' restarts it.

EOS
  while true
    if(cmd = prompt)
      execute cmd
    else
      self << "Console session ended."
      break
    end
  end
end