Class: Test
- Inherits:
-
Object
- Object
- Test
- Defined in:
- lib/cluster_bomb/actest.rb
Instance Method Summary collapse
- #foo_completion_proc(tokens) ⇒ Object
- #main_completion_proc(s) ⇒ Object
- #read_line ⇒ Object
- #run ⇒ Object
Instance Method Details
#foo_completion_proc(tokens) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cluster_bomb/actest.rb', line 51 def foo_completion_proc(tokens) files=Dir.glob('*') if tokens[1]=='' candidates=files candidates else candidates = files.grep(/^#{tokens[1]}/) candidates.collect {|c| "#{tokens[0]} #{c}"} end end |
#main_completion_proc(s) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cluster_bomb/actest.rb', line 30 def main_completion_proc(s) # No line buffer for mac, so no way to get command context # Very lame with libedit. Will not return candidates, and # We cannot get the current line so we can do context-based # edits cmds = ['foo','bar','plushy','food','bear','plum','ls','los','lsu'] ret=[] tokens = s.split(' ') if s =~ /^\w.* $/ tokens << '' end # Initial command only if tokens.length <= 1 ret = cmds.grep(/^#{s}/) else if tokens[0]=='ls' ret = foo_completion_proc(tokens) end end ret end |
#read_line ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cluster_bomb/actest.rb', line 15 def read_line begin line = Readline.readline("> ", true) if line =~ /^\s*$/ || Readline::HISTORY.to_a[-2] == line Readline::HISTORY.pop end rescue Interrupt => e system('stty', @stty_save) return nil end return line if line.nil? # Ctrl-d line.strip! return line end |
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cluster_bomb/actest.rb', line 5 def run() Readline.completion_proc=proc {|s| self.main_completion_proc(s)} Readline.completer_word_break_characters = 7.chr Readline.completion_case_fold = true Readline.completion_append_character = '' while(true) do line = read_line break if !line end end |