Class: Redwood::Buffer

Inherits:
Object show all
Defined in:
lib/sup/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, mode, width, height, opts = {}) ⇒ Buffer

Returns a new instance of Buffer.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sup/buffer.rb', line 78

def initialize window, mode, width, height, opts={}
  @w = window
  @mode = mode
  @dirty = true
  @focus = false
  @title = opts[:title] || ""
  @force_to_top = opts[:force_to_top] || false
  @x, @y, @width, @height = 0, 0, width, height
  @atime = Time.at 0
  @system = opts[:system] || false
end

Instance Attribute Details

#atimeObject (readonly)

Returns the value of attribute atime.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def atime
  @atime
end

#heightObject (readonly)

Returns the value of attribute height.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def height
  @height
end

#modeObject (readonly)

Returns the value of attribute mode.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def mode
  @mode
end

#titleObject (readonly)

Returns the value of attribute title.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def title
  @title
end

#widthObject (readonly)

Returns the value of attribute width.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



74
75
76
# File 'lib/sup/buffer.rb', line 74

def y
  @y
end

Instance Method Details

#blurObject



156
157
158
159
160
# File 'lib/sup/buffer.rb', line 156

def blur
  @focus = false
  @dirty = true
  @mode.blur
end

#clearObject



142
143
144
# File 'lib/sup/buffer.rb', line 142

def clear
  @w.clear
end

#commitObject



113
114
115
116
# File 'lib/sup/buffer.rb', line 113

def commit
  @dirty = false
  @w.noutrefresh
end

#content_heightObject



90
# File 'lib/sup/buffer.rb', line 90

def content_height; @height - 1; end

#content_widthObject



91
# File 'lib/sup/buffer.rb', line 91

def content_width; @width; end

#draw(status) ⇒ Object



118
119
120
121
122
123
# File 'lib/sup/buffer.rb', line 118

def draw status
  @mode.draw
  draw_status status
  commit
  @atime = Time.now
end

#draw_status(status) ⇒ Object



146
147
148
# File 'lib/sup/buffer.rb', line 146

def draw_status status
  write @height - 1, 0, status, :color => :status_color
end

#focusObject



150
151
152
153
154
# File 'lib/sup/buffer.rb', line 150

def focus
  @focus = true
  @dirty = true
  @mode.focus
end

#mark_dirtyObject



111
# File 'lib/sup/buffer.rb', line 111

def mark_dirty; @dirty = true; end

#redraw(status) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/sup/buffer.rb', line 101

def redraw status
  if @dirty
    draw status
  else
    draw_status status
  end

  commit
end

#resize(rows, cols) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/sup/buffer.rb', line 93

def resize rows, cols
  return if cols == @width && rows == @height
  @width = cols
  @height = rows
  @dirty = true
  mode.resize rows, cols
end

#write(y, x, s, opts = {}) ⇒ Object

s nil means a blank line!



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sup/buffer.rb', line 126

def write y, x, s, opts={}
  return if x >= @width || y >= @height

  @w.attrset Colormap.color_for(opts[:color] || :none, opts[:highlight])
  s ||= ""
  maxl = @width - x # maximum display width width
  stringl = maxl    # string "length"

  # fill up the line with blanks to overwrite old screen contents
  @w.mvaddstr y, x, " " * maxl unless opts[:no_fill]

  ## the next horribleness is thanks to ruby's lack of widechar support
  stringl += 1 while stringl < s.length && s[0 ... stringl].display_length < maxl
  @w.mvaddstr y, x, s[0 ... stringl]
end