Class: WindowBlessing::XtermOutput
- Inherits:
-
Object
- Object
- WindowBlessing::XtermOutput
show all
- Includes:
- SetColor, SetState
- Defined in:
- lib/window_blessing/xterm_output.rb
Defined Under Namespace
Modules: SetColor, SetState
Instance Attribute Summary collapse
Attributes included from SetColor
#current_bg, #current_fg
Instance Method Summary
collapse
-
#clear ⇒ Object
-
#cursor(loc_or_x, y = nil) ⇒ Object
cursor 0, 0 is the upper left hand corner cursor point(0, 0) is also accepted.
-
#disable_resize_events ⇒ Object
-
#draw_buffer(loc, buffer) ⇒ Object
-
#enable_resize_events ⇒ Object
-
#initialize(xterm_state) ⇒ XtermOutput
constructor
A new instance of XtermOutput.
-
#out(str) ⇒ Object
-
#out_at(loc, str) ⇒ Object
-
#out_at_with_color(loc, str, fg, bg) ⇒ Object
-
#puts(s = nil) ⇒ Object
-
#request_cursor_position ⇒ Object
-
#request_display_pixel_size ⇒ Object
INTERNAL NOTE: xterm returns 3 numbers: ?, height, width This returns the entire screen size in pixels - not just the pixel-size of the x-term.
-
#request_state_update ⇒ Object
-
#request_xterm_size ⇒ Object
INTERNAL NOTE: xterm returns 3 numbers: ?, height, width Xterm sends back response as an escape sequence.
-
#reset_all ⇒ Object
Methods included from SetState
#disable_alternate_screen, #disable_focus_events, #disable_mouse, #disable_utf8, #echo_off, #echo_on, #enable_alternate_screen, #enable_focus_events, #enable_mouse, #enable_utf8, #hide_cursor, #show_cursor
Methods included from SetColor
#change_bg, #change_fg, #out_color, #reset_color, #set_bg, #set_bold, #set_color, #set_color_24bit, #set_fg, #set_underline
Constructor Details
#initialize(xterm_state) ⇒ XtermOutput
111
112
113
|
# File 'lib/window_blessing/xterm_output.rb', line 111
def initialize(xterm_state)
@xterm_state = xterm_state
end
|
Instance Attribute Details
#xterm_state ⇒ Object
Returns the value of attribute xterm_state.
109
110
111
|
# File 'lib/window_blessing/xterm_output.rb', line 109
def xterm_state
@xterm_state
end
|
Instance Method Details
#clear ⇒ Object
176
|
# File 'lib/window_blessing/xterm_output.rb', line 176
def clear; out "\e[2J"; end
|
#cursor(loc_or_x, y = nil) ⇒ Object
cursor 0, 0 is the upper left hand corner
cursor point(0, 0) is also accepted
117
118
119
120
|
# File 'lib/window_blessing/xterm_output.rb', line 117
def cursor(loc_or_x, y=nil)
loc = y ? point(loc_or_x,y) : loc_or_x
out "\e[#{loc.y+1};#{loc.x+1}H"
end
|
#disable_resize_events ⇒ Object
200
201
202
|
# File 'lib/window_blessing/xterm_output.rb', line 200
def disable_resize_events
Signal.trap "SIGWINCH", "DEFAULT"
end
|
#draw_buffer(loc, buffer) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/window_blessing/xterm_output.rb', line 158
def draw_buffer(loc, buffer)
loc = loc.clone
reset_color
buffer.each_line do |line,fg,bg|
out_at_with_color loc, line, fg, bg
loc.y += 1
end
end
|
#enable_resize_events ⇒ Object
194
195
196
197
198
|
# File 'lib/window_blessing/xterm_output.rb', line 194
def enable_resize_events
Signal.trap "SIGWINCH" do
request_xterm_size
end
end
|
#out(str) ⇒ Object
123
124
125
126
|
# File 'lib/window_blessing/xterm_output.rb', line 123
def out(str)
$stdout.print str
str
end
|
#out_at(loc, str) ⇒ Object
128
129
130
131
|
# File 'lib/window_blessing/xterm_output.rb', line 128
def out_at(loc, str)
cursor(loc)
out str
end
|
#out_at_with_color(loc, str, fg, bg) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/window_blessing/xterm_output.rb', line 133
def out_at_with_color(loc, str, fg, bg)
return unless str.length > 0
cursor loc
change_fg fg[0]
change_bg bg[0]
current_attrs = [current_fg, current_bg]
next_output_pos = 0
pos = 0
fg.zip(bg).each do |attrs|
if current_attrs!=attrs
out str[next_output_pos..pos-1]
change_fg attrs[0]
change_bg attrs[1]
current_attrs = attrs
next_output_pos = pos
end
pos += 1
end
out str[next_output_pos..-1]
end
|
#puts(s = nil) ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/window_blessing/xterm_output.rb', line 168
def puts(s=nil)
width = xterm_state.size.x
lines = "#{s}\n".split("\n").collect do |line|
line + " " * (width - (line.length % width))
end
out lines.flatten.join "\n"
end
|
#request_cursor_position ⇒ Object
187
|
# File 'lib/window_blessing/xterm_output.rb', line 187
def request_cursor_position; out "\e[?6n"; end
|
#request_display_pixel_size ⇒ Object
INTERNAL NOTE: xterm returns 3 numbers: ?, height, width
This returns the entire screen size in pixels - not just the pixel-size of the x-term
185
|
# File 'lib/window_blessing/xterm_output.rb', line 185
def request_display_pixel_size; out "\e[14t"; end
|
#request_state_update ⇒ Object
189
190
191
192
|
# File 'lib/window_blessing/xterm_output.rb', line 189
def request_state_update
request_xterm_size
request_display_pixel_size
end
|
#request_xterm_size ⇒ Object
INTERNAL NOTE: xterm returns 3 numbers: ?, height, width
Xterm sends back response as an escape sequence. XtermEventParser knows how to capture and interpret the result.
181
|
# File 'lib/window_blessing/xterm_output.rb', line 181
def request_xterm_size; out "\e[18t"; end
|
#reset_all ⇒ Object
204
205
206
207
208
209
210
211
|
# File 'lib/window_blessing/xterm_output.rb', line 204
def reset_all
disable_focus_events
disable_mouse
disable_resize_events
reset_color
show_cursor
echo_on
end
|