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 =
<<'EOF'
____    __    ____   _______. __    __  
\   \  /  \  /   /  /       ||  |  |  | 
 \   \/    \/   /  |   (----`|  |__|  | 
  \            /    \   \    |   __   | 
   \    /\    / .----)   |   |  |  |  | 
    \__/  \__/  |_______/    |__|  |__| 
    
Welcome to the WATOBO Shell!
Simply enter your ruby code you want to execute and press enter.
To get your output written to the textbox use the <out> stream, e.g. 
out << "Hello World"
For command history use Up- and Down-Keys.
A good starting point to explore WATOBO is the Watobo object itself.

Example 1: List all sites
>> Watobo::Chats.sites do |s| out << "#{s}\n";end

Example 2: Get all values of URL parameter <raid>
>> Watobo::Chats.each do |c| v = c.request.get_parm_value('raid'); out << "#{v}\n" unless v.empty?;end

Example 3: List all URL where chat comment contains 'Session-Test'
>> out << Watobo::Chats.map { |c| c.comment =~ /Session-Test/i ? c.request.url : nil }.compact.join("\n")

EOF

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