Class: Mysh::SmartSource

Inherits:
Object show all
Defined in:
lib/mysh/sources/smart_auto_complete.rb

Overview

An array as the source for auto-complete.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SmartSource

Create a new file/folder auto-data source. NOP



10
11
12
13
14
15
# File 'lib/mysh/sources/smart_auto_complete.rb', line 10

def initialize(options)
  @prefix        = options[:prefix]
  @auto_source   = MiniReadline::AutoFileSource.new(options)
  @quote_source  = MiniReadline::QuotedFileFolderSource.new(options)
  @active_source = nil
end

Instance Method Details

#nextObject

Get the next string for auto-complete



30
31
32
# File 'lib/mysh/sources/smart_auto_complete.rb', line 30

def next
  @active_source ? @active_source.next : @str
end

#rebuild(str) ⇒ Object

Construct a new data list for auto-complete



18
19
20
21
22
23
24
25
26
27
# File 'lib/mysh/sources/smart_auto_complete.rb', line 18

def rebuild(str)
  if /(?<=\s|^)\$[a-z][a-z0-9_]*\z/ =~ str
    sym = $MATCH[1..-1].to_sym
    @active_source = nil
    return @str = $PREMATCH + MNV[sym] if MNV.key?(sym)
  end

  @active_source = (@prefix || str[0]) == '=' ? @quote_source : @auto_source
  @active_source.rebuild(str)
end