Class: Ruvi::StatusBar

Inherits:
Widget
  • Object
show all
Defined in:
lib/widgets.rb

Instance Attribute Summary collapse

Attributes inherited from Widget

#buffer, #cursor, #parent

Instance Method Summary collapse

Methods inherited from Widget

#watch_buffer

Constructor Details

#initialize(app, buffer) ⇒ StatusBar

Returns a new instance of StatusBar.



135
136
137
138
139
140
# File 'lib/widgets.rb', line 135

def initialize app, buffer
    super app, buffer
    @text = ""
    @highlight_progress = nil
    @needs_update = true
end

Instance Attribute Details

#highlight_progress=(p) ⇒ Object (writeonly)

Sets the attribute highlight_progress

Parameters:

  • value

    the value to set the attribute highlight_progress to.



134
135
136
# File 'lib/widgets.rb', line 134

def highlight_progress=(value)
  @highlight_progress = value
end

#needs_updateObject (readonly)

Returns the value of attribute needs_update.



133
134
135
# File 'lib/widgets.rb', line 133

def needs_update
  @needs_update
end

#textObject

Returns the value of attribute text.



133
134
135
# File 'lib/widgets.rb', line 133

def text
  @text
end

Instance Method Details

#canvasObject



154
155
156
# File 'lib/widgets.rb', line 154

def canvas
    Curses.begin_draw WinDescs::instance.descs[self]
end

#heightObject



153
# File 'lib/widgets.rb', line 153

def height; 1;   end

#invalidateObject



149
150
151
# File 'lib/widgets.rb', line 149

def invalidate
    @needs_update = true
end

#render(y) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/widgets.rb', line 157

def render y
    return unless @needs_update
    screen = canvas
    current = (@app.current_buffer == @buffer)
    screen.setpos y, 0 # y, x
    hl_prog_str = @highlight_progress.nil? || !current ? "" : "HL:#{"%0.2f" % (@highlight_progress * 100)}% "
    pos_str = ":B(#{@buffer.bnum}:#{@buffer.fname})- #{@buffer.x},#{@buffer.y}:"
    desc_str = hl_prog_str + pos_str 
    max_len = WinDescs::instance.descs[self].sx - 1 - desc_str.length
    fg = current ? Curses::COLOR_RED : Curses::COLOR_CYAN
    screen.set_attr true, fg, Curses::COLOR_BLACK
    str = current ? @text[0, max_len].ljust(max_len) : (" " * max_len)
    screen.addstr str + desc_str
    @needs_update = false
end

#widthObject



152
# File 'lib/widgets.rb', line 152

def width;  nil; end