_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q23800
Canis.Table.model_row
train
def model_row index array = @list[index] array.each_with_index { |c,i| # if columns added later we could be overwriting the width ch = get_column(i) ch.width = c.to_s.length + 2 } # maintains index in current pointer and gives next or prev @column_pointer = Circular.new array.size()-1 self end
ruby
{ "resource": "" }
q23801
Canis.Table.save_as
train
def save_as outfile _t = "(all rows)" if @selected_indices.size > 0 _t = "(selected rows)" end unless outfile outfile = get_string "Enter file name to save #{_t} as " return unless outfile end # if there is a selection, then write only selected rows l = nil if @selected_indices.size > 0 l = [] @list.each_with_index { |v,i| l << v if @selected_indices.include? i } else l = @list end File.open(outfile, 'w') {|f| l.each {|r| line = r.join "\t" f.puts line } } end
ruby
{ "resource": "" }
q23802
Canis.Table.delete_at
train
def delete_at ix return unless @list raise ArgumentError, "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list.length fire_dimension_changed #@list.delete_at(ix + @_header_adjustment) @list.delete_at(ix) end
ruby
{ "resource": "" }
q23803
Canis.Table.set_value_at
train
def set_value_at row,col,val actrow = row + @_header_adjustment @list[actrow , col] = val fire_row_changed actrow self end
ruby
{ "resource": "" }
q23804
Canis.Table.move_column
train
def move_column ix, newix acol = @chash.delete_at ix @chash.insert newix, acol _invalidate_width_cache #tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE) #fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce end
ruby
{ "resource": "" }
q23805
Canis.Table.fire_action_event
train
def fire_action_event if header_row? if @table_row_sorter x = _convert_curpos_to_column c = @chash[x] # convert to index in data model since sorter only has data_model index = c.index @table_row_sorter.toggle_sort_order index @table_row_sorter.sort fire_dimension_changed end end super end
ruby
{ "resource": "" }
q23806
Canis.Table.matching_indices
train
def matching_indices raise "block required for matching_indices" unless block_given? @indices = [] ## content can be string or Chunkline, so we had to write <tt>index</tt> for this. @list.each_with_index do |fields, ix| flag = yield ix, fields if flag @indices << ix end end #$log.debug "XXX: INDICES found #{@indices}" if @indices.count > 0 fire_dimension_changed init_vars else @indices = nil end #return @indices end
ruby
{ "resource": "" }
q23807
Canis.Table.render_all
train
def render_all if @indices && @indices.count > 0 @indices.each_with_index do |ix, jx| render @pad, jx, @list[ix] end else @list.each_with_index { |line, ix| # FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix].to_s) render @pad, ix, line } end end
ruby
{ "resource": "" }
q23808
Enceladus::Configuration.Image.reset!
train
def reset! self.base_url = nil self.secure_base_url = nil self.backdrop_sizes = [] self.logo_sizes = [] self.logo_sizes = [] self.poster_sizes = [] self.profile_sizes = [] self.still_sizes = [] self.include_image_language = "en" self end
ruby
{ "resource": "" }
q23809
Enceladus::Configuration.Image.valid?
train
def valid? !base_url.nil? && !secure_base_url.nil? && backdrop_sizes.any? && logo_sizes.any? && poster_sizes.any? && profile_sizes.any? && still_sizes.any? end
ruby
{ "resource": "" }
q23810
Danger.DangerPronto.lint
train
def lint(commit = nil) files = pronto(commit) return if files.empty? markdown offenses_message(files) end
ruby
{ "resource": "" }
q23811
Cork.Board.path
train
def path(pathname, relative_to = Pathname.pwd) if pathname path = Pathname(pathname).relative_path_from(relative_to) "`#{path}`" else '' end end
ruby
{ "resource": "" }
q23812
Cork.Board.labeled
train
def labeled(label, value, justification = 12) if value title = "- #{label}:" if value.is_a?(Enumerable) lines = [wrap_string(title, indentation_level)] lines += value.map do |v| wrap_string("- #{v}", indentation_level + 2) end puts lines.join("\n") else string = title.ljust(justification) + "#{value}" puts wrap_string(string, indentation_level) end end end
ruby
{ "resource": "" }
q23813
Cork.Board.info
train
def info(message) indentation = verbose? ? @indentation_level : 0 indented = wrap_string(message, indentation) puts(indented) if block_given? @indentation_level += 2 @treat_titles_as_messages = true yield @treat_titles_as_messages = false @indentation_level -= 2 end end
ruby
{ "resource": "" }
q23814
Cork.Board.title
train
def title(title, verbose_prefix = '', relative_indentation = 2) if @treat_titles_as_messages message(title, verbose_prefix) else puts_title(title, verbose_prefix) end if block_given? @indentation_level += relative_indentation @title_level += 1 yield @indentation_level -= relative_indentation @title_level -= 1 end end
ruby
{ "resource": "" }
q23815
Cork.Board.message
train
def message(message, verbose_prefix = '', relative_indentation = 2) message = verbose_prefix + message if verbose? puts_indented message if verbose? @indentation_level += relative_indentation yield if block_given? @indentation_level -= relative_indentation end
ruby
{ "resource": "" }
q23816
Canis.Container.correct_component
train
def correct_component c raise "Form is still not set in Container" unless @form attach_form(c) unless c.form @last_row ||= @row + 1 inset = 2 # 2011-10-20 current default behaviour is to stack if @positioning == :stack c.row = @last_row c.col = @col + inset # do not advance row, save col for next row @last_row += 1 elsif @positioning == :relative # UNTESTED NOTE if (c.row || 0) <= 0 $log.warn "c.row in CONTAINER is #{c.row} " c.row = @last_row @last_row += 1 elsif c.row > @row + @height -1 $log.warn "c.row in CONTAINER exceeds container. #{c.row} " c.row -= @height - @row_offset else # this is where it should come c.row += @row + @row_offset @last_row = c.row + 1 end if (c.col || 0) <= 0 c.col = @col + inset + @col_offset elsif c.col > @col + @width -1 c.col -= @width elsif c.col == @col c.col += @col_offset + inset else #f c.col < @col c.col += @col+@col_offset end $log.debug "XXX: CORRECT #{c.name} r:#{c.row} c:#{c.col} " end @first_time = false end
ruby
{ "resource": "" }
q23817
RTanque.Runner.start
train
def start(gui = true) if gui require 'rtanque/gui' window = RTanque::Gui::Window.new(self.match) trap(:INT) { window.close } window.show else trap(:INT) { self.match.stop } self.match.start end end
ruby
{ "resource": "" }
q23818
Canis.App.loop
train
def loop &block @form.repaint @window.wrefresh Ncurses::Panel.update_panels @break_key = ?\C-q.getbyte(0) # added this extra loop since from some places we exit using throw :close # amd that was in a much higher place, and was getting us right out, with # no chance of user canceling quit. This extra loop allows us to remain # added on 2011-11-24 while true catch :close do while((ch = @window.getchar()) != 999 ) if ch == @break_key || ch == @quit_key break end # 2014-08-19 - 22:51 commented next line, too much choice. keep it simple. delete in a month FIXME #yield ch if block # <<<---- # this is what the user should have control ove. earlier we would put this in # a try catch block so user could do what he wanted with the error. Now we # need to get it to him somehow, perhaps through a block or on_error event begin # execute a code block so caller program can handle keys from a hash or whatever. # NOTE: these keys will not appear in help # FIXME : ideally if its just a hash, we should allow user to give it to form # or widget which it will use, or merge, and be able to print help from if @keyblock str = keycode_tos ch # why did we ever want to convert to a symbol. why not just pass it as is. #@keyblock.call(str.gsub(/-/, "_").to_sym) # not used ever ret = @keyblock.call(str) if ret @form.repaint next end end @form.handle_key ch rescue => err $log.debug( "app.rb handle_key rescue reached ") $log.debug( err.to_s) $log.debug(err.backtrace.join("\n")) textdialog [err.to_s, *err.backtrace], :title => "Exception" end @window.wrefresh end end # catch stopping = @window.fire_close_handler @window.wrefresh break if stopping.nil? || stopping end # while end
ruby
{ "resource": "" }
q23819
Canis.App.safe_loop
train
def safe_loop &block begin loop &block rescue => ex $log.debug( "APP.rb rescue reached ") $log.debug( ex) if ex $log.debug(ex.backtrace.join("\n")) if ex ensure close # putting it here allows it to be printed on screen, otherwise it was not showing at all. if ex puts "========== EXCEPTION ==========" p ex puts "===============================" puts(ex.backtrace.join("\n")) end end end
ruby
{ "resource": "" }
q23820
Canis.App.field_help_text
train
def field_help_text f = @form.get_current_field if f.respond_to?('help_text') h = f.help_text h = "No help text defined for this field.\nTry F1, or press '?' for key-bindings." unless h textdialog "#{h}", :title => "Widget Help Text" else alert "Could not get field #{f} or does not respond to helptext. Try F1 or '?'" end end
ruby
{ "resource": "" }
q23821
Canis.App.longest_in_list
train
def longest_in_list list #:nodoc: longest = list.inject(0) do |memo,word| memo >= word.length ? memo : word.length end longest end
ruby
{ "resource": "" }
q23822
Canis.App._resolve_command
train
def _resolve_command opts, cmd return cmd if opts.include? cmd matches = opts.grep Regexp.new("^#{cmd}") end
ruby
{ "resource": "" }
q23823
Canis.App.run
train
def run &block begin # check if user has passed window coord in config, else root window @window = Canis::Window.root_window awin = @window catch(:close) do @form = Form.new @window #@form.bind_key(KEY_F1, 'help'){ display_app_help } # NOT REQUIRED NOW 2012-01-7 since form does it @form.bind_key([?q,?q], 'quit' ){ throw :close } if $log.debug? #@message = Variable.new #@message.value = "" $status_message ||= Variable.new # remember there are multiple levels of apps $status_message.value = "" #$error_message.update_command { @message.set_value($error_message.value) } if block begin yield_or_eval &block if block_given? # how the hell does a user trap exception if the loop is hidden from him ? FIXME loop rescue => ex $log.debug( "APP.rb rescue reached ") $log.debug( ex) if ex $log.debug(ex.backtrace.join("\n")) if ex ensure close # putting it here allows it to be printed on screen, otherwise it was not showing at all. if ex puts "========== EXCEPTION ==========" p ex puts "===============================" puts(ex.backtrace.join("\n")) end end nil else #@close_on_terminate = true self end #if block end # :close end end
ruby
{ "resource": "" }
q23824
Canis.App._process_args
train
def _process_args args, config, block_event, events #:nodoc: raise "FIXME seems uncalled _process_args, remove it this does not come up within a month 2014-08-19 " args.each do |arg| case arg when Array # please don't use this, keep it simple and use hash NOTE # we can use r,c, w, h row, col, width, height = arg config[:row] = row config[:col] = col config[:width] = width if width # width for most XXX ? config[:height] = height if height when Hash config.merge!(arg) if block_event block_event = config.delete(:block_event){ block_event } raise "Invalid event. Use #{events}" unless events.include? block_event end when String config[:name] = arg config[:title] = arg # some may not have title #config[:text] = arg # some may not have title end end end
ruby
{ "resource": "" }
q23825
Canis.ListFooter.print
train
def print comp config = @config row = comp.row + comp.height - 1 col = comp.col + 2 len = comp.width - col g = comp.form.window # we check just in case user nullifies it deliberately, since he may have changed config values @color_pair ||= get_color($datacolor, config[:color], config[:bgcolor]) @attrib ||= config[:attrib] || Ncurses::A_REVERSE # first print dashes through #g.printstring row, col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE # now call the block to get current values for footer text on left ftext = nil if @command_text ftext = text(comp) else if !@right_text # user has not specified right or left, so we use a default on left ftext = "#{comp.current_index} of #{comp.size} " end end g.printstring(row, col, ftext, @color_pair, @attrib) if ftext # user has specified text for right, print it if @right_text len = comp.width ftext = right_text(comp) c = len - ftext.length - 2 g.printstring row, c, ftext, @color_pair, @attrib end end
ruby
{ "resource": "" }
q23826
Canis.Window.set_layout
train
def set_layout(layout) case layout when Array $log.error "NIL in window constructor" if layout.include? nil raise ArgumentError, "Nil in window constructor" if layout.include? nil # NOTE this is just setting, and not replacing zero with max values @height, @width, @top, @left = *layout raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil? @layout = { :height => @height, :width => @width, :top => @top, :left => @left } when Hash @layout = layout [:height, :width, :top, :left].each do |name| instance_variable_set("@#{name}", @layout[name]) end end end
ruby
{ "resource": "" }
q23827
Canis.Window.destroy
train
def destroy # typically the ensure block should have this #$log.debug "win destroy start" $global_windows.delete self Ncurses::Panel.del_panel(@panel.pointer) if @panel delwin() if @window Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1 # destroy any pads that were created by widgets using get_pad @pads.each { |pad| FFI::NCurses.delwin(pad) if pad pad = nil } if @pads # added here to hopefully take care of this issue once and for all. # Whenever any window is destroyed, the root window is repainted. # # 2014-08-18 - 20:35 trying out without refresh all since lower dialog gets erased Window.refresh_all #$log.debug "win destroy end" end
ruby
{ "resource": "" }
q23828
Canis.Window.get_pad
train
def get_pad content_rows, content_cols pad = FFI::NCurses.newpad(content_rows, content_cols) @pads ||= [] @pads << pad ## added 2013-03-05 - 19:21 without next line how was pad being returned return pad end
ruby
{ "resource": "" }
q23829
Canis.Window.print_border_mb
train
def print_border_mb row, col, height, width, color, attr # the next is for xterm-256 att = get_attrib attr len = width len = Ncurses.COLS-0 if len == 0 # print a bar across the screen #attron(Ncurses.COLOR_PAIR(color) | att) # this works for newmessagebox but not for old one. # Even now in some cases some black shows through, if the widget is printing spaces # such as field or textview on a messagebox. # 2016-01-14 - replacing 1 with space since junk is showing up in some cases. space_char = " ".codepoints.first (row-1).upto(row+height-1) do |r| # this loop clears the screen, printing spaces does not work since ncurses does not do anything mvwhline(r, col, space_char, len) end #attroff(Ncurses.COLOR_PAIR(color) | att) mvwaddch row, col, Ncurses::ACS_ULCORNER mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6) mvwaddch row, col+width-5, Ncurses::ACS_URCORNER mvwvline( row+1, col, Ncurses::ACS_VLINE, height-4) mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER mvwhline(row+height-3, col+1, Ncurses::ACS_HLINE, width-6) mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER mvwvline( row+1, col+width-5, Ncurses::ACS_VLINE, height-4) end
ruby
{ "resource": "" }
q23830
Canis.Window.print_border
train
def print_border row, col, height, width, color, att=Ncurses::A_NORMAL raise "height needs to be supplied." if height.nil? raise "width needs to be supplied." if width.nil? att ||= Ncurses::A_NORMAL #$log.debug " inside window print_border r #{row} c #{col} h #{height} w #{width} " # 2009-11-02 00:45 made att nil for blanking out # FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view # when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53 ww=width-2 clr = " "*ww (row+1).upto(row+height-1) do |r| printstring( r, col+1, clr, color, att) end print_border_only row, col, height, width, color, att end
ruby
{ "resource": "" }
q23831
Canis.Window.print_border_only
train
def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL if att.nil? att = Ncurses::A_NORMAL else att = get_attrib att end wattron(Ncurses.COLOR_PAIR(color) | att) mvwaddch row, col, Ncurses::ACS_ULCORNER mvwhline( row, col+1, Ncurses::ACS_HLINE, width-2) mvwaddch row, col+width-1, Ncurses::ACS_URCORNER mvwvline( row+1, col, Ncurses::ACS_VLINE, height-1) mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER mvwhline(row+height-0, col+1, Ncurses::ACS_HLINE, width-2) mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1) wattroff(Ncurses.COLOR_PAIR(color) | att) end
ruby
{ "resource": "" }
q23832
Canis.TabbedPane.goto_last_item
train
def goto_last_item bc = @buttons.count f = nil @components[bc..-1].each { |c| if c.focusable f = c end } if f leave_current_component @current_component = f set_form_row end end
ruby
{ "resource": "" }
q23833
Canis.TabbedPane.goto_next_component
train
def goto_next_component if @current_component != nil leave_current_component if on_last_component? @_entered = false return :UNHANDLED end @current_index = @components.index(@current_component) index = @current_index + 1 index.upto(@components.length-1) do |i| f = @components[i] if f.focusable @current_index = i @current_component = f return set_form_row end end end @_entered = false return :UNHANDLED end
ruby
{ "resource": "" }
q23834
Canis.TabbedPane.goto_prev_component
train
def goto_prev_component if @current_component != nil leave_current_component if on_first_component? @_entered = false return :UNHANDLED end @current_index = @components.index(@current_component) index = @current_index -= 1 index.downto(0) do |i| f = @components[i] if f.focusable @current_index = i @current_component = f return set_form_row end end end return :UNHANDLED end
ruby
{ "resource": "" }
q23835
Canis.TabbedPane.make_buttons
train
def make_buttons names @action_buttons = [] $log.debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} " total = names.inject(0) {|total, item| total + item.length + 4} bcol = center_column total # this craps out when height is zero brow = @row + @height-2 brow = FFI::NCurses.LINES-2 if brow < 0 $log.debug "XXX: putting buttons :on #{brow} : #{@row} , #{@height} " button_ct=0 tpp = self names.each_with_index do |bname, ix| text = bname #underline = @underlines[ix] if !@underlines.nil? button = Button.new nil do text text name bname row brow col bcol #underline underline highlight_bgcolor $reversecolor color $datacolor bgcolor $datacolor end @action_buttons << button button.form = @form button.override_graphic @graphic index = button_ct tpp = self button.command { |form| @selected_index = index; @stop = true; # ActionEvent has source event and action_command fire_handler :PRESS, ActionEvent.new(tpp, index, button.text) #throw(:close, @selected_index) } button_ct += 1 bcol += text.length+6 end end
ruby
{ "resource": "" }
q23836
Canis.ComboBox.handle_key
train
def handle_key(ch) @current_index ||= 0 # added 2009-01-18 22:44 no point moving horiz or passing up to Field if not edit if !@editable if ch == KEY_LEFT or ch == KEY_RIGHT return :UNHANDLED end end case @arrow_key_policy when :ignore if ch == KEY_DOWN or ch == KEY_UP return :UNHANDLED end when :popup if ch == KEY_DOWN or ch == KEY_UP popup end end case ch #when KEY_UP # show previous value # previous_row #when KEY_DOWN # show previous value # next_row # adding spacebar to popup combo, as in microemacs 2010-10-01 13:21 when 32, KEY_DOWN+ META_KEY # alt down popup # pop up the popup else super end end
ruby
{ "resource": "" }
q23837
Canis.ComboBox.putc
train
def putc c if c >= 0 and c <= 127 ret = putch c.chr if ret == 0 addcol 1 if @editable set_modified end end return -1 # always ??? XXX end
ruby
{ "resource": "" }
q23838
Canis.ComboBox.putch
train
def putch char @current_index ||= 0 if @editable raise "how is it editable here in combo" super return 0 else match = next_match(char) text match unless match.nil? fire_handler :ENTER_ROW, self end @modified = true fire_handler :CHANGE, self # 2008-12-09 14:51 ??? 0 end
ruby
{ "resource": "" }
q23839
Canis.ComboBox.next_match
train
def next_match char start = @current_index start.upto(@list.length-1) do |ix| if @list[ix][0,1].casecmp(char) == 0 return @list[ix] unless @list[ix] == @buffer end @current_index += 1 end ## could not find, start from zero @current_index = 0 start = [@list.length()-1, start].min 0.upto(start) do |ix| if @list[ix][0,1].casecmp(char) == 0 return @list[ix] unless @list[ix] == @buffer end @current_index += 1 end @current_index = [@list.length()-1, @current_index].min return nil end
ruby
{ "resource": "" }
q23840
Canis.Devel.choose_file_and_view
train
def choose_file_and_view glob=nil, startdir="." glob ||= "**/*.rb" str = choose_file glob, :title => "Select a file", :directory => startdir, :help_text => "Enter pattern, use UP DOWN to traverse, Backspace to delete, ENTER to select. Esc-Esc to quit" if str and str != "" code_browse str end end
ruby
{ "resource": "" }
q23841
Canis.Devel.view_properties_as_tree
train
def view_properties_as_tree field=@form.get_current_field alert "Nil field" unless field return unless field text = [] tree = {} #iv = field.instance_variables.map do |v| v.to_s; end field.instance_variables.each do |v| val = field.instance_variable_get(v) klass = val.class if val.is_a? Array #tree[v.to_s] = val text << { v.to_s => val } val = val.size elsif val.is_a? Hash #tree[v.to_s] = val text << { v.to_s => val } if val.size <= 5 val = val.keys else val = val.keys.size.to_s + " [" + val.keys.first(5).join(", ") + " ...]" end end case val when String, Integer, TrueClass, FalseClass, NilClass, Array, Hash, Symbol ; else val = "Not shown" end text << "%-20s %10s %s" % [v, klass, val] end tree["Instance Variables"] = text pm = field.public_methods(false).map do |v| v.to_s; end tree["Public Methods"] = pm pm = field.public_methods(true) - field.public_methods(false) pm = pm.map do |v| v.to_s; end tree["Inherited Methods"] = pm #$log.debug " view_properties #{s.size} , #{s} " treedialog tree, :title => "Properties" end
ruby
{ "resource": "" }
q23842
Canis.MenuSeparator.repaint
train
def repaint acolor = get_color($reversecolor, @color, @bgcolor) #@parent.window.printstring( @row, 0, "|%s|" % ("-"*@width), acolor) @parent.window.mvwhline( @row, 1, Ncurses::ACS_HLINE, @width) # these 2 are probably overwritten by the borders @parent.window.mvaddch( @row, 0, Ncurses::ACS_LTEE) @parent.window.mvaddch( @row, @width+1, Ncurses::ACS_RTEE) end
ruby
{ "resource": "" }
q23843
Canis.Menu.select_item
train
def select_item ix0 return if @items.nil? or @items.empty? #$log.debug "insdie select item : #{ix0} active: #{@active_index}" if !@active_index.nil? @items[@active_index].on_leave end previtem = @active_index @active_index = ix0 if @items[ix0].enabled @items[ix0].on_enter else #$log.debug "insdie sele nxt item ENABLED FALSE : #{ix0}" if @active_index > previtem select_next_item else select_prev_item end end @window.refresh end
ruby
{ "resource": "" }
q23844
Canis.Menu.array_width
train
def array_width a longest = a.max {|a,b| a.to_s.length <=> b.to_s.length } #$log.debug "array width #{longest}" longest.to_s.length end
ruby
{ "resource": "" }
q23845
Canis.Menu.handle_key
train
def handle_key ch if !@current_menu.empty? cmenu = @current_menu.last else cmenu = self end if !@@menus.empty? cmenu = @@menus.last else cmenu = self end case ch when KEY_DOWN cmenu.select_next_item #return cmenu.fire # XXX 2010-10-16 21:39 trying out if cmenu.is_a? Canis::Menu #alert "is a menu" # this gets triggered even when we are on items end when KEY_UP cmenu.select_prev_item when KEY_ENTER, 10, 13, 32 # added 32 2008-11-27 23:50 return cmenu.fire when KEY_LEFT if cmenu.parent.is_a? Canis::Menu #$log.debug "LEFT IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}" #$log.debug "left IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}" end ret = cmenu.select_left_item # 2011-09-24 V1.3.1 attempt to goto left item if columns if ret == :UNHANDLED if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.parent.current_menu.empty? #$log.debug " ABOU TO DESTROY DUE TO LEFT" cmenu.current_menu.pop @@menus.pop ## NEW cmenu.destroy return :UNHANDLED end # LEFT on a menu list allows me to close and return to higher level if cmenu.parent.is_a? Canis::Menu #and !cmenu.parent.current_menu.empty? #$log.debug " ABOU TO DESTROY DUE TO LEFT" cmenu.current_menu.pop @@menus.pop ## NEW cmenu.destroy #return :UNHANDLED end end when KEY_RIGHT $log.debug "RIGHTIN MENU : #{text} " if cmenu.active_index if cmenu.items[cmenu.active_index].is_a? Canis::Menu #alert "could fire here cmenu: #{cmenu.text}, par: #{cmenu.parent.text} " cmenu.fire return #$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}" #$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}" end end # This introduces a bug if no open items ret = cmenu.select_right_item # 2011-09-24 V1.3.1 attempt to goto right item if columns #alert "attempting to select right #{ret} " if ret == :UNHANDLED #if cmenu.parent.is_a? Canis::Menu and !cmenu.parent.current_menu.empty? if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.current_menu.empty? $log.debug " ABOU TO DESTROY DUE TO RIGHT" cmenu.current_menu.pop @@menus.pop cmenu.destroy return :UNHANDLED end end else ret = check_mnemonics cmenu, ch return ret end end
ruby
{ "resource": "" }
q23846
Canis.MenuBar.set_menu
train
def set_menu index #$log.debug "set meu: #{@active_index} #{index}" # first leave the existing window menu = @items[@active_index] menu.on_leave # hide its window, if open # now move to given menu @active_index = index menu = @items[@active_index] menu.on_enter #display window, if previous was displayed # move cursor to selected menu option on top, not inside list @window.wmove menu.row, menu.col # menu.show # menu.window.wrefresh # XXX we need this end
ruby
{ "resource": "" }
q23847
Canis.MenuBar.handle_keys
train
def handle_keys @selected = false @repaint_required = true # added 2011-12-12 otherwise keeps repainting and you see a flicker @toggle_key ||= 27 # default switch off with ESC, if nothing else defined set_menu 0 begin catch(:menubarclose) do while((ch = @window.getchar()) != @toggle_key ) #$log.debug "menuubar inside handle_keys : #{ch}" if ch != -1 case ch when -1 next when KEY_DOWN if !@selected current_menu.fire else current_menu.handle_key ch end @selected = true when KEY_ENTER, 10, 13, 32 @selected = true ret = current_menu.handle_key ch #break; ## 2008-12-29 18:00 This will close after firing anything break if ret == :CLOSE when KEY_UP current_menu.handle_key ch when KEY_LEFT ret = current_menu.handle_key ch prev_menu if ret == :UNHANDLED when KEY_RIGHT ret = current_menu.handle_key ch next_menu if ret == :UNHANDLED when ?\C-g.getbyte(0) # abort throw :menubarclose else ret = current_menu.handle_key ch if ret == :UNHANDLED Ncurses.beep else break # we handled a menu action, close menubar (THIS WORKS FOR MNEMONICS ONLY and always) end end Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end end # catch ensure #ensure is required becos one can throw a :close $log.debug " DESTROY IN ENSURE" current_menu.clear_menus @repaint_required = false destroy # Note that we destroy the menu bar upon exit end end
ruby
{ "resource": "" }
q23848
Canis.KeyLabelPrinter.update_application_key_label
train
def update_application_key_label(display_code, new_display_code, text) @repaint_required = true labels = key_labels() raise "labels are nil !!!" unless labels labels.each_index do |ix| lab = labels[ix] next if lab.nil? if lab[0] == display_code labels[ix] = [new_display_code , text] $log.debug("updated #{labels[ix]}") return true end end return false end
ruby
{ "resource": "" }
q23849
RubyCurses.StackFlow.handle_key
train
def handle_key ch $log.debug " STACKFLOW handle_key #{ch} " return if @components.empty? _multiplier = ($multiplier == 0 ? 1 : $multiplier ) # should this go here 2011-10-19 unless @_entered $log.warn "XXX WARN: calling ON_ENTER since in this situation it was not called" on_enter end if ch == KEY_TAB $log.debug "STACKFLOW GOTO NEXT TAB" return goto_next_component elsif ch == KEY_BTAB return goto_prev_component end comp = @current_component $log.debug " STACKFLOW handle_key #{ch}: #{comp}" if comp ret = comp.handle_key(ch) $log.debug " STACKFLOW handle_key#{ch}: #{comp} returned #{ret} " if ret != :UNHANDLED comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL # in repaint of this. return ret end $log.debug "XXX STACKFLOW key unhandled by comp #{comp.name} " else $log.warn "XXX STACKFLOW key unhandled NULL comp" end case ch when ?\C-c.getbyte(0) $multiplier = 0 return 0 when ?0.getbyte(0)..?9.getbyte(0) $log.debug " VIM coming here to set multiplier #{$multiplier} " $multiplier *= 10 ; $multiplier += (ch-48) return 0 end ret = process_key ch, self # allow user to map left and right if he wants if ret == :UNHANDLED case ch when KEY_UP # form will pick this up and do needful return goto_prev_component #unless on_first_component? when KEY_LEFT # if i don't check for first component, key will go back to form, # but not be processes. so focussed remain here, but be false. # In case of returnign an unhandled TAB, on_leave will happen and cursor will move to # previous component outside of this. return goto_prev_component unless on_first_component? when KEY_RIGHT return goto_next_component #unless on_last_component? when KEY_DOWN return goto_next_component #unless on_last_component? else @_entered = false return :UNHANDLED end end $multiplier = 0 return 0 end
ruby
{ "resource": "" }
q23850
RubyCurses.StackFlow.leave_current_component
train
def leave_current_component begin @current_component.on_leave rescue FieldValidationException => fve alert fve.to_s end # NOTE this is required, since repaint will just not happen otherwise # Some components are erroneously repainting all, after setting this to true so it is # working there. @current_component.repaint_required true $log.debug " after on_leave STACKFLOW XXX #{@current_component.focussed} #{@current_component.name}" @current_component.repaint end
ruby
{ "resource": "" }
q23851
Canis.NewListSelectable.add_to_selection
train
def add_to_selection crow=@current_index-@_header_adjustment @last_clicked ||= crow min = [@last_clicked, crow].min max = [@last_clicked, crow].max case @selection_mode when :multiple @widget_scrolled = true # FIXME we need a better name if @selected_indices.include? crow # delete from last_clicked until this one in any direction min.upto(max){ |i| @selected_indices.delete i } lse = ListSelectionEvent.new(min, max, self, :DELETE) fire_handler :LIST_SELECTION_EVENT, lse else # add to selection from last_clicked until this one in any direction min.upto(max){ |i| @selected_indices << i unless @selected_indices.include?(i) } lse = ListSelectionEvent.new(min, max, self, :INSERT) fire_handler :LIST_SELECTION_EVENT, lse end else end @repaint_required = true self end
ruby
{ "resource": "" }
q23852
Canis.NewListSelectable.list_bindings
train
def list_bindings # what about users wanting 32 and ENTER to also go to next row automatically # should make that optional, TODO bind_key($row_selector || 32, 'toggle selection') { toggle_row_selection } # 2013-03-24 - 14:46 added condition so single select does not get these if @selection_mode == :multiple bind_key(0, 'range select') { add_to_selection } bind_key(?+, :ask_select) # --> calls select_values bind_key(?-, :ask_unselect) # please implement FIXME TODO bind_key(?a, :select_all) bind_key(?*, :invert_selection) bind_key(?u, :clear_selection) end @_header_adjustment ||= 0 # incase caller does not use @_events << :LIST_SELECTION_EVENT unless @_events.include? :LIST_SELECTION_EVENT end
ruby
{ "resource": "" }
q23853
Canis.DefaultTreeModel.add
train
def add nodechild, allows_children=true, &block # calling TreeNode.add $log.debug " XXX def add of DTM #{nodechild} to root " node = @root.add nodechild, allows_children, &block if @handler # only if someone is listening, won't fire when being prepared tme = TreeModelEvent.new(row, row,:ALL_COLUMNS, self, :INSERT) fire_handler :TREE_MODEL_EVENT, tme end #return @root return node end
ruby
{ "resource": "" }
q23854
Canis.DefaultTreeModel.undo
train
def undo where raise "not yet used" return unless @delete_buffer case @delete_buffer[0] when Array @delete_buffer.each do |r| insert where, r end else insert where, @delete_buffer end end
ruby
{ "resource": "" }
q23855
Canis.DefaultTreeModel.data=
train
def data=(data) raise "not yet used" raise "Data nil or invalid" if data.nil? or data.size == 0 delete_all @data = data tme = TreeModelEvent.new(0, @data.length-1,:ALL_COLUMNS, self, :INSERT) fire_handler :TREE_MODEL_EVENT, tme end
ruby
{ "resource": "" }
q23856
Canis.TreeNode.add
train
def add node, allows_children=true, &block raise IllegalStateException, "Cannot add a child to this node" unless @allows_children $log.debug " XXX def add of TreeNode #{node} parent #{self} " case node when Array node.each do |e| add e, allows_children, &block end when Hash node.each_pair { |name, val| n = _add name, allows_children, &block n.add val, allows_children, &block } else return _add node, allows_children, &block end self end
ruby
{ "resource": "" }
q23857
Canis.TreeNode.user_object_path
train
def user_object_path arr = [] arr << self.user_object.to_s traverse_up do |e| arr << e.user_object.to_s end arr.reverse! end
ruby
{ "resource": "" }
q23858
Canis.Bottomline.say
train
def say statement, config={} @window ||= _create_footer_window #@window.show #unless @window.visible? $log.debug "XXX: inside say win #{@window} !" case statement when Question if config.has_key? :color_pair $log.debug "INSIDE QUESTION 2 " if $log.debug? else $log.debug "XXXX SAY using colorpair: #{statement.color_pair} " if $log.debug? config[:color_pair] = statement.color_pair end else $log.debug "XXX INSDIE SAY #{statement.class} " if $log.debug? end statement = statement.to_str template = ERB.new(statement, nil, "%") statement = template.result(binding) @prompt_length = statement.length # required by ask since it prints after @statement = statement # clear_line print_str statement, config end
ruby
{ "resource": "" }
q23859
Canis.Bottomline.say_with_pause
train
def say_with_pause statement, config={} @window ||= _create_footer_window #@window.show #unless @window.visible? # 2011-10-14 23:52:52 say statement, config @window.wrefresh Ncurses::Panel.update_panels ch=@window.getchar() hide_bottomline ## return char so we can use for asking for one character return ch end
ruby
{ "resource": "" }
q23860
Canis.Bottomline.say_with_wait
train
def say_with_wait statement, config={} @window ||= _create_footer_window #@window.show #unless @window.visible? # 2011-10-14 23:52:59 say statement, config @window.wrefresh Ncurses::Panel.update_panels sleep 0.5 hide_bottomline end
ruby
{ "resource": "" }
q23861
Canis.Bottomline.explain_error
train
def explain_error( error ) say_with_pause(@question.responses[error]) unless error.nil? if @question.responses[:ask_on_error] == :question say(@question) elsif @question.responses[:ask_on_error] say(@question.responses[:ask_on_error]) end end
ruby
{ "resource": "" }
q23862
Canis.Bottomline.print_str
train
def print_str(text, config={}) win = config.fetch(:window, @window) # assuming its in App x = config.fetch :x, 0 # @message_row # Ncurses.LINES-1, 0 since one line window 2011-10-8 y = config.fetch :y, 0 $log.debug "XXX: print_str #{win} with text : #{text} at #{x} #{y} " color = config[:color_pair] || $datacolor raise "no window for ask print in #{self.class} name: #{name} " unless win color=Ncurses.COLOR_PAIR(color); win.attron(color); #win.mvprintw(x, y, "%-40s" % text); win.mvprintw(x, y, "%s" % text); win.attroff(color); win.refresh # FFI NW 2011-09-9 , added back gets overwritten end
ruby
{ "resource": "" }
q23863
Canis.Bottomline.display_text_interactive
train
def display_text_interactive text, config={} require 'canis/core/util/rcommandwindow' ht = config[:height] || 15 layout = { :height => ht, :width => Ncurses.COLS-1, :top => Ncurses.LINES-ht+1, :left => 0 } rc = CommandWindow.new nil, :layout => layout, :box => true, :title => config[:title] w = rc.window #rc.text "There was a quick brown fox who ran over the lazy dog and then went over the moon over and over again and again" rc.display_interactive(text) { |l| l.focussed_attrib = 'bold' # Ncurses::A_UNDERLINE l.focussed_symbol = '>' } rc = nil end
ruby
{ "resource": "" }
q23864
Canis.Bottomline.list
train
def list( items, mode = :rows, option = nil ) items = items.to_ary.map do |item| ERB.new(item, nil, "%").result(binding) end case mode when :inline option = " or " if option.nil? case items.size when 0 "" when 1 items.first when 2 "#{items.first}#{option}#{items.last}" else items[0..-2].join(", ") + "#{option}#{items.last}" end when :columns_across, :columns_down max_length = actual_length( items.max { |a, b| actual_length(a) <=> actual_length(b) } ) if option.nil? limit = @wrap_at || 80 option = (limit + 2) / (max_length + 2) end items = items.map do |item| pad = max_length + (item.length - actual_length(item)) "%-#{pad}s" % item end row_count = (items.size / option.to_f).ceil if mode == :columns_across rows = Array.new(row_count) { Array.new } items.each_with_index do |item, index| rows[index / option] << item end rows.map { |row| row.join(" ") + "\n" }.join else columns = Array.new(option) { Array.new } items.each_with_index do |item, index| columns[index / row_count] << item end list = "" columns.first.size.times do |index| list << columns.map { |column| column[index] }. compact.join(" ") + "\n" end list end else items.map { |i| "#{i}\n" }.join end end
ruby
{ "resource": "" }
q23865
DelSolr.Document.construct_field_tag
train
def construct_field_tag(name, value, options={}) options[:name] = name.to_s use_cdata = options.delete(:cdata) return "<field#{options.to_xml_attribute_string}>#{use_cdata ? cdata(value) : value}</field>\n" end
ruby
{ "resource": "" }
q23866
Canis.DefaultListSelectionModel.goto_next_selection
train
def goto_next_selection return if selected_rows().length == 0 row = selected_rows().sort.find { |i| i > @obj.current_index } row ||= @obj.current_index #@obj.current_index = row @obj.goto_line row end
ruby
{ "resource": "" }
q23867
Canis.DefaultListSelectionModel.goto_prev_selection
train
def goto_prev_selection return if selected_rows().length == 0 row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @obj.current_index } row ||= @obj.current_index #@obj.current_index = row @obj.goto_line row end
ruby
{ "resource": "" }
q23868
Canis.DefaultListSelectionModel.remove_row_selection_interval
train
def remove_row_selection_interval ix0, ix1 @anchor_selection_index = ix0 @lead_selection_index = ix1 arr = @selected_indices.dup # to un highlight @selected_indices.delete_if {|x| x >= ix0 and x <= ix1 } arr.each {|i| @obj.fire_row_changed(i) } lse = ListSelectionEvent.new(ix0, ix1, @obj, :DELETE) @obj.fire_handler :LIST_SELECTION_EVENT, lse end
ruby
{ "resource": "" }
q23869
Canis.DefaultListSelectionModel.ask_select
train
def ask_select prompt="Enter selection pattern: " ret = get_string prompt return if ret.nil? || ret == "" indices = get_matching_indices ret #$log.debug "listselectionmodel: ask_select got matches#{@indices} " return if indices.nil? || indices.empty? indices.each { |e| # will not work if single select !! FIXME add_row_selection_interval e,e } end
ruby
{ "resource": "" }
q23870
Canis.DefaultListSelectionModel.ask_unselect
train
def ask_unselect prompt="Enter selection pattern: " ret = get_string prompt return if ret.nil? || ret == "" indices = get_matching_indices ret return if indices.nil? || indices.empty? indices.each { |e| # will not work if single select !! FIXME remove_row_selection_interval e,e } end
ruby
{ "resource": "" }
q23871
Canis.DefaultListSelectionModel.list_bindings
train
def list_bindings # freeing space for paging, now trying out 'v' as selector. 2014-04-14 - 18:57 @obj.bind_key($row_selector || 'v'.ord, 'toggle selection') { toggle_row_selection } # the mode may be set to single after the constructor, so this would have taken effect. if @obj.selection_mode == :multiple # freeing ctrl_space for back paging, now trying out 'V' as selector. 2014-04-14 - 18:57 @obj.bind_key($range_selector || 'V'.ord, 'range select') { range_select } @obj.bind_key(?+, 'ask_select') { ask_select } @obj.bind_key(?-, 'ask_unselect') { ask_unselect } @obj.bind_key(?a, 'select_all') {select_all} @obj.bind_key(?*, 'invert_selection') { invert_selection } @obj.bind_key(?u, 'clear_selection') { clear_selection } @obj.bind_key([?g,?n], 'goto next selection'){ goto_next_selection } # mapping double keys like vim @obj.bind_key([?g,?p], 'goto prev selection'){ goto_prev_selection } # mapping double keys like vim end @_header_adjustment ||= 0 # incase caller does not use #@obj._events << :LIST_SELECTION_EVENT unless @obj._events.include? :LIST_SELECTION_EVENT end
ruby
{ "resource": "" }
q23872
RubyCurses.ModStack.item_for
train
def item_for widget each do |e| if e.is_a? Item if e.widget == widget return e end end end return nil end
ruby
{ "resource": "" }
q23873
Canis.ApplicationHeader.print_center
train
def print_center(htext, r = 0, c = 0) win = @window len = win.getmaxx len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS # win.printstring r, ((len-htext.length)/2).floor, htext, @color_pair, @attr end
ruby
{ "resource": "" }
q23874
Canis.ApplicationHeader.print_top_right
train
def print_top_right(htext) hlen = htext.length len = @window.getmaxx # width was not changing when resize happens len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS #$log.debug " def print_top_right(#{htext}) #{len} #{Ncurses.COLS} " @form.window.printstring 0, len-hlen, htext, @color_pair, @attr end
ruby
{ "resource": "" }
q23875
Cream::Helper.Role.owner?
train
def owner? obj, relation=nil if relation return true if user_relation?(obj, relation) end [:user, :owner, :author].each do |relation| return true if user_relation?(obj, relation) end false end
ruby
{ "resource": "" }
q23876
DelSolr.Client.prepare_update_xml
train
def prepare_update_xml(options = {}) r = ["<add#{options.to_xml_attribute_string}>\n"] # copy and clear pending docs working_docs, @pending_documents = @pending_documents, nil working_docs.each { |doc| r << doc.xml } r << "\n</add>\n" r.join # not sure, but I think Array#join is faster then String#<< for large buffers end
ruby
{ "resource": "" }
q23877
Canis.Utils.suspend
train
def suspend _suspend(false) do system("tput cup 26 0") system("tput ed") system("echo Enter C-d to return to application") system (ENV['PS1']='\s-\v\$ ') if ENV['SHELL']== '/bin/bash' system(ENV['SHELL']); end end
ruby
{ "resource": "" }
q23878
Canis.Utils.shell_output
train
def shell_output $shell_history ||= [] cmd = get_string("Enter shell command:", :maxlen => 50) do |f| require 'canis/core/include/rhistory' f.extend(FieldHistory) f.history($shell_history) end if cmd && !cmd.empty? run_command cmd $shell_history.push(cmd) unless $shell_history.include? cmd end end
ruby
{ "resource": "" }
q23879
Canis.PrefixCommand.define_key
train
def define_key _keycode, *args, &blk _symbol = @symbol h = $rb_prefix_map[_symbol] raise ArgumentError, "No such keymap #{_symbol} defined. Use define_prefix_command." unless h _keycode = _keycode[0].getbyte(0) if _keycode[0].class == String arg = args.shift if arg.is_a? String desc = arg arg = args.shift elsif arg.is_a? Symbol # its a symbol desc = arg.to_s elsif arg.nil? desc = "unknown" else raise ArgumentError, "Don't know how to handle #{arg.class} in PrefixManager" end @descriptions[_keycode] = desc if !block_given? blk = arg end h[_keycode] = blk end
ruby
{ "resource": "" }
q23880
Canis.Tabular.column_width
train
def column_width colindex, width @cw[colindex] ||= width if @chash[colindex].nil? @chash[colindex] = ColumnInfo.new("", width) else @chash[colindex].w = width end @chash end
ruby
{ "resource": "" }
q23881
Canis.Tabular.render
train
def render buffer = [] _guess_col_widths rows = @list.size.to_s.length @rows = rows _prepare_format str = "" if @numbering str = " "*(rows+1)+@y end str << @fmstr % @columns buffer << str #puts "-" * str.length buffer << separator if @list if @numbering @fmstr = "%#{rows}d "+ @y + @fmstr end #@list.each { |e| puts e.join(@y) } count = 0 @list.each_with_index { |r,i| value = convert_value_to_text r, count buffer << value count += 1 } end buffer end
ruby
{ "resource": "" }
q23882
Abn.Client.search_by_acn
train
def search_by_acn(acn) self.errors << "No ACN provided." && return if acn.nil? self.errors << "No GUID provided. Please obtain one at - http://www.abr.business.gov.au/Webservices.aspx" && return if self.guid.nil? begin client = Savon.client(self.client_options) response = client.call(:abr_search_by_asic, message: { authenticationGuid: self.guid, searchString: acn.gsub(" ", ""), includeHistoricalDetails: "N" }) result = response.body[:abr_search_by_asic_response][:abr_payload_search_results][:response][:business_entity] return parse_search_result(result) rescue => ex self.errors << ex.to_s end end
ruby
{ "resource": "" }
q23883
Canis.ViEditable.vieditable_init_listbox
train
def vieditable_init_listbox $log.debug " inside vieditable_init_listbox " @editable = true bind_key( ?C, :edit_line) bind_key( ?o) { insert_line(@current_index+1) } bind_key( ?O) { insert_line(@current_index) } bind_key( [?d, ?d] , :delete_line ) bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler } bind_key( ?u ) { @undo_handler.undo if @undo_handler } bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler } bind_key( [?y, ?y] , :kill_ring_save ) bind_key( ?p, :yank ) # paste after this line #bind_key( ?P ) { yank(@current_index - 1) } # should be before this line # seems -1 was pasting 2 lines before bind_key( ?P ) { yank(@current_index - 0) } # should be before this line bind_key(?w, :forward_word) bind_key(?\M-y, :yank_pop) bind_key(?\C-y, :yank) bind_key(?\M-w, :kill_ring_save) @_events.push :CHANGE # thru vieditable #bind_key( ?D, :delete_eol) #bind_key( [?d, ?$], :delete_eol) #bind_key(?f, :forward_char) #bind_key( ?x, :delete_curr_char ) #bind_key( ?X, :delete_prev_char ) #bind_key( [?d, ?w], :delete_word ) #bind_key( [?d, ?t], :delete_till ) #bind_key( [?d, ?f], :delete_forward ) end
ruby
{ "resource": "" }
q23884
Canis.ViEditable.vieditable_init_tabular
train
def vieditable_init_tabular $log.debug " inside vieditable_init tabular" @editable = true #bind_key( ?C, :edit_line) #bind_key( ?o, :insert_line) #bind_key( ?O) { insert_line(@current_index-1) } #bind_key( ?o) { insert_line(@current_index+1) } #bind_key( ?O) { insert_line(@current_index) } bind_key( [?d, ?d] , :delete_line ) #bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler } #bind_key( ?u ) { @undo_handler.undo if @undo_handler } #bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler } bind_key( [?y, ?y] , :kill_ring_save ) bind_key( ?p, :yank ) # paste after this line bind_key( ?P ) { yank(@current_index - 1) } # should be before this line bind_key(?\M-y, :yank_pop) bind_key(?\M-w, :kill_ring_save) @_events.push :CHANGE # thru vieditable end
ruby
{ "resource": "" }
q23885
Canis.ViEditable.edit_line
train
def edit_line lineno=@current_index line = self[lineno] prompt = "Edit: " maxlen = 80 config={}; oldline = line.dup config[:default] = line ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config) $log.debug " rb_getstr returned #{ret} , #{str} " return if ret != 0 # we possibly cou;d have done []= but maybe in textpad or something that would replace a row pointer ?? self[lineno].replace(str) fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline) # 2008-12-24 18:34 fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str) fire_row_changed lineno end
ruby
{ "resource": "" }
q23886
Canis.ViEditable.edit_string
train
def edit_string string, prompt="Edit: ", maxlen=80 config={}; config[:default] = string ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config) #return str if ret == 0 #return "" end
ruby
{ "resource": "" }
q23887
Canis.ViEditable.input_string
train
def input_string prompt="Insert: ", maxlen=80 #ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config) ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config) #return str if ret == 0 #return "" end
ruby
{ "resource": "" }
q23888
Canis.TextPad.fire_row_changed
train
def fire_row_changed ix return if ix >= @list.length clear_row @pad, ix # allow documents to reparse that line fire_handler :ROW_CHANGED, ix _arr = _getarray render @pad, ix, _arr[ix] end
ruby
{ "resource": "" }
q23889
Canis.TextPad.forward_regex
train
def forward_regex regex if regex.is_a? Symbol regex = @text_patterns[regex] raise "Pattern specified #{regex} does not exist in text_patterns " unless regex end $multiplier = 1 if !$multiplier || $multiplier == 0 line = @current_index _arr = _getarray buff = _arr[line].to_s return unless buff pos = @curpos || 0 # list does not have curpos $multiplier.times { found = buff.index(regex, pos) if !found # if not found, we've lost a counter if line+1 < _arr.length line += 1 else return end pos = 0 else pos = found + 1 end $log.debug " forward_word: pos #{pos} line #{line} buff: #{buff}" } $multiplier = 0 @current_index = line @curpos = pos ensure_visible @repaint_required = true end
ruby
{ "resource": "" }
q23890
Canis.TextPad._handle_key
train
def _handle_key ch begin ret = process_key ch, self $multiplier = 0 bounds_check rescue => err $log.error " TEXTPAD ERROR _handle_key #{err} " $log.debug(err.backtrace.join("\n")) alert "#{err}" #textdialog ["Error in TextPad: #{err} ", *err.backtrace], :title => "Exception" ensure padrefresh Ncurses::Panel.update_panels end return 0 end
ruby
{ "resource": "" }
q23891
Canis.TextPad.on_enter_row
train
def on_enter_row arow return nil if @list.nil? || @list.size == 0 @repaint_footer_required = true ## can this be done once and stored, and one instance used since a lot of traversal will be done require 'canis/core/include/ractionevent' aev = TextActionEvent.new self, :ENTER_ROW, current_value().to_s, @current_index, @curpos fire_handler :ENTER_ROW, aev end
ruby
{ "resource": "" }
q23892
Canis.TextPad.next_regex
train
def next_regex regex if regex.is_a? Symbol regex = @text_patterns[regex] raise "Pattern specified #{regex} does not exist in text_patterns " unless regex end @last_regex = regex find_more end
ruby
{ "resource": "" }
q23893
Canis.AbstractTextPadRenderer.pre_render
train
def pre_render @attr = @source.attr cp = get_color($datacolor, @source.color(), @source.bgcolor()) @color_pair = @source.color_pair || cp @cp = FFI::NCurses.COLOR_PAIR(cp) end
ruby
{ "resource": "" }
q23894
Canis.AbstractTextPadRenderer.render_all
train
def render_all pad, arr pre_render @content_cols = @source.pad_cols @clearstring = " " * @content_cols @list = arr att = @attr || NORMAL FFI::NCurses.wattron(pad, @cp | att) arr.each_with_index { |line, ix| render pad, ix, line } FFI::NCurses.wattroff(pad, @cp | att) end
ruby
{ "resource": "" }
q23895
Canis.DefaultRenderer.render
train
def render pad, lineno, text if text.is_a? AbstractChunkLine text.print pad, lineno, 0, @content_cols, color_pair, attr return end ## messabox does have a method to paint the whole window in bg color its in rwidget.rb att = NORMAL FFI::NCurses.wattron(pad, @cp | att) FFI::NCurses.mvwaddstr(pad, lineno, 0, @clearstring) if @clearstring FFI::NCurses.mvwaddstr(pad, lineno, 0, @list[lineno]) #FFI::NCurses.mvwaddstr(pad, lineno, 0, text) FFI::NCurses.wattroff(pad, @cp | att) end
ruby
{ "resource": "" }
q23896
Canis.FieldHistory.history
train
def history arr return @history unless arr if arr.is_a? Array @history = arr else @history << arr unless @history.include? arr end end
ruby
{ "resource": "" }
q23897
Canis.MultiBuffers.add_content
train
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 if text.is_a? String config[:filename] = text config[:title] ||= text end @_buffers_conf << config @_buffer_ctr ||= 0 $log.debug "XXX: HELP adding text #{@_buffers.size} " end
ruby
{ "resource": "" }
q23898
Canis.MultiBuffers.add_files
train
def add_files filearray, config={} filearray.each do |e| add_content(e, config.dup); end end
ruby
{ "resource": "" }
q23899
Canis.MultiBuffers.buffer_next
train
def buffer_next buffer_update_info @_buffer_ctr += 1 x = @_buffer_ctr l = @_buffers[x] if l populate_buffer_from_filename x else @_buffer_ctr = 0 end set_content @_buffers[@_buffer_ctr], @_buffers_conf[@_buffer_ctr] buffer_update_position end
ruby
{ "resource": "" }