Class: Watobo::Plugin::WShell

Inherits:
Watobo::PluginBase
  • Object
show all
Defined in:
plugins/wshell/wshell.rb,
plugins/wshell/gui/main.rb,
plugins/wshell/lib/core.rb

Defined Under Namespace

Classes: Gui

Constant Summary collapse

HELP_TEXT =
"____    __    ____   _______. __    __  \n\\   \\  /  \\  /   /  /       ||  |  |  | \n \\   \\/    \\/   /  |   (----`|  |__|  | \n  \\            /    \\   \\    |   __   | \n   \\    /\\    / .----)   |   |  |  |  | \n    \\__/  \\__/  |_______/    |__|  |__| \n    \nWelcome to the WATOBO Shell!\nSimply enter your ruby code you want to execute and press enter.\nTo get your output written to the textbox use the <out> stream, e.g. \nout << \"Hello World\"\nFor command history use Up- and Down-Keys.\nA good starting point to explore WATOBO is the Watobo object itself.\n\nExample 1: List all sites\n>> Watobo::Chats.sites do |s| out << \"\#{s}\\n\";end\n\nExample 2: Get all values of URL parameter <raid>\n>> Watobo::Chats.each do |c| v = c.request.get_parm_value('raid'); out << \"\#{v}\\n\" unless v.empty?;end\n\nExample 3: List all URL where chat comment contains 'Session-Test'\n>> out << Watobo::Chats.map { |c| c.comment =~ /Session-Test/i ? c.request.url : nil }.compact.join(\"\\n\")\n\n"

Class Method Summary collapse

Class Method Details

.execute_cmd(command) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'plugins/wshell/lib/core.rb', line 74

def self.execute_cmd(command)
  
   Thread.new(command){ |cmd|
     begin
       @history << cmd unless @history.include? cmd
       @history.shift if @history.length > 20
       
       command = "out = StringIO.new; #{cmd}; out.string"
       r = eval(command)           
                   
       @executions << [ cmd, r ]
     rescue SyntaxError, LocalJumpError, NameError
       @executions << [ cmd, "Error In Command!" ]
     rescue => bang
       puts bang.backtrace
       @executions << [ cmd, bang ]
       
     end
   }
end

.executionsObject



58
59
60
# File 'plugins/wshell/lib/core.rb', line 58

def self.executions
  @executions
end

.helpObject



54
55
56
# File 'plugins/wshell/lib/core.rb', line 54

def self.help
  HELP_TEXT
end

.history_at(index) ⇒ Object



67
68
69
70
71
72
# File 'plugins/wshell/lib/core.rb', line 67

def self.history_at(index)
  if index >= 0 and index < @history.length
    return @history[index]
  end
  return nil
end

.history_lengthObject



63
64
65
# File 'plugins/wshell/lib/core.rb', line 63

def self.history_length
  @history.length
end