Class: WindowBlessing::XtermScreen

Inherits:
Object
  • Object
show all
Includes:
GuiGeo, GuiGeo::Tools
Defined in:
lib/window_blessing/xterm_screen.rb

Direct Known Subclasses

BufferedScreen, WindowedScreen

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXtermScreen

Returns a new instance of XtermScreen.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/window_blessing/xterm_screen.rb', line 8

def initialize
  @event_manager = EventManager.new(self)
  @state = XtermState.new @event_manager
  @input = XtermInput.new
  @output = XtermOutput.new(@state)
  @running = true
  @pending_events = []
  @event_queue = EventQueue.new

  @event_manager.on :key_press do |event|
    quit if event[:control] && event[:key]==:q
  end
end

Instance Attribute Details

#event_managerObject

Returns the value of attribute event_manager.



6
7
8
# File 'lib/window_blessing/xterm_screen.rb', line 6

def event_manager
  @event_manager
end

#event_queueObject

Returns the value of attribute event_queue.



6
7
8
# File 'lib/window_blessing/xterm_screen.rb', line 6

def event_queue
  @event_queue
end

#inputObject

Returns the value of attribute input.



6
7
8
# File 'lib/window_blessing/xterm_screen.rb', line 6

def input
  @input
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/window_blessing/xterm_screen.rb', line 6

def output
  @output
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/window_blessing/xterm_screen.rb', line 6

def state
  @state
end

Instance Method Details

#event_loopObject



56
57
58
59
60
61
# File 'lib/window_blessing/xterm_screen.rb', line 56

def event_loop
  while running?
    process_events
    sleep 1/60.0
  end
end

#in_xterm_state(options = {}) ⇒ Object

options

:mouse => true
:no_cursor => true
:alternate_screen => true
:full => true (enables all above features)
:utf8


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/window_blessing/xterm_screen.rb', line 87

def in_xterm_state(options = {})
  output.echo_off
  output.enable_alternate_screen  if options[:full] || options[:alternate_screen]
  output.enable_mouse             if options[:full] || options[:mouse]
  output.hide_cursor              if options[:full] || options[:no_cursor]
  output.enable_utf8              if options[:utf8]
  output.enable_focus_events
  output.enable_resize_events
  output.clear

  yield self
ensure
  output.reset_all
  output.disable_utf8             if options[:utf8]
  if options[:full] || options[:alternate_screen]
    output.reset_color
    output.clear
    output.disable_alternate_screen
  end
end

#initialize_screenObject



63
64
65
66
67
# File 'lib/window_blessing/xterm_screen.rb', line 63

def initialize_screen
  output.request_state_update
  wait_for_events
  process_events
end

#inspectObject



22
23
24
# File 'lib/window_blessing/xterm_screen.rb', line 22

def inspect
  "<#{self.class}:#{object_id}>"
end

#process_eventsObject



50
51
52
53
54
# File 'lib/window_blessing/xterm_screen.rb', line 50

def process_events
  queue_pending_xterm_events
  queue_event :type => :tick
  process_queued_events
end

#process_queued_eventsObject



46
47
48
# File 'lib/window_blessing/xterm_screen.rb', line 46

def process_queued_events
  event_manager.handle_events event_queue.pop_all
end

#queue_event(e) ⇒ Object



29
# File 'lib/window_blessing/xterm_screen.rb', line 29

def queue_event(e); event_queue << e end

#queue_pending_xterm_eventsObject



32
33
34
# File 'lib/window_blessing/xterm_screen.rb', line 32

def queue_pending_xterm_events
  event_queue << input.read_events
end

#queued_events?Boolean

Returns:

  • (Boolean)


30
# File 'lib/window_blessing/xterm_screen.rb', line 30

def queued_events?; !event_queue.empty? end

#quitObject



26
# File 'lib/window_blessing/xterm_screen.rb', line 26

def quit; @running = false; end

#running?Boolean

Returns:

  • (Boolean)


27
# File 'lib/window_blessing/xterm_screen.rb', line 27

def running?; @running; end

#start(options = {}) ⇒ Object

run xterm raw-session options



72
73
74
75
76
77
78
# File 'lib/window_blessing/xterm_screen.rb', line 72

def start(options={})
  in_xterm_state(options) do
    initialize_screen
    yield self
    event_loop
  end
end

#wait_for_events(max = 100) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/window_blessing/xterm_screen.rb', line 36

def wait_for_events(max=100)
  count = max
  while !queued_events? && count > 0
    queue_pending_xterm_events
    count -= 1
    sleep 0.01
  end
  raise "no events!" unless queued_events?
end