Module: Trepan::Complete
- Defined in:
- app/complete.rb
Overview
Command completion methods
Class Method Summary collapse
-
.complete_token(complete_ary, prefix) ⇒ Object
Return an Array of String found from Array of String
complete_ary
which start out with Stringprefix
. -
.complete_token_filtered(aliases, prefix, expanded) ⇒ Object
Find all starting matches in Hash
aliases
that start withprefix
, but filter out any matches already inexpanded
. -
.complete_token_filtered_with_next(aliases, prefix, expanded, commands) ⇒ Object
Find all starting matches in Hash
aliases
that start withprefix
, but filter out any matches already inexpanded
. - .complete_token_with_next(complete_hash, prefix, cmd_prefix = '') ⇒ Object
-
.next_token(str, start_pos) ⇒ Object
Find the next token in str string from start_pos, we return the token and the next blank position after the token or str.size if this is the last token.
Class Method Details
.complete_token(complete_ary, prefix) ⇒ Object
Return an Array of String found from Array of String complete_ary
which start out with String prefix
.
12 13 14 |
# File 'app/complete.rb', line 12 def complete_token(complete_ary, prefix) complete_ary.select { |cmd| cmd.to_s.start_with?(prefix) }.sort end |
.complete_token_filtered(aliases, prefix, expanded) ⇒ Object
Find all starting matches in Hash aliases
that start with prefix
, but filter out any matches already in expanded
.
27 28 29 30 31 |
# File 'app/complete.rb', line 27 def complete_token_filtered(aliases, prefix, ) complete_ary = aliases.keys complete_ary.select { |cmd| cmd.to_s.start_with?(prefix) && ! .member?(aliases[cmd])}.sort end |
.complete_token_filtered_with_next(aliases, prefix, expanded, commands) ⇒ Object
Find all starting matches in Hash aliases
that start with prefix
, but filter out any matches already in expanded
.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/complete.rb', line 35 def complete_token_filtered_with_next(aliases, prefix, , commands) complete_ary = aliases.keys = .keys result = [] complete_ary.each do |cmd| if cmd.to_s.start_with?(prefix) && !.member?(aliases[cmd]) result << [cmd, commands[aliases[cmd]]] end end result.sort end |
.complete_token_with_next(complete_hash, prefix, cmd_prefix = '') ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/complete.rb', line 16 def complete_token_with_next(complete_hash, prefix, cmd_prefix='') result = [] complete_hash.each do |cmd_name, cmd_obj| result << [cmd_name.to_s[cmd_prefix.size..-1], cmd_obj] if cmd_name.to_s.start_with?(cmd_prefix + prefix) end result.sort{|a, b| a[0] <=> b[0]} end |
.next_token(str, start_pos) ⇒ Object
Find the next token in str string from start_pos, we return the token and the next blank position after the token or str.size if this is the last token. Tokens are delimited by white space.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/complete.rb', line 53 def next_token(str, start_pos) look_at = str[start_pos..-1] next_nonblank_pos = start_pos + (look_at =~ /\S/ || 0) next_blank_pos = if next_match = str[next_nonblank_pos..-1] =~ /\s/ next_nonblank_pos + next_match else str.size end return [next_blank_pos, str[next_nonblank_pos...next_blank_pos]] end |