Class: RubyCurses::BufferManager

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rbcurse/experimental/widgets/multiform.rb

Overview

Handles multiple buffers, navigation, maintenance etc Instantiated at startup of

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ BufferManager

Returns a new instance of BufferManager.



259
260
261
262
263
264
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 259

def initialize source
  @source = source
  @buffers = [] # contains RBuffer
  @counter = 0
  # for each buffer i need to store data, current_index (row), curpos (col offset) and title (filename).
end

Instance Method Details

#add(component, title = nil) ⇒ Object



319
320
321
322
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 319

def add component, title=nil
  #$log.debug " ADD H: #{component.height} C: #{component.width} "
  insert component, @buffers.size, title
end

#currentRBuffer

Returns current buffer/file.

Returns:

  • (RBuffer)

    current buffer/file



275
276
277
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 275

def current
  @buffers[@counter]
end

#delete_at(index = @counter) ⇒ Object



307
308
309
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 307

def delete_at index=@counter
  @buffers.delete_at index
end

#delete_by_name(name) ⇒ Object



310
311
312
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 310

def delete_by_name name
  @buffers.delete_if {|b| b.filename == name }
end

#eachObject



268
269
270
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 268

def each
  @buffers.each {|k| yield(k)}
end

#element_at(index) ⇒ Object

for each buffer i need to store data, current_index (row), curpos (col offset) and title (filename).



265
266
267
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 265

def element_at index
  @buffers[index]
end

#firstObject



298
299
300
301
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 298

def first
  @counter = 0
  @buffers[@counter]
end

#insert(component, position, title = nil) ⇒ Object



313
314
315
316
317
318
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 313

def insert component, position, title=nil
  anew = RComponents.new(component, title)
  @buffers.insert position, anew
  @counter = position
  return anew
end

#lastObject



302
303
304
305
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 302

def last
  @counter = @buffers.size - 1
  @buffers[@counter]
end

#nextRBuffer

Would have liked to just return next buffer and not get lost in details of caller

Returns:

  • (RBuffer)

    next buffer/file



283
284
285
286
287
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 283

def next
  @counter += 1
  @counter = 0 if @counter >= @buffers.size
  @buffers[@counter]
end

#previousRBuffer

Returns previous buffer/file.

Returns:

  • (RBuffer)

    previous buffer/file



291
292
293
294
295
296
297
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 291

def previous
  $log.debug " previous bs: #{@buffers.size}, #{@counter}  "
  @counter -= 1
  return last() if @counter < 0
  $log.debug " previous ctr  #{@counter} "
  @buffers[@counter]
end

#sizeObject Also known as: count



323
324
325
# File 'lib/rbcurse/experimental/widgets/multiform.rb', line 323

def size
  @buffers.size
end