Class: Twterm::App

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

Constant Summary collapse

DATA_DIR =
"#{ENV['HOME']}/.twterm"

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/twterm/app.rb', line 7

def initialize
  Dir.mkdir(DATA_DIR, 0700) unless File.directory?(DATA_DIR)

  Config.load
  Auth.authenticate_user if Config[:screen_name].nil?

  Screen.instance

  client = Client.new(Config[:user_id], Config[:screen_name], Config[:access_token], Config[:access_token_secret])

  timeline = Tab::TimelineTab.new(client)
  TabManager.instance.add_and_show(timeline)

  mentions_tab = Tab::MentionsTab.new(client)
  TabManager.instance.add(mentions_tab)

  Screen.instance.refresh

  client.stream
  UserWindow.instance

  reset_interruption_handler
end

Instance Method Details

#register_interruption_handler(&block) ⇒ Object



38
39
40
41
42
43
# File 'lib/twterm/app.rb', line 38

def register_interruption_handler(&block)
  fail ArgumentError, 'no block given' unless block_given?
  Signal.trap(:INT) do
    block.call
  end
end

#reset_interruption_handlerObject



45
46
47
48
49
# File 'lib/twterm/app.rb', line 45

def reset_interruption_handler
  Signal.trap(:INT) do
    exit
  end
end

#runObject



31
32
33
34
35
36
# File 'lib/twterm/app.rb', line 31

def run
  run_periodic_cleanup

  Screen.instance.wait
  Screen.instance.refresh
end