Class: Twterm::Tab::New::User

Inherits:
Object
  • Object
show all
Includes:
Readline, Base
Defined in:
lib/twterm/tab/new/user.rb

Instance Attribute Summary

Attributes included from Base

#window

Instance Method Summary collapse

Methods included from Base

#close, #initialize, #refresh, #resize

Instance Method Details

#==(other) ⇒ Object



8
9
10
# File 'lib/twterm/tab/new/user.rb', line 8

def ==(other)
  other.is_a?(self.class)
end

#invoke_inputObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/twterm/tab/new/user.rb', line 12

def invoke_input
  resetter = proc do
    reset_prog_mode
    sleep 0.1
    Screen.instance.refresh
  end

  CompletionManager.instance.set_screen_name_mode!

  input_thread = Thread.new do
    close_screen
    puts "\nSearch user"
    screen_name = (readline('> @') || '').strip
    resetter.call

    if screen_name.nil? || screen_name.empty?
      TabManager.instance.switch(Tab::New::Start.new)
    else
      Client.current.show_user(screen_name).then do |user|
        if user.nil?
          Notifier.instance.show_error 'User not found'
          tab = Tab::New::Start.new
        else
          tab = Tab::UserTab.new(user.id)
        end
        TabManager.instance.switch(tab)
      end
    end
  end

  App.instance.register_interruption_handler do
    input_thread.kill
    resetter.call
    tab = Tab::New::Start.new
    TabManager.instance.switch(tab)
  end

  input_thread.join
end

#respond_to_key(_) ⇒ Object



52
53
54
# File 'lib/twterm/tab/new/user.rb', line 52

def respond_to_key(_)
  false
end

#titleObject



56
57
58
# File 'lib/twterm/tab/new/user.rb', line 56

def title
  'New tab'.freeze
end