Class: Redwood::Buffer

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of Buffer



58
59
60
61
62
63
64
65
66
# File 'lib/sup/buffer.rb', line 58

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
end

Instance Attribute Details

- (Object) height (readonly)

Returns the value of attribute height



54
55
56
# File 'lib/sup/buffer.rb', line 54

def height
  @height
end

- (Object) mode (readonly)

Returns the value of attribute mode



54
55
56
# File 'lib/sup/buffer.rb', line 54

def mode
  @mode
end

- (Object) title (readonly)

Returns the value of attribute title



54
55
56
# File 'lib/sup/buffer.rb', line 54

def title
  @title
end

- (Object) width (readonly)

Returns the value of attribute width



54
55
56
# File 'lib/sup/buffer.rb', line 54

def width
  @width
end

- (Object) x (readonly)

Returns the value of attribute x



54
55
56
# File 'lib/sup/buffer.rb', line 54

def x
  @x
end

- (Object) y (readonly)

Returns the value of attribute y



54
55
56
# File 'lib/sup/buffer.rb', line 54

def y
  @y
end

Instance Method Details

- (Object) blur



129
130
131
132
133
# File 'lib/sup/buffer.rb', line 129

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

- (Object) clear



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

def clear
  @w.clear
end

- (Object) commit



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

def commit
  @dirty = false
  @w.noutrefresh
end

- (Object) content_height



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

def content_height; @height - 1; end

- (Object) content_width



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

def content_width; @width; end

- (Object) draw(status)



96
97
98
99
100
# File 'lib/sup/buffer.rb', line 96

def draw status
  @mode.draw
  draw_status status
  commit
end

- (Object) draw_status(status)



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

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

- (Object) focus



123
124
125
126
127
# File 'lib/sup/buffer.rb', line 123

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

- (Object) mark_dirty



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

def mark_dirty; @dirty = true; end

- (Object) redraw(status)



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

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

  commit
end

- (Object) resize(rows, cols)



71
72
73
74
75
76
77
# File 'lib/sup/buffer.rb', line 71

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

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

s nil means a blank line!



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/sup/buffer.rb', line 103

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
  @w.mvaddstr y, x, s[0 ... maxl]
  unless s.length >= maxl || opts[:no_fill]
    @w.mvaddstr(y, x + s.length, " " * (maxl - s.length))
  end
end