idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
13,600 | def print_top_right ( htext ) hlen = htext . length len = @window . getmaxx len = Ncurses . COLS - 0 if len == 0 || len > Ncurses . COLS @form . window . printstring 0 , len - hlen , htext , @color_pair , @attr end | internal method to print text_right |
13,601 | 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 | returns true if the current user owns the object tries default owner relations if none given as an argument |
13,602 | def prepare_update_xml ( options = { } ) r = [ "<add#{options.to_xml_attribute_string}>\n" ] working_docs , @pending_documents = @pending_documents , nil working_docs . each { | doc | r << doc . xml } r << "\n</add>\n" r . join end | returns the update xml buffer |
13,603 | 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 | suspends current program and puts user on unix prompt |
13,604 | 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 en... | prompts user for unix command and displays output in viewer |
13,605 | 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 =... | define a key within a prefix key map such as C - x Now that i am moving this from global how will describe bindings get hold of the bindings and descriptions |
13,606 | 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 | set width of a given column |
13,607 | 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 buffer << separator if @list if @numbering @fmstr = "%#{rows}d " + @y + @fmstr end count = 0 @list . each_with_index ... | Now returns an array with formatted data |
13,608 | 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... | Setup a new instance of the ABN search class . |
13,609 | 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_h... | Separate mappings for listboxes . Some methods don ; t make sense for listboxes and are crashing since not present for them . f was being overwritten too . Sorry for duplication need to clean this somehow . |
13,610 | def vieditable_init_tabular $log . debug " inside vieditable_init tabular" @editable = true bind_key ( [ ?d , ?d ] , :delete_line ) bind_key ( [ ?y , ?y ] , :kill_ring_save ) bind_key ( ?p , :yank ) bind_key ( ?P ) { yank ( @current_index - 1 ) } bind_key ( ?\M-y , :yank_pop ) bind_key ( ?\M-w , :kill_ring_save ) @_eve... | currently only adding delete_line and some yank pop functions These will all give wrong results in table due to _header_offset |
13,611 | 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} " retu... | edit current or given line |
13,612 | 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 ) end | common method to edit given string |
13,613 | def input_string prompt = "Insert: " , maxlen = 80 ret , str = rb_getstr ( @form . window , $error_message_row , $error_message_col , prompt , maxlen , config ) end | common method to input a blank string |
13,614 | def fire_row_changed ix return if ix >= @list . length clear_row @pad , ix fire_handler :ROW_CHANGED , ix _arr = _getarray render @pad , ix , _arr [ ix ] end | repaint only one row since content of that row has changed . No recreate of pad is done . |
13,615 | 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 |... | jump to the next occurence of given regex in the current line . It only jumps to next line after exhausting current . |
13,616 | 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}" ensure padrefresh Ncurses :: Panel . update_panels end return 0 end | this is a barebones handler to be used only if an overriding key handler wishes to fall back to default processing after it has handled some keys . The complete version is in Defaultkeyhandler . BUT the key will be executed again . |
13,617 | def on_enter_row arow return nil if @list . nil? || @list . size == 0 @repaint_footer_required = true require 'canis/core/include/ractionevent' aev = TextActionEvent . new self , :ENTER_ROW , current_value ( ) . to_s , @current_index , @curpos fire_handler :ENTER_ROW , aev end | execute binding when a row is entered used more in lists to display some text in a header or footer as one traverses |
13,618 | 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 | search for the next occurence of given regexp . Returns line and col if found else nil . |
13,619 | 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 | have the renderer get the latest colors from the widget . Override this if for some reason the renderer wishes to hardcode its own . But then the widgets colors would be changed ? |
13,620 | 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 | derived classes may choose to override this . However they should set size and color and attrib at the start since these can change after the object has been created depending on the application . |
13,621 | def render pad , lineno , text if text . is_a? AbstractChunkLine text . print pad , lineno , 0 , @content_cols , color_pair , attr return end att = NORMAL FFI :: NCurses . wattron ( pad , @cp | att ) FFI :: NCurses . mvwaddstr ( pad , lineno , 0 , @clearstring ) if @clearstring FFI :: NCurses . mvwaddstr ( pad , lineno... | default method for rendering a line If it is a chunkline then we take care of it . Only if it is a String do we pass to renderer . Should a renderer be allowed to handle chunks . Or be yielded chunks? |
13,622 | def history arr return @history unless arr if arr . is_a? Array @history = arr else @history << arr unless @history . include? arr end end | pass the array of history values Trying out a change where an item can also be sent in . I am lost i want the initialization to happen once . |
13,623 | 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 ) bind_key ( ?: , :buffer_menu ) end @_buffers ||= [ ] @_buffers_conf ||= [ ] @_buffers << text if text . is_a? String config [ :filename ] = text config [ :ti... | add content to buffers of a textview |
13,624 | def add_files filearray , config = { } filearray . each do | e | add_content ( e , config . dup ) ; end end | supply an array of files to the multibuffer . These will be read as the user presses next or last etc . |
13,625 | 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 | display next buffer |
13,626 | def buffer_prev buffer_update_info if @_buffer_ctr < 1 buffer_last return end @_buffer_ctr -= 1 if @_buffer_ctr > 0 x = @_buffer_ctr l = @_buffers [ x ] if l populate_buffer_from_filename x l = @_buffers [ x ] $log . debug "bp calling set_content with #{l.class} " set_content l , @_buffers_conf [ x ] buffer_update_posi... | display previous buffer if any |
13,627 | 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 :l , :list_buffers 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... | 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 |
13,628 | def list_buffers arr = [ ] @_buffers_conf . each_with_index do | e , i | t = e [ :title ] || "no title for #{i}" arr << t end ix = popuplist arr buffer_at ix end | pops up a list of buffers using titles allowing the user to select Based on selection that buffer is displayed . |
13,629 | def row_length case @buffer when String @buffer . length when Chunks :: ChunkLine return @buffer . length when Array if @buffer [ 0 ] . is_a? Array result = 0 @buffer . each { | e | result += e [ 1 ] . length } return result end return @buffer [ 1 ] . length end end | determine length of row since we have chunks now . Since chunk implements length so not required except for the old cases of demos that use an array . |
13,630 | def getstr prompt , maxlen = 80 tabc = Proc . new { | str | Dir . glob ( str + "*" ) } config = { } ; config [ :tab_completion ] = tabc config [ :default ] = "test" config [ :display_length ] = 11 $log . debug " inside getstr before call " ret , str = rbgetstr ( @form . window , @row + @height - 1 , @col + 1 , prompt ,... | this is just a test of prompting user for a string + as an alternative to the dialog . |
13,631 | def message message @suggested_h = @height || 10 message = message . gsub ( / \n \r \t / , ' ' ) rescue message message_col = 5 @suggested_w = @width || [ message . size + 8 + message_col , FFI :: NCurses . COLS - 2 ] . min r = 3 len = message . length @suggested_w = len + 8 + message_col if len < @suggested_w - 8 - me... | Pass a short message to be printed . This creates a label for a short message and a field for a long one . |
13,632 | def text message @suggested_w = @width || ( FFI :: NCurses . COLS * 0.80 ) . floor @suggested_h = @height || ( FFI :: NCurses . LINES * 0.80 ) . floor message_col = 3 r = 2 display_length = @suggested_w - 4 display_length -= message_col clr = @color || :white bgclr = @bgcolor || :black if message . is_a? Array l = long... | This is for larger messages or messages where the size is not known . A textview object is created and yielded . |
13,633 | def textarea config = { } , & block require 'canis/rtextarea' events = [ :CHANGE , :LEAVE , :ENTER ] block_event = events [ 0 ] useform = nil w = TextArea . new useform , config w . width = :expand unless w . width w . height ||= 8 _position ( w ) if block w . bind ( block_event , & block ) end return w end | editable text area |
13,634 | def stack config = { } , & block s = WsStack . new config _configure s @_ws_active << s yield_or_eval & block if block_given? @_ws_active . pop last = @_ws_active . last if last case last when WsStack when WsFlow last [ :col ] += last [ :item_width ] || 0 last [ :height ] = s [ :row ] if s [ :row ] > ( last [ :height ]... | make it as simple as possible don t try to be intelligent or clever put as much on the user |
13,635 | def flow config = { } , & block s = WsFlow . new config _configure s @_ws_active << s yield_or_eval & block if block_given? @_ws_active . pop last = @_ws_active . last if last case last when WsStack if s [ :height ] last [ :row ] += s [ :height ] else last [ :row ] += 1 end when WsFlow last [ :col ] += last [ :item_wid... | item_width - width to use per item but the item width may apply to stacks inside not to items |
13,636 | def box config = { } , & block require 'canis/core/widgets/box' last = @_ws_active . last if last r = last [ :row ] c = last [ :col ] config [ :row ] = r config [ :col ] = c last [ :row ] += config [ :margin_top ] || 1 last [ :col ] += config [ :margin_left ] || 1 _box = Box . new @form , config yield_or_eval & block i... | flow and stack could have a border option |
13,637 | def menu_tree mt , pm = self mt . each_pair { | ch , code | if code . is_a? Canis :: MenuTree item = pm . add ( ch , code . value , "" ) current = PromptMenu . new @caller , code . value item . action = current menu_tree code , current else item = pm . add ( ch , code . to_s , "" , code ) end } end | create the whole thing using a MenuTree which has minimal information . It uses a hotkey and a code only . We are supposed to resolve the display text and actual proc from the caller using this code . |
13,638 | def submenu key , label , & block item = CMenuItem . new ( key , label ) @options << item item . action = PromptMenu . new @caller , label , & block end | To allow a more rubyesque way of defining menus and submenus |
13,639 | def display_columns config = { } prompt = config [ :prompt ] || "Choose: " require 'canis/core/util/rcommandwindow' layout = { :height => 5 , :width => Ncurses . COLS - 0 , :top => Ncurses . LINES - 6 , :left => 0 } rc = CommandWindow . new nil , :layout => layout , :box => true , :title => config [ :title ] || "Menu" ... | Display prompt_menu in columns using commandwindow This is an improved way of showing the most like menu . The earlier format would only print in one row . |
13,640 | def create_color_pairs @color_pair = get_color $datacolor @pairs = Hash . new ( @color_pair ) @attrs = Hash . new ( Ncurses :: A_NORMAL ) color_pair = get_color $selectedcolor , @parent . selected_color , @parent . selected_bgcolor @pairs [ :normal ] = @color_pair @pairs [ :selected ] = color_pair @pairs [ :focussed ] ... | creates pairs of colors at start since often classes are overriding init_vars so not gettin created |
13,641 | def repaint graphic , r = @row , c = @col , row_index = - 1 , value = @text , focussed = false , selected = false select_colors focussed , selected value = value . to_s if ! @display_length . nil? if value . length > @display_length value = value [ 0 .. @display_length - 1 ] end if @justify == :center value = value . c... | paint a list box cell |
13,642 | def rb_getchar ( prompt , config = { } ) begin win = __create_footer_window r = 0 ; c = 1 ; default = config [ :default ] prompt = "#{prompt} [#{default}] " if default win . mvprintw ( r , c , "%s: " % prompt ) ; bg = Ncurses . COLORS >= 236 ? 236 : :blue color_pair = get_color ( $reversecolor , :white , bg ) win . pri... | get a character . unlike rb_gets allows user to enter control or alt or function character too . |
13,643 | def get_file prompt , config = { } maxlen = 70 tabc = Proc . new { | str | Dir . glob ( str + "*" ) } config [ :tab_completion ] ||= tabc config [ :maxlen ] ||= maxlen str = rb_gets ( prompt , config ) str ||= "" return str end | This is just experimental trying out tab_completion Prompt user for a file name allowing him to tab to complete filenames |
13,644 | def print_this ( win , text , color , x , y ) raise "win nil in print_this" unless win color = Ncurses . COLOR_PAIR ( color ) ; win . attron ( color ) ; win . mvprintw ( x , y , "%s" % text ) ; win . attroff ( color ) ; win . refresh end | prints given text to window in color at x and y coordinates |
13,645 | def rb_getstr ( nolongerused , r , c , prompt , maxlen , config = { } ) config [ :maxlen ] = maxlen str = rb_gets ( prompt , config ) if str return 0 , str else return - 1 , nil end end | routine to get a string at bottom of window . The first 3 params are no longer required since we create a window of our own . |
13,646 | def columns = ( array ) @_header_adjustment = 1 @columns = array @columns . each_with_index { | c , i | @cw [ i ] ||= c . to_s . length @calign [ i ] ||= :left } @column_pointer = Circular . new @columns . size ( ) - 1 end | set column names |
13,647 | def OLDprint_borders raise "#{self.class} needs width" unless @width raise "#{self.class} needs height" unless @height $log . debug " #{@name} print_borders, #{@graphic.name} " bordercolor = @border_color || $datacolor borderatt = @border_attrib || Ncurses :: A_NORMAL @graphic . print_border @row , @col , @height - 1 ... | print a border Note that print_border clears the area too so should be used sparingly . |
13,648 | def set_form_col col1 = @curpos @cols_panned ||= 0 @pad_offset ||= 0 @curpos = col1 maxlen = @maxlen || @width - @internal_width if @curpos > maxlen @pcol = @curpos - maxlen @curpos = maxlen - 1 @repaint_required = true else @pcol = 0 end win_col = 0 col2 = win_col + @col + @col_offset + @curpos + @cols_panned + @pad_o... | set cursor on correct column tview |
13,649 | def print_data_row r , c , len , value , color , attr @graphic . printstring r , c , "%-*s" % [ len , value ] , color , attr end | print data rows |
13,650 | def truncate content _maxlen = @maxlen || @width - @internal_width _maxlen = @width - @internal_width if _maxlen > @width - @internal_width _maxlen -= @left_margin if ! content . nil? cl = content . length if cl > _maxlen @longest_line = cl if cl > @longest_line content . replace ( content [ @pcol .. @pcol + maxlen - 1... | Truncates data to fit into display area . Copied from listscrollable since we need to take care of left_margin 2011 - 10 - 6 This may need to be reflected in listbox and others FIXME |
13,651 | def print_header_row r , c , len , value , color , attr @graphic . printstring r , c + @left_margin , "%-*s" % [ len - @left_margin , value ] , color , attr end | print header row allows user to override |
13,652 | def print_header r , c = rowcol value = convert_value_to_text :columns , 0 len = @width - @internal_width truncate value @header_color_pair ||= get_color $promptcolor , @header_fgcolor , @header_bgcolor @header_attrib ||= @attr print_header_row r , c , len , value , @header_color_pair , @header_attrib end | prints the column headers Uses + convert_value_to_text + and + print_header_row + |
13,653 | def _guess_col_widths return if @second_time @second_time = true if @list . size > 0 @list . each_with_index { | r , i | break if i > 10 next if r == :separator r . each_with_index { | c , j | x = c . to_s . length if @cw [ j ] . nil? @cw [ j ] = x else @cw [ j ] = x if x > @cw [ j ] end } } total = 0 @cw . each_pair {... | perhaps we can delete this since it does not respect |
13,654 | def next_column c = @column_pointer . next cp = @coffsets [ c ] @curpos = cp if cp next_row ( ) if c < @column_pointer . last_index set_form_col end | move cursor to next column FIXME need to account for hidden columns and numbering |
13,655 | def get_server ( name ) params = { 'command' => 'listVirtualMachines' , 'name' => name } json = send_request ( params ) machines = json [ 'virtualmachine' ] if ! machines || machines . empty? then return nil end machine = machines . select { | item | name == item [ 'name' ] } machine . first end | Finds the server with the specified name . |
13,656 | def get_server_public_ip ( server , cached_rules = nil , cached_nat = nil ) return nil unless server nic = get_server_default_nic ( server ) ssh_rule = get_ssh_port_forwarding_rule ( server , cached_rules ) return ssh_rule [ 'ipaddress' ] if ssh_rule winrm_rule = get_winrm_port_forwarding_rule ( server , cached_rules )... | Finds the public ip for a server |
13,657 | def get_server_fqdn ( server ) return nil unless server nic = get_server_default_nic ( server ) || { } networks = list_networks || { } id = nic [ 'networkid' ] network = networks . select { | net | net [ 'id' ] == id } . first return nil unless network "#{server['name']}.#{network['networkdomain']}" end | Returns the fully qualified domain name for a server . |
13,658 | def list_object ( params , json_result ) json = send_request ( params ) Chef :: Log . debug ( "JSON (list_object) result: #{json}" ) result = json [ "#{json_result}" ] || [ ] result = data_filter ( result , params [ 'filter' ] ) if params [ 'filter' ] result end | List all the objects based on the command that is specified . |
13,659 | def create_server ( host_name , service_name , template_name , disk_name = nil , zone_name = nil , network_names = [ ] , extra_params ) if host_name then if get_server ( host_name ) then puts "\nError: Server '#{host_name}' already exists." exit 1 end end service = get_service_offering ( service_name ) if ! service the... | Deploys a new server using the specified parameters . |
13,660 | def delete_server ( name , expunge ) server = get_server ( name ) if ! server || ! server [ 'id' ] then puts "\nError: Virtual machine '#{name}' does not exist" exit 1 end params = { 'command' => 'destroyVirtualMachine' , 'id' => server [ 'id' ] , 'expunge' => expunge } json = send_async_request ( params ) json [ 'virt... | Deletes the server with the specified name . |
13,661 | def stop_server ( name , forced = nil ) server = get_server ( name ) if ! server || ! server [ 'id' ] then puts "\nError: Virtual machine '#{name}' does not exist" exit 1 end params = { 'command' => 'stopVirtualMachine' , 'id' => server [ 'id' ] } params [ 'forced' ] = true if forced json = send_async_request ( params ... | Stops the server with the specified name . |
13,662 | def start_server ( name ) server = get_server ( name ) if ! server || ! server [ 'id' ] then puts "\nError: Virtual machine '#{name}' does not exist" exit 1 end params = { 'command' => 'startVirtualMachine' , 'id' => server [ 'id' ] } json = send_async_request ( params ) json [ 'virtualmachine' ] end | Start the server with the specified name . |
13,663 | def get_service_offering ( name ) params = { 'command' => 'listServiceOfferings' } json = send_request ( params ) services = json [ 'serviceoffering' ] return nil unless services services . each { | s | if name . is_uuid? then return s if s [ 'id' ] == name else return s if s [ 'name' ] == name end } nil end | Finds the service offering with the specified name . |
13,664 | def get_template ( name , zone_name = nil ) zone = zone_name ? get_zone ( zone_name ) : get_default_zone params = { 'command' => 'listTemplates' , 'templateFilter' => 'executable' , } params [ 'zoneid' ] = zone [ 'id' ] if zone json = send_request ( params ) templates = json [ 'template' ] return nil unless templates t... | Finds the template with the specified name . |
13,665 | def get_iso ( name , zone_name = nil ) zone = zone_name ? get_zone ( zone_name ) : get_default_zone params = { 'command' => 'listIsos' , 'isoFilter' => 'executable' , } params [ 'zoneid' ] = zone [ 'id' ] if zone json = send_request ( params ) iso = json [ 'iso' ] return nil unless iso iso . each { | i | if name . is_u... | Finds the iso with the specified name . |
13,666 | def get_disk_offering ( name ) params = { 'command' => 'listDiskOfferings' , } json = send_request ( params ) disks = json [ 'diskoffering' ] return nil if ! disks disks . each { | d | return d if d [ 'name' ] == name } nil end | Finds the disk offering with the specified name . |
13,667 | def get_volume ( name ) params = { 'command' => 'listVolumes' , 'name' => name } json = send_request ( params ) volumes = json [ 'volume' ] if ! volumes || volumes . empty? then return nil end volume = volumes . select { | item | name == item [ 'name' ] } volume . first end | Finds the volume with the specified name . |
13,668 | def delete_volume ( name ) volume = get_volume ( name ) if ! volume || ! volume [ 'id' ] then puts "\nError: Volume '#{name}' does not exist" exit 1 end params = { 'command' => 'deleteVolume' , 'id' => volume [ 'id' ] } json = send_request ( params ) json [ 'success' ] end | Deletes the volume with the specified name . |
13,669 | def get_project ( name ) params = { 'command' => 'listProjects' , 'listall' => true } json = send_request ( params ) projects = json [ 'project' ] return nil unless projects projects . each { | n | if name . is_uuid? then return n if n [ 'id' ] == name else return n if n [ 'name' ] == name end } nil end | Fetch project with the specified name |
13,670 | def data_filter ( data , filters ) filters . split ( ',' ) . each do | filter | field = filter . split ( ':' ) . first . strip . downcase search = filter . split ( ':' ) . last . strip if search =~ / \/ \/ / data = data . find_all { | k | k [ "#{field}" ] . to_s =~ search . to_regexp } if field && search else data = da... | Filter data on regex or just on string |
13,671 | def get_network ( name ) params = { 'command' => 'listNetworks' } json = send_request ( params ) networks = json [ 'network' ] return nil unless networks networks . each { | n | if name . is_uuid? then return n if n [ 'id' ] == name else return n if n [ 'name' ] == name end } nil end | Finds the network with the specified name . |
13,672 | def get_default_network ( zone ) params = { 'command' => 'listNetworks' , 'isDefault' => true , 'zoneid' => zone } json = send_request ( params ) networks = json [ 'network' ] return nil if ! networks || networks . empty? default = networks . first return default if networks . length == 1 networks . each { | n | if n [... | Finds the default network . |
13,673 | def get_zone ( name ) params = { 'command' => 'listZones' , 'available' => 'true' } json = send_request ( params ) networks = json [ 'zone' ] return nil unless networks networks . each { | z | if name . is_uuid? then return z if z [ 'id' ] == name else return z if z [ 'name' ] == name end } nil end | Finds the zone with the specified name . |
13,674 | def get_default_zone params = { 'command' => 'listZones' , 'available' => 'true' } json = send_request ( params ) zones = json [ 'zone' ] return nil unless zones zones . first end | Finds the default zone for your account . |
13,675 | def get_public_ip_address ( ip_address ) params = { 'command' => 'listPublicIpAddresses' , 'ipaddress' => ip_address } json = send_request ( params ) return nil unless json [ 'publicipaddress' ] json [ 'publicipaddress' ] . first end | Finds the public ip address for a given ip address string . |
13,676 | def associate_ip_address ( zone_id , networks ) params = { 'command' => 'associateIpAddress' , 'zoneId' => zone_id } if networks . nil? || networks . empty? default_network = get_default_network ( zone_id ) params [ 'networkId' ] = default_network [ 'id' ] else params [ 'networkId' ] = get_network ( networks . first ) ... | Acquires and associates a public IP to an account . |
13,677 | def list_port_forwarding_rules ( ip_address_id = nil , listall = false ) params = { 'command' => 'listPortForwardingRules' } params [ 'ipAddressId' ] = ip_address_id if ip_address_id params [ 'listall' ] = listall json = send_request ( params ) json [ 'portforwardingrule' ] end | Lists all port forwarding rules . |
13,678 | def get_ssh_port_forwarding_rule ( server , cached_rules = nil ) rules = cached_rules || list_port_forwarding_rules || [ ] rules . find_all { | r | r [ 'virtualmachineid' ] == server [ 'id' ] && r [ 'privateport' ] == '22' && r [ 'publicport' ] == '22' } . first end | Gets the SSH port forwarding rule for the specified server . |
13,679 | def get_winrm_port_forwarding_rule ( server , cached_rules = nil ) rules = cached_rules || list_port_forwarding_rules || [ ] rules . find_all { | r | r [ 'virtualmachineid' ] == server [ 'id' ] && ( r [ 'privateport' ] == '5985' && r [ 'publicport' ] == '5985' ) || ( r [ 'privateport' ] == '5986' && r [ 'publicport' ] ... | Gets the WINRM port forwarding rule for the specified server . |
13,680 | def create_port_forwarding_rule ( ip_address_id , private_port , protocol , public_port , virtual_machine_id ) params = { 'command' => 'createPortForwardingRule' , 'ipAddressId' => ip_address_id , 'privatePort' => private_port , 'protocol' => protocol , 'publicPort' => public_port , 'virtualMachineId' => virtual_machin... | Creates a port forwarding rule . |
13,681 | def key_tos ch x = $key_cache [ ch ] return x if x chr = case ch when 10 , 13 , KEY_ENTER "<CR>" when 9 "<TAB>" when 0 "<C-@>" when 27 "<ESC>" when 31 "<C-/>" when 1 .. 30 x = ch + 96 "<C-#{x.chr}>" when 32 "<SPACE>" when 41 "<M-CR>" when 33 .. 126 ch . chr when 127 , 263 "<BACKSPACE>" when 128 .. 154 x = ch - 128 xx =... | returns a string representation of a given int keycode |
13,682 | def get_color default = $datacolor , color = color ( ) , bgcolor = bgcolor ( ) return default if color . nil? || bgcolor . nil? acolor = ColorMap . get_color ( color , bgcolor ) return acolor end | }}} if passed a string in second or third param will create a color and return else it will return default color Use this in order to create a color pair with the colors provided however if user has not provided use supplied default . |
13,683 | def print_key_bindings * args f = get_current_field labels = [ ] labels << ( f . key_label || { } ) labels << @key_label arr = [ ] if get_current_field . help_text arr << get_current_field . help_text end labels . each_with_index { | h , i | case i when 0 arr << " === Current widget bindings ===" when 1 arr << " ===... | Display key bindings for current widget and form in dialog |
13,684 | def view what , config = { } , & block require 'canis/core/util/viewer' Canis :: Viewer . view what , config , & block end | view a file or array of strings |
13,685 | def create_logger path _path = File . open ( path , File :: WRONLY | File :: TRUNC | File :: CREAT ) logg = Logger . new ( _path ) raise "Could not create logger: #{path}" unless logg logg . level = ENV [ "CANIS_LOG_LEVEL" ] . to_i colors = Ncurses . COLORS logg . info "START #{colors} colors -- #{$0} win: #{@window} ... | create a logger giving a path . |
13,686 | def fire_property_change text , oldvalue , newvalue return if @_object_created . nil? $log . debug " FPC #{self}: #{text} " if @pce . nil? @pce = PropertyChangeEvent . new ( self , text , oldvalue , newvalue ) else @pce . set ( self , text , oldvalue , newvalue ) end fire_handler :PROPERTY_CHANGE , @pce @repaint_requir... | goes with dsl_property Can throw a FieldValidationException or PropertyVetoException |
13,687 | def property_set sym , val oldvalue = instance_variable_get "@#{sym}" tmp = val . size == 1 ? val [ 0 ] : val newvalue = tmp if oldvalue . nil? || @_object_created . nil? instance_variable_set "@#{sym}" , tmp end return ( self ) if oldvalue . nil? || @_object_created . nil? if oldvalue != newvalue begin @property_chang... | this is supposed to be a duplicate of what dsl_property generates for cases when we need to customise the get portion but not copy the set part . just call this . |
13,688 | def repaint r , c = rowcol _bgcolor = bgcolor ( ) _color = color ( ) $log . debug ( "widget repaint : r:#{r} c:#{c} col:#{_color}" ) value = getvalue_for_paint len = @width || value . length acolor = @color_pair || get_color ( $datacolor , _color , _bgcolor ) @graphic . printstring r , c , "%-*s" % [ len , value ] , ac... | default repaint method . Called by form for all widgets . widget does not have display_length . |
13,689 | def set_form form raise "Form is nil in set_form" if form . nil? @form = form @id = form . add_widget ( self ) if ! form . nil? and form . respond_to? :add_widget if @graphic . nil? @graphic = form . window unless form . nil? end fire_handler ( :FORM_ATTACHED , self ) if event? :FORM_ATTACHED end | in those cases where we create widget without a form and later give it to some other program which sets the form . Dirty we should perhaps create widgets without forms and add explicitly . |
13,690 | def color_pair ( * val ) if val . empty? return @color_pair || get_color ( $datacolor , color ( ) , bgcolor ( ) ) end oldvalue = @color_pair case val . size when 1 raise ArgumentError , "Expecting fixnum for color_pair." unless val [ 0 ] . is_a? Integer @color_pair = val [ 0 ] @color , @bgcolor = ColorMap . get_colors_... | returns array of events defined for this object |
13,691 | def command * args , & block if event? :PRESS bind :PRESS , * args , & block else bind :CHANGED , * args , & block end end | a general method for all widgets to override with their favorite or most meaninful event Ideally this is where the block in the constructor should land up . |
13,692 | def set_menu_bar mb @menu_bar = mb add_widget mb mb . toggle_key ||= Ncurses . KEY_F2 if ! mb . toggle_key . nil? ch = mb . toggle_key bind_key ( ch , 'Menu Bar' ) do | _form | if ! @menu_bar . nil? @menu_bar . toggle @menu_bar . handle_keys end end end end | set this menubar as the form s menu bar . also bind the toggle_key for popping up . Should this not be at application level ? |
13,693 | def repaint $log . debug " form repaint:#{self}, #{@name} , r #{@row} c #{@col} " if $log . debug? if @resize_required && @layout_manager @layout_manager . form = self unless @layout_manager . form @layout_manager . do_layout @resize_required = false end @widgets . each do | f | next if f . visible == false f . repaint... | form repaint calls repaint on each widget which will repaint it only if it has been modified since last call . called after each keypress . |
13,694 | def setpos r = @row , c = @col return if r . nil? or c . nil? return if r < 0 or c < 0 @window . wmove r , c end | move cursor to where the fields row and col are private |
13,695 | def on_leave f return if f . nil? || ! f . focusable f . state = :NORMAL f . on_leave if f . respond_to? :on_leave if f . respond_to? :editable and f . modified? $log . debug " Form about to fire CHANGED for #{f} " f . fire_handler ( :CHANGED , f ) end end | do not override form s trigger fired when any widget loses focus This wont get called in editor components in tables since they are formless |
13,696 | def on_enter f return if f . nil? || ! f . focusable f . state = :HIGHLIGHTED if f . highlight_bgcolor || f . highlight_color f . repaint_required true end f . modified false f . on_enter if f . respond_to? :on_enter end | form calls on_enter of each object . However if a multicomponent calls on_enter of a widget this code will not be triggered . The highlighted part |
13,697 | def map_keys return if @keys_mapped bind_key ( KEY_F1 , 'help' ) { hm = help_manager ( ) ; hm . display_help } bind_keys ( [ ?\M-? , ?\? ] , 'show field help' ) { print_key_bindings } bind_key ( FFI :: NCurses :: KEY_F9 , "Print keys" , :print_key_bindings ) bind_key ( ?\M-: , 'show menu' ) { fld = get_current_field am... | These mappings will only trigger if the current field does not use them . |
13,698 | def _set_buffer value @repaint_required = true @datatype = value . class @delete_buffer = @buffer . dup @buffer = value . to_s . dup @buffer = @buffer [ 0 , @maxlen ] if @maxlen && @buffer . length > @maxlen @curpos = 0 fire_handler :CHANGE , InputDataEvent . new ( @curpos , @curpos , self , :DELETE , 0 , @delete_buffe... | set value of Field fires CHANGE handler Please don t use this directly use + text + This name is from ncurses field added underscore to emphasize not to use |
13,699 | def set_label label case label when String @label_unattached = true unless @form label = Label . new @form , { :text => label } end @label = label if @row position_label else @label_unplaced = true end label end | create a label linked to this field Typically one passes a Label but now we can pass just a String a label is created . This differs from + label + in positioning . The + Field + is printed on + row + and + col + and the label before it . Thus all fields are aligned on column however you must leave adequate columns for... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.