Class: Twterm::CompletionManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/twterm/completion_mamanger.rb

Instance Method Summary collapse

Constructor Details

#initializeCompletionManager

Returns a new instance of CompletionManager.



5
6
7
8
# File 'lib/twterm/completion_mamanger.rb', line 5

def initialize
  Readline.basic_word_break_characters = " \t\n\"\\'`$><=;|&{("
  Readline.completion_case_fold = false
end

Instance Method Details

#set_default_mode!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/twterm/completion_mamanger.rb', line 10

def set_default_mode!
  Readline.completion_append_character = ' '

  Readline.completion_proc = proc do |str|
    if str.start_with?('#')
      History::Hashtag.instance.history
      .map { |tag| "##{tag}" }
      .select { |tag| tag.start_with?(str) }
    elsif str.start_with?('@')
      History::ScreenName.instance.history
      .map { |name| "@#{name}" }
      .select { |name| name.start_with?(str) }
    else
      []
    end
  end
end

#set_screen_name_mode!Object



28
29
30
31
32
33
34
35
# File 'lib/twterm/completion_mamanger.rb', line 28

def set_screen_name_mode!
  Readline.completion_append_character = ''

  Readline.completion_proc = proc do |str|
    History::ScreenName.instance.history
      .select { |name| name.start_with?(str) }
  end
end