Class: Twterm::Screen

Inherits:
Object
  • Object
show all
Includes:
Subscriber
Defined in:
lib/twterm/screen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Subscriber

included, #subscribe, #unsubscribe

Constructor Details

#initialize(app, client) ⇒ Screen

Returns a new instance of Screen.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twterm/screen.rb', line 25

def initialize(app, client)
  @app, @client = app, client

  @stdscr = Curses.init_screen

  width = @stdscr.maxx
  height = @stdscr.maxy

  @tab_manager_window = @stdscr.subwin(1, width, 0, 0)
  @tab_window = @stdscr.subwin(height - 3, width, 2, 0)
  @message_window_window = @stdscr.subwin(1, width, height - 2, 0)
  @search_query_window_window = @stdscr.subwin(1, width, height - 1, 0)

  Curses.noecho
  Curses.raw
  Curses.curs_set(0)
  Curses.stdscr.keypad(true)
  Curses.start_color
  Curses.use_default_colors
  Curses.mousemask(Curses::BUTTON1_CLICKED | 65536 | 2097152)

  subscribe(Event::Screen::Refresh) { refresh }
end

Instance Attribute Details

#message_window_windowCurses::Window (readonly)

TODO:

Make private

Returns:



19
20
21
# File 'lib/twterm/screen.rb', line 19

def message_window_window
  @message_window_window
end

#search_query_window_windowCurses::Window (readonly)

TODO:

Make private

Returns:



23
24
25
# File 'lib/twterm/screen.rb', line 23

def search_query_window_window
  @search_query_window_window
end

#tab_manager_windowCurses::Window (readonly)

TODO:

Make private

Returns:



11
12
13
# File 'lib/twterm/screen.rb', line 11

def tab_manager_window
  @tab_manager_window
end

#tab_windowCurses::Window (readonly)

TODO:

Make private

Returns:



15
16
17
# File 'lib/twterm/screen.rb', line 15

def tab_window
  @tab_window
end

Instance Method Details

#resize(lines, cols) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/twterm/screen.rb', line 49

def resize(lines, cols)
  return if Curses.closed?

  Curses.resizeterm(lines, cols)
  @stdscr.resize(lines, cols)

  tab_manager_window.move(0, 0)
  tab_manager_window.resize(1, cols)
  tab_manager_window.refresh

  tab_window.move(2, 0)
  tab_window.resize(lines - 3, cols)
  tab_window.refresh

  message_window_window.move(cols - 1, 0)
  message_window_window.resize(1, cols)
  message_window_window.refresh

  search_query_window_window.move(cols - 1, 0)
  search_query_window_window.resize(1, cols)
  search_query_window_window.refresh

  refresh
end

#respond_to_key(key) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/twterm/screen.rb', line 74

def respond_to_key(key)
  k = KeyMapper.instance

  case key
  when k[:status, :compose]
    app.tweetbox.compose
    return
  when k[:app, :quit], 3
    app.quit
  when k[:app, :cheatsheet]
    tab = Tab::KeyAssignmentsCheatsheet.new(app, client)
    app.tab_manager.add_and_show tab
  else
    return false
  end

  true
end

#waitObject



93
94
95
96
97
98
# File 'lib/twterm/screen.rb', line 93

def wait
  @thread = Thread.new do
    loop { scan }
  end
  @thread.join
end