Module: RubyCurses::MultiBuffers

Extended by:
MultiBuffers
Included in:
MultiBuffers
Defined in:
lib/rbcurse/core/include/multibuffer.rb

Overview

TODO allow setting of a limit, so in some cases where we keep adding programatically, the

Instance Method Summary collapse

Instance Method Details

#add_content(text, config = {}) ⇒ Object

add content to buffers of a textview

Parameters:

  • text (Array)
  • options, (Hash)

    typically :content_type => :ansi or :tmux



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rbcurse/core/include/multibuffer.rb', line 17

def add_content text, config={}
  unless @_buffers
    bind_key(?\M-n, :buffer_next)
    bind_key(?\M-p, :buffer_prev)
    bind_key(KEY_BACKSPACE, :buffer_prev) # backspace, already hardcoded in textview !
    bind_key(?:, :buffer_menu)
  end
  @_buffers ||= []
  @_buffers_conf ||= []
  @_buffers << text
  @_buffers_conf << config
  @_buffer_ctr ||= 0
  $log.debug "XXX:  HELP adding text #{@_buffers.size} "
end

#buffer_lastObject



54
55
56
57
58
# File 'lib/rbcurse/core/include/multibuffer.rb', line 54

def buffer_last
  @_buffer_ctr = @_buffers.count - 1
  l = @_buffers.last
  set_content l, @_buffers_conf.last
end

#buffer_menuObject

display a menu so user can do buffer management However, how can application add to these. Or disable, such as when we add buffer delete or buffer insert or edit



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rbcurse/core/include/multibuffer.rb', line 66

def buffer_menu
  menu = PromptMenu.new self do
    item :n, :buffer_next
    item :p, :buffer_prev
    item :b, :scroll_backward
    item :f, :scroll_forward
    item :q, :close
    submenu :m, "submenu..." do
      item :p, :goto_last_position
      item :r, :scroll_right
      item :l, :scroll_left
    end
  end
  menu.display_new :title => "Buffer Menu"
end

#buffer_nextObject

display next buffer



33
34
35
36
37
38
39
# File 'lib/rbcurse/core/include/multibuffer.rb', line 33

def buffer_next
  @_buffer_ctr += 1
  x = @_buffer_ctr
  l = @_buffers[x]
  @_buffer_ctr = 0 unless l
  set_content @_buffers[@_buffer_ctr], @_buffers_conf[@_buffer_ctr]
end

#buffer_prevObject

display previous buffer if any



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rbcurse/core/include/multibuffer.rb', line 42

def buffer_prev
  if @_buffer_ctr < 1
    buffer_last
    return
  end
  @_buffer_ctr -= 1 if @_buffer_ctr > 0
  x = @_buffer_ctr
  l = @_buffers[x]
  if l
    set_content l, @_buffers_conf[x]
  end
end

#closeObject

close window, a bit clever



60
61
62
# File 'lib/rbcurse/core/include/multibuffer.rb', line 60

def close
  @graphic.ungetch(?q.ord)
end