Class: RubyCurses::CommandWindow
- Includes:
- Utils
- Defined in:
- lib/rbcurse/rcommandwindow.rb
Defined Under Namespace
Classes: ListObject
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#window ⇒ Object
readonly
required for keyboard or printing.
Instance Method Summary collapse
- #cget(param) ⇒ Object
-
#clear ⇒ Object
clears the window, leaving the title line as is, from row 1 onwards.
-
#configure(*val, &block) ⇒ Object
might as well add more keys for paging.
- #destroy ⇒ Object
-
#display_interactive(text, config = {}) {|@to| ... } ⇒ Object
lower line of border will get erased currently since we are writing to last line FIXME.
-
#display_menu(list, options = {}) ⇒ Object
do not go more than 3 columns and do not print more than window TODO FIXME.
-
#handle_keys ⇒ Object
todo handle mappings, so user can map keys TODO.
-
#initialize(form = nil, aconfig = {}, &block) ⇒ CommandWindow
constructor
A new instance of CommandWindow.
-
#press(ch) ⇒ Object
handles a key, commandline.
-
#refresh ⇒ Object
refresh whatevers painted onto the window.
- #set_layout(height = 0, width = 0, top = 0, left = 0) ⇒ Object
-
#stopping? ⇒ Boolean
message box.
-
#udisplay_list(text, config = {}) {|@to| ... } ⇒ Object
non interactive list display - EACH CALL IS CREATING A LIST OBJECT.
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text
Constructor Details
#initialize(form = nil, aconfig = {}, &block) ⇒ CommandWindow
Returns a new instance of CommandWindow.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rbcurse/rcommandwindow.rb', line 28 def initialize form=nil, aconfig={}, &block @config = aconfig @config.each_pair { |k,v| instance_variable_set("@#{k}",v) } instance_eval &block if block_given? if @layout.nil? set_layout(1,80, 27, 0) end @height = @layout[:height] @width = @layout[:width] @window = VER::Window.new(@layout) @start = 0 # row for display of text with paging @list = [] require 'forwardable' require 'rbcurse/extras/bottomline' @bottomline = Bottomline.new @window, 0 @bottomline.name = "rcommandwindow's bl" extend Forwardable def_delegators :@bottomline, :ask, :say, :agree, :choose #, :display_text_interactive if @box == :border @window.box 0,0 elsif @box @window.attron(Ncurses.COLOR_PAIR($normalcolor) | Ncurses::A_REVERSE) @window.mvhline 0,0,1,@width @window.printstring 0,0,@title, $normalcolor #, 'normal' if @title @window.attroff(Ncurses.COLOR_PAIR($normalcolor) | Ncurses::A_REVERSE) else @window.printstring 0,0,@title, $normalcolor, 'reverse' if @title end @window.wrefresh @panel = @window.panel Ncurses::Panel.update_panels @window.wrefresh @row_offset = 0 if @box @row_offset = 1 end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/rbcurse/rcommandwindow.rb', line 23 def config @config end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
24 25 26 |
# File 'lib/rbcurse/rcommandwindow.rb', line 24 def layout @layout end |
#window ⇒ Object (readonly)
required for keyboard or printing
25 26 27 |
# File 'lib/rbcurse/rcommandwindow.rb', line 25 def window @window end |
Instance Method Details
#cget(param) ⇒ Object
133 134 135 |
# File 'lib/rbcurse/rcommandwindow.rb', line 133 def cget param @config[param] end |
#clear ⇒ Object
clears the window, leaving the title line as is, from row 1 onwards
230 231 232 233 234 235 236 |
# File 'lib/rbcurse/rcommandwindow.rb', line 230 def clear @window.wmove 1,1 @window.wclrtobot @window.box 0,0 if @box == :border # lower line of border will get erased currently since we are writing to # last line FIXME end |
#configure(*val, &block) ⇒ Object
might as well add more keys for paging.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rbcurse/rcommandwindow.rb', line 123 def configure(*val , &block) case val.size when 1 return @config[val[0]] when 2 @config[val[0]] = val[1] instance_variable_set("@#{val[0]}", val[1]) end instance_eval &block if block_given? end |
#destroy ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rbcurse/rcommandwindow.rb', line 142 def destroy $log.debug "DESTROY : rcommandwindow" if @window begin panel = @window.panel Ncurses::Panel.del_panel(panel.pointer) if panel @window.delwin rescue => exc end end end |
#display_interactive(text, config = {}) {|@to| ... } ⇒ Object
lower line of border will get erased currently since we are writing to last line FIXME
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/rbcurse/rcommandwindow.rb', line 237 def display_interactive text, config={} if @to @to.content text else config[:box] = @box @to = ListObject.new self, text, config end yield @to if block_given? @to.display_interactive # this returns the item selected @to # this will return the ListObject to the user with list and current_index end |
#display_menu(list, options = {}) ⇒ Object
do not go more than 3 columns and do not print more than window TODO FIXME
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/rbcurse/rcommandwindow.rb', line 154 def list, ={} indexing = [:indexing] max_cols = 3 # maximum no of columns, we will reduce based on data size l_succ = "`" act_height = @height if @box act_height = @height - 2 end lh = list.size if lh < act_height $log.debug "DDD inside one window" if $log.debug? list.each_with_index { |e, i| text = e case e when Array text = e.first + " ..." end if indexing == :number text = "%d. %s" % [i+1, text] elsif indexing == :letter text = "%s. %s" % [l_succ.succ!, text] end @window.printstring i+@row_offset, 1, text, $normalcolor } else $log.debug "DDD inside two window" if $log.debug? row = 0 h = act_height cols = (lh*1.0 / h).ceil cols = max_cols if cols > max_cols # sometimes elements are large like directory paths, so check size datasize = list.first.length if datasize > @width/3 # keep safety margin since checking only first row cols = 1 elsif datasize > @width/2 cols = [2,cols].min end adv = (@width/cols).to_i colct = 0 col = 1 $log.debug "DDDcols #{cols}, adv #{adv} size: #{lh} h: #{act_height} w #{@width} " if $log.debug? list.each_with_index { |e, i| # check that row + @row_offset < @top + @height or whatever TODO text = e # signify that there's a deeper level case e when Array text = e.first + "..." end if indexing == :number text = "%d. %s" % [i+1, text] elsif indexing == :letter text = "%s. %s" % [l_succ.succ!, text] end @window.printstring row+@row_offset, col, text, $normalcolor colct += 1 if colct == cols col = 1 row += 1 colct = 0 else col += adv end } end Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end |
#handle_keys ⇒ Object
todo handle mappings, so user can map keys TODO
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rbcurse/rcommandwindow.rb', line 71 def handle_keys begin while((ch = @window.getchar()) != 999 ) case ch when -1 next else press ch break if @stop yield ch if block_given? end end ensure destroy end return #@selected_index end |
#press(ch) ⇒ Object
handles a key, commandline
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rbcurse/rcommandwindow.rb', line 89 def press ch ch = ch.getbyte(0) if ch.class==String ## 1.9 $log.debug " XXX press #{ch} " if $log.debug? case ch when -1 return when KEY_F1, 27, ?\C-q.getbyte(0) @stop = true return when KEY_ENTER, 10, 13 #$log.debug "popup ENTER : #{@selected_index} " #$log.debug "popup ENTER : #{field.name}" if !field.nil? @stop = true return when ?\C-d.getbyte(0) @start += @height-1 bounds_check when KEY_UP @start -= 1 @start = 0 if @start < 0 when KEY_DOWN @start += 1 bounds_check when ?\C-b.getbyte(0) @start -= @height-1 @start = 0 if @start < 0 when 0 @start = 0 end Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end |
#refresh ⇒ Object
refresh whatevers painted onto the window
224 225 226 227 228 |
# File 'lib/rbcurse/rcommandwindow.rb', line 224 def refresh Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end |
#set_layout(height = 0, width = 0, top = 0, left = 0) ⇒ Object
137 138 139 140 141 |
# File 'lib/rbcurse/rcommandwindow.rb', line 137 def set_layout(height=0, width=0, top=0, left=0) @layout = { :height => height, :width => width, :top => top, :left => left } @height = height @width = width end |
#stopping? ⇒ Boolean
message box
67 68 69 |
# File 'lib/rbcurse/rcommandwindow.rb', line 67 def stopping? @stop end |
#udisplay_list(text, config = {}) {|@to| ... } ⇒ Object
non interactive list display - EACH CALL IS CREATING A LIST OBJECT
249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/rbcurse/rcommandwindow.rb', line 249 def udisplay_list text, config={} if @to @to.content text else config[:box] = @box @to = ListObject.new self, text, config end #@to ||= ListObject.new self, text, config yield @to if block_given? @to.display_content @to end |