Class: Rumacs::Screen
- Inherits:
-
Object
- Object
- Rumacs::Screen
- Defined in:
- lib/rumacs/screen.rb,
lib/rumacs/screen/curses.rb
Defined Under Namespace
Classes: Backend
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#cols ⇒ Object
Returns the value of attribute cols.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#point_col ⇒ Object
Returns the value of attribute point_col.
-
#point_row ⇒ Object
Returns the value of attribute point_row.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#top_row ⇒ Object
Returns the value of attribute top_row.
-
#window_col ⇒ Object
Returns the value of attribute window_col.
-
#window_row ⇒ Object
Returns the value of attribute window_row.
Instance Method Summary collapse
- #call_key(c) ⇒ Object
-
#call_key_in_table(key, table, rescuer) ⇒ Object
This function is RECURSIVE! Do NOT refactor!.
- #compound_key_c ⇒ Object
- #compound_key_x ⇒ Object
- #draw_lines ⇒ Object
- #init_screen ⇒ Object
-
#initialize ⇒ Screen
constructor
A new instance of Screen.
- #key_loop ⇒ Object
- #kill_rumacs ⇒ Object
- #minibuf(type, str) ⇒ Object
- #point_move(row_offset, col_offset) ⇒ Object
- #point_set(row, col) ⇒ Object
- #put_lines(lines) ⇒ Object
- #shunt_col(col_offset) ⇒ Object
- #shunt_row(row_offset) ⇒ Object
- #status_line ⇒ Object
- #unbound_key_warning(key) ⇒ Object
Constructor Details
#initialize ⇒ Screen
Returns a new instance of Screen.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rumacs/screen.rb', line 14 def initialize() @rows = 0 @cols = 0 @point_row = 0 @point_col = 0 @window_row = 0 @window_col = 0 @lines = [''] @top_row = 0 @backend = Rumacs::Screen::Backend.new(self) @selected_keys = "" end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
12 13 14 |
# File 'lib/rumacs/screen.rb', line 12 def backend @backend end |
#cols ⇒ Object
Returns the value of attribute cols.
7 8 9 |
# File 'lib/rumacs/screen.rb', line 7 def cols @cols end |
#lines ⇒ Object
Returns the value of attribute lines.
10 11 12 |
# File 'lib/rumacs/screen.rb', line 10 def lines @lines end |
#point_col ⇒ Object
Returns the value of attribute point_col.
8 9 10 |
# File 'lib/rumacs/screen.rb', line 8 def point_col @point_col end |
#point_row ⇒ Object
Returns the value of attribute point_row.
8 9 10 |
# File 'lib/rumacs/screen.rb', line 8 def point_row @point_row end |
#rows ⇒ Object
Returns the value of attribute rows.
7 8 9 |
# File 'lib/rumacs/screen.rb', line 7 def rows @rows end |
#top_row ⇒ Object
Returns the value of attribute top_row.
11 12 13 |
# File 'lib/rumacs/screen.rb', line 11 def top_row @top_row end |
#window_col ⇒ Object
Returns the value of attribute window_col.
9 10 11 |
# File 'lib/rumacs/screen.rb', line 9 def window_col @window_col end |
#window_row ⇒ Object
Returns the value of attribute window_row.
9 10 11 |
# File 'lib/rumacs/screen.rb', line 9 def window_row @window_row end |
Instance Method Details
#call_key(c) ⇒ Object
199 200 201 |
# File 'lib/rumacs/screen.rb', line 199 def call_key(c) call_key_in_table(c, $known_keys, lambda {|key| $filemgr.insert_character_at_point(key) }) end |
#call_key_in_table(key, table, rescuer) ⇒ Object
This function is RECURSIVE! Do NOT refactor!
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rumacs/screen.rb', line 181 def call_key_in_table(key, table, rescuer) if key.is_a? Symbol then if table.key?(key) then if table[key].is_a? Proc then table[key].call(self) elsif table[key].is_a? Symbol then call_key_in_table(table[key], table, rescuer) else raise Exception.new("unknown type of known_key in #{key}") end else unbound_key_warning(key) end else rescuer.call(key) end end |
#compound_key_c ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/rumacs/screen.rb', line 211 def compound_key_c() @selected_keys += "C-c " minibuf(:notice, "#{@selected_keys}...") do call_key_in_table(@backend.next_character, $known_compound_c, lambda {|key| abort_command }) end @selected_keys = "" end |
#compound_key_x ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/rumacs/screen.rb', line 203 def compound_key_x() @selected_keys += "C-x " minibuf(:notice, "#{@selected_keys}...") do call_key_in_table(@backend.next_character, $known_compound_x, lambda {|key| abort_command }) end @selected_keys = "" end |
#draw_lines ⇒ Object
106 107 108 109 110 |
# File 'lib/rumacs/screen.rb', line 106 def draw_lines() (0..(@rows-2)).to_a.each do |i| @backend.draw_line(i, 0, @lines[@top_row+i]) end end |
#init_screen ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rumacs/screen.rb', line 28 def init_screen() @backend.init_screen do status_line() yield end end |
#key_loop ⇒ Object
219 220 221 222 223 |
# File 'lib/rumacs/screen.rb', line 219 def key_loop() loop do call_key(@backend.next_character) end end |
#kill_rumacs ⇒ Object
35 36 37 38 |
# File 'lib/rumacs/screen.rb', line 35 def kill_rumacs() @backend.clean_exit exit 0 end |
#minibuf(type, str) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rumacs/screen.rb', line 118 def minibuf(type, str) if (type == :warning) || (type == :error) then @backend.notify end @backend.draw_line_mode(@rows - 1, 0, str, :minibuf) @backend.jump_to_point() @backend.redraw() yield @backend.draw_line_mode(@rows - 1, 0, " "*(@cols-1), :minibuf) @backend.jump_to_point() @backend.redraw() end |
#point_move(row_offset, col_offset) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/rumacs/screen.rb', line 40 def point_move(row_offset, col_offset) if (row_offset != 0) then shunt_row(row_offset) elsif (col_offset != 0) then shunt_col(col_offset) end status_line() end |
#point_set(row, col) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rumacs/screen.rb', line 83 def point_set(row, col) if row === true then @point_row = @lines.size else @point_row = (row || @point_row) end if col === true then @point_col = (@lines[@point_row] || 0).size else @point_col = (col || @point_col) end @window_col = @point_col status_line() end |
#put_lines(lines) ⇒ Object
100 101 102 103 104 |
# File 'lib/rumacs/screen.rb', line 100 def put_lines(lines) @lines = lines @lines.collect! {|line| line || ''} draw_lines end |
#shunt_col(col_offset) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rumacs/screen.rb', line 65 def shunt_col(col_offset) prev_line_length = @lines[@point_row-1].size this_line_length = (@lines[@point_row] || '').size if (@point_col >= this_line_length) && (col_offset > 0) then col_offset = ((@point_col + col_offset) - this_line_length) - 1 shunt_row( +1 ) @point_col = col_offset elsif (@point_col <= 0) && (col_offset < 0) then shunt_row( -1 ) col_offset = prev_line_length - (@point_col + col_offset + 1) @point_col = col_offset else @point_col += col_offset end @window_col = @point_col end |
#shunt_row(row_offset) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rumacs/screen.rb', line 50 def shunt_row(row_offset) if (@point_row <= 0) && (row_offset < 0) then minibuf(:error, "Beginning of buffer") { sleep 1 } elsif (@point_row >= @lines.length) && (row_offset > 0) then minibuf(:error, "End of buffer") { sleep 1 } else @point_row += row_offset if @point_col > ((@lines[@point_row] || '').size) then @point_col = (@lines[@point_row] || '').size end end @window_row = @point_row end |
#status_line ⇒ Object
112 113 114 115 116 |
# File 'lib/rumacs/screen.rb', line 112 def status_line() status_string = "- rumacs - [#{@point_row},(#{@point_col}/#{(@lines[@point_row] || '').size}) inside #{@top_row}..#{@top_row + @rows - 2}] (#{@rows}:#{@cols}:#{$$}) " @backend.draw_line_mode(@rows - 2, 0, status_string+("-" * (@cols - (status_string.size))), :statusbar) @backend.jump_to_point() end |
#unbound_key_warning(key) ⇒ Object
174 175 176 |
# File 'lib/rumacs/screen.rb', line 174 def unbound_key_warning(key) minibuf(:warning, "'#{key.to_s}' is undefined.") { sleep 1 } end |