repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
mare-imbrium/canis | lib/canis/core/widgets/applicationheader.rb | Canis.ApplicationHeader.print_top_right | 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 | 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 | [
"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 | [
"internal",
"method",
"to",
"print",
"text_right"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/applicationheader.rb#L114-L120 | train |
kristianmandrup/cream | lib/cream/helper/role.rb | Cream::Helper.Role.owner? | 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 | 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 | [
"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 | [
"returns",
"true",
"if",
"the",
"current",
"user",
"owns",
"the",
"object",
"tries",
"default",
"owner",
"relations",
"if",
"none",
"given",
"as",
"an",
"argument"
]
| 6edbdc8796b4a942e11d1054649b2e058c90c9d8 | https://github.com/kristianmandrup/cream/blob/6edbdc8796b4a942e11d1054649b2e058c90c9d8/lib/cream/helper/role.rb#L71-L79 | train |
avvo/delsolr | lib/delsolr/client.rb | DelSolr.Client.prepare_update_xml | 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 | 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 | [
"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 | [
"returns",
"the",
"update",
"xml",
"buffer"
]
| 30debacab9e7bf3c6f1907563286c29fb61441b2 | https://github.com/avvo/delsolr/blob/30debacab9e7bf3c6f1907563286c29fb61441b2/lib/delsolr/client.rb#L291-L298 | train |
mare-imbrium/canis | lib/canis/core/include/appmethods.rb | Canis.Utils.suspend | 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 | 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 | [
"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 | [
"suspends",
"current",
"program",
"and",
"puts",
"user",
"on",
"unix",
"prompt"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/appmethods.rb#L36-L44 | train |
mare-imbrium/canis | lib/canis/core/include/appmethods.rb | Canis.Utils.shell_output | 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 | 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 | [
"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"
]
| prompts user for unix command and displays output in viewer | [
"prompts",
"user",
"for",
"unix",
"command",
"and",
"displays",
"output",
"in",
"viewer"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/appmethods.rb#L49-L60 | train |
mare-imbrium/canis | lib/canis/core/include/appmethods.rb | Canis.PrefixCommand.define_key | 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 | 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 | [
"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",
"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"
]
| 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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/appmethods.rb#L168-L191 | train |
mare-imbrium/canis | lib/canis/core/widgets/tabular.rb | Canis.Tabular.column_width | 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 | 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 | [
"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
@param [Number] column offset, starting 0
@param [Number] width | [
"set",
"width",
"of",
"a",
"given",
"column"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tabular.rb#L105-L113 | train |
mare-imbrium/canis | lib/canis/core/widgets/tabular.rb | Canis.Tabular.render | 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 | 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 | [
"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",
"{",
"|",
"r",
",",
"i",
"|",
"value",
"=",
"convert_value_to_text",
"r",
",",
"count",
"buffer",
"<<",
"value",
"count",
"+=",
"1",
"}",
"end",
"buffer",
"end"
]
| Now returns an array with formatted data
@return [Array<String>] array of formatted data | [
"Now",
"returns",
"an",
"array",
"with",
"formatted",
"data"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tabular.rb#L132-L160 | train |
Oneflare/abn_search | lib/abn/client.rb | Abn.Client.search_by_acn | 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 | 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 | [
"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"
]
| Setup a new instance of the ABN search class.
@param [String] guid - the ABR GUID for Web Services access
@param [Hash] options - options detailed below
@option options [String] :proxy Proxy URL string if required (Example: http://user:[email protected]:443)
@return [ABNSearch]
Performs an ABR search for the ABN setup upon initialization
@param [String] acn - the acn you wish to search for
@return [Hash] search result in a hash | [
"Setup",
"a",
"new",
"instance",
"of",
"the",
"ABN",
"search",
"class",
"."
]
| 596d388b45e7c95d5b8cce92b9705fc27b63e47d | https://github.com/Oneflare/abn_search/blob/596d388b45e7c95d5b8cce92b9705fc27b63e47d/lib/abn/client.rb#L31-L43 | train |
mare-imbrium/canis | lib/canis/core/include/vieditable.rb | Canis.ViEditable.vieditable_init_listbox | 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 | 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 | [
"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",
")",
"bind_key",
"(",
"?P",
")",
"{",
"yank",
"(",
"@current_index",
"-",
"0",
")",
"}",
"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",
"end"
]
| 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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/vieditable.rb#L50-L79 | train |
mare-imbrium/canis | lib/canis/core/include/vieditable.rb | Canis.ViEditable.vieditable_init_tabular | 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 | 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 | [
"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",
")",
"@_events",
".",
"push",
":CHANGE",
"end"
]
| currently only adding delete_line and some yank pop functions
These will all give wrong results in table due to _header_offset | [
"currently",
"only",
"adding",
"delete_line",
"and",
"some",
"yank",
"pop",
"functions",
"These",
"will",
"all",
"give",
"wrong",
"results",
"in",
"table",
"due",
"to",
"_header_offset"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/vieditable.rb#L83-L101 | train |
mare-imbrium/canis | lib/canis/core/include/vieditable.rb | Canis.ViEditable.edit_line | 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 | 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 | [
"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",
"self",
"[",
"lineno",
"]",
".",
"replace",
"(",
"str",
")",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"0",
",",
"oldline",
".",
"length",
",",
"self",
",",
":DELETE_LINE",
",",
"lineno",
",",
"oldline",
")",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"0",
",",
"str",
".",
"length",
",",
"self",
",",
":INSERT_LINE",
",",
"lineno",
",",
"str",
")",
"fire_row_changed",
"lineno",
"end"
]
| edit current or given line | [
"edit",
"current",
"or",
"given",
"line"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/vieditable.rb#L105-L120 | train |
mare-imbrium/canis | lib/canis/core/include/vieditable.rb | Canis.ViEditable.edit_string | 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 | 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 | [
"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
@param [String] string to edit/modify
@param [String] prompt to display before string
@param [int] max length of input
@return [0, -1] return value 0 if okay, -1 if error | [
"common",
"method",
"to",
"edit",
"given",
"string"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/vieditable.rb#L150-L156 | train |
mare-imbrium/canis | lib/canis/core/include/vieditable.rb | Canis.ViEditable.input_string | 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 | 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 | [
"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
@param [String] prompt to display before string
@param [int] max length of input
@return [0, -1] return value 0 if okay, -1 if error | [
"common",
"method",
"to",
"input",
"a",
"blank",
"string"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/vieditable.rb#L162-L167 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.TextPad.fire_row_changed | 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 | 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 | [
"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. | [
"repaint",
"only",
"one",
"row",
"since",
"content",
"of",
"that",
"row",
"has",
"changed",
".",
"No",
"recreate",
"of",
"pad",
"is",
"done",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L413-L421 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.TextPad.forward_regex | 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 | 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 | [
"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",
"$multiplier",
".",
"times",
"{",
"found",
"=",
"buff",
".",
"index",
"(",
"regex",
",",
"pos",
")",
"if",
"!",
"found",
"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"
]
| jump to the next occurence of given regex in the current line.
It only jumps to next line after exhausting current.
@param [Regexp] passed to String.index | [
"jump",
"to",
"the",
"next",
"occurence",
"of",
"given",
"regex",
"in",
"the",
"current",
"line",
".",
"It",
"only",
"jumps",
"to",
"next",
"line",
"after",
"exhausting",
"current",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L937-L968 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.TextPad._handle_key | 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 | 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 | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1101-L1116 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.TextPad.on_enter_row | 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 | 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 | [
"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 | [
"execute",
"binding",
"when",
"a",
"row",
"is",
"entered",
"used",
"more",
"in",
"lists",
"to",
"display",
"some",
"text",
"in",
"a",
"header",
"or",
"footer",
"as",
"one",
"traverses"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1139-L1148 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.TextPad.next_regex | 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 | 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 | [
"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.
@param [String, Regexp] pattern to search for (uses :index)
@return [nil] return value of no consequence | [
"search",
"for",
"the",
"next",
"occurence",
"of",
"given",
"regexp",
".",
"Returns",
"line",
"and",
"col",
"if",
"found",
"else",
"nil",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1470-L1477 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.AbstractTextPadRenderer.pre_render | 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 | 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 | [
"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 ? | [
"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",
"?"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1547-L1552 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.AbstractTextPadRenderer.render_all | 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 | 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 | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1558-L1571 | train |
mare-imbrium/canis | lib/canis/core/widgets/textpad.rb | Canis.DefaultRenderer.render | 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 | 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 | [
"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",
",",
"0",
",",
"@list",
"[",
"lineno",
"]",
")",
"FFI",
"::",
"NCurses",
".",
"wattroff",
"(",
"pad",
",",
"@cp",
"|",
"att",
")",
"end"
]
| 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? | [
"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?"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/textpad.rb#L1590-L1603 | train |
mare-imbrium/canis | lib/canis/core/include/rhistory.rb | Canis.FieldHistory.history | def history arr
return @history unless arr
if arr.is_a? Array
@history = arr
else
@history << arr unless @history.include? arr
end
end | ruby | def history arr
return @history unless arr
if arr.is_a? Array
@history = arr
else
@history << arr unless @history.include? arr
end
end | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/rhistory.rb#L39-L46 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.add_content | 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 | 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 | [
"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",
"[",
":title",
"]",
"||=",
"text",
"end",
"@_buffers_conf",
"<<",
"config",
"@_buffer_ctr",
"||=",
"0",
"$log",
".",
"debug",
"\"XXX: HELP adding text #{@_buffers.size} \"",
"end"
]
| add content to buffers of a textview
@param [Array] text, or String (filename)
@param [Hash] options, typically :content_type => :ansi or :tmux, and :title | [
"add",
"content",
"to",
"buffers",
"of",
"a",
"textview"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L26-L43 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.add_files | def add_files filearray, config={}
filearray.each do |e| add_content(e, config.dup); end
end | ruby | def add_files filearray, config={}
filearray.each do |e| add_content(e, config.dup); end
end | [
"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. | [
"supply",
"an",
"array",
"of",
"files",
"to",
"the",
"multibuffer",
".",
"These",
"will",
"be",
"read",
"as",
"the",
"user",
"presses",
"next",
"or",
"last",
"etc",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L47-L49 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.buffer_next | 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 | 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 | [
"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 | [
"display",
"next",
"buffer"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L52-L64 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.buffer_prev | 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_position
end
end | ruby | 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_position
end
end | [
"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_position",
"end",
"end"
]
| display previous buffer if any | [
"display",
"previous",
"buffer",
"if",
"any"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L82-L98 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.buffer_menu | 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 :title => "Buffer Menu"
end | ruby | 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 :title => "Buffer Menu"
end | [
"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",
":title",
"=>",
"\"Buffer Menu\"",
"end"
]
| 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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L132-L147 | train |
mare-imbrium/canis | lib/canis/core/include/multibuffer.rb | Canis.MultiBuffers.list_buffers | def list_buffers
arr = []
@_buffers_conf.each_with_index do |e, i|
t = e[:title] || "no title for #{i}"
#$log.debug " TITLE is #{e.title} , t is #{t} "
arr << t
end
ix = popuplist arr
buffer_at ix
end | ruby | def list_buffers
arr = []
@_buffers_conf.each_with_index do |e, i|
t = e[:title] || "no title for #{i}"
#$log.debug " TITLE is #{e.title} , t is #{t} "
arr << t
end
ix = popuplist arr
buffer_at ix
end | [
"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. | [
"pops",
"up",
"a",
"list",
"of",
"buffers",
"using",
"titles",
"allowing",
"the",
"user",
"to",
"select",
"Based",
"on",
"selection",
"that",
"buffer",
"is",
"displayed",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/multibuffer.rb#L150-L159 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtextview.rb | Canis.TextView.row_length | def row_length
case @buffer
when String
@buffer.length
when Chunks::ChunkLine
return @buffer.length
when Array
# this is for those old cases like rfe.rb which sent in an array
# (before we moved to chunks)
# line is an array of arrays
if @buffer[0].is_a? Array
result = 0
@buffer.each {|e| result += e[1].length }
return result
end
# line is one single chunk
return @buffer[1].length
end
end | ruby | def row_length
case @buffer
when String
@buffer.length
when Chunks::ChunkLine
return @buffer.length
when Array
# this is for those old cases like rfe.rb which sent in an array
# (before we moved to chunks)
# line is an array of arrays
if @buffer[0].is_a? Array
result = 0
@buffer.each {|e| result += e[1].length }
return result
end
# line is one single chunk
return @buffer[1].length
end
end | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtextview.rb#L250-L268 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtextview.rb | Canis.TextView.getstr | def getstr prompt, maxlen=80 #:nodoc:
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, maxlen, config)
$log.debug " rbgetstr returned #{ret} ,#{str}."
return "" if ret != 0
return str
end | ruby | def getstr prompt, maxlen=80 #:nodoc:
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, maxlen, config)
$log.debug " rbgetstr returned #{ret} ,#{str}."
return "" if ret != 0
return str
end | [
"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",
",",
"maxlen",
",",
"config",
")",
"$log",
".",
"debug",
"\" rbgetstr returned #{ret} ,#{str}.\"",
"return",
"\"\"",
"if",
"ret",
"!=",
"0",
"return",
"str",
"end"
]
| this is just a test of prompting user for a string
+ as an alternative to the dialog. | [
"this",
"is",
"just",
"a",
"test",
"of",
"prompting",
"user",
"for",
"a",
"string",
"+",
"as",
"an",
"alternative",
"to",
"the",
"dialog",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtextview.rb#L616-L626 | train |
mare-imbrium/canis | lib/canis/core/widgets/rmessagebox.rb | Canis.MessageBox.message | def message message # yield label or field being used for display for further customization
@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 - message_col
display_length = @suggested_w-8
display_length -= message_col
message_height = 2
clr = @color || :white
bgclr = @bgcolor || :black
# trying this out. sometimes very long labels get truncated, so i give a field in wchich user
# can use arrow key or C-a and C-e
if message.size > display_length
message_label = Canis::Field.new @form, {:text => message, :name=>"message_label",
:row => r, :col => message_col, :width => display_length,
:bgcolor => bgclr , :color => clr, :editable => false}
else
message_label = Canis::Label.new @form, {:text => message, :name=>"message_label",
:row => r, :col => message_col, :width => display_length,
:height => message_height, :bgcolor => bgclr , :color => clr}
end
@maxrow = 3
yield message_label if block_given?
end | ruby | def message message # yield label or field being used for display for further customization
@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 - message_col
display_length = @suggested_w-8
display_length -= message_col
message_height = 2
clr = @color || :white
bgclr = @bgcolor || :black
# trying this out. sometimes very long labels get truncated, so i give a field in wchich user
# can use arrow key or C-a and C-e
if message.size > display_length
message_label = Canis::Field.new @form, {:text => message, :name=>"message_label",
:row => r, :col => message_col, :width => display_length,
:bgcolor => bgclr , :color => clr, :editable => false}
else
message_label = Canis::Label.new @form, {:text => message, :name=>"message_label",
:row => r, :col => message_col, :width => display_length,
:height => message_height, :bgcolor => bgclr , :color => clr}
end
@maxrow = 3
yield message_label if block_given?
end | [
"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",
"-",
"message_col",
"display_length",
"=",
"@suggested_w",
"-",
"8",
"display_length",
"-=",
"message_col",
"message_height",
"=",
"2",
"clr",
"=",
"@color",
"||",
":white",
"bgclr",
"=",
"@bgcolor",
"||",
":black",
"if",
"message",
".",
"size",
">",
"display_length",
"message_label",
"=",
"Canis",
"::",
"Field",
".",
"new",
"@form",
",",
"{",
":text",
"=>",
"message",
",",
":name",
"=>",
"\"message_label\"",
",",
":row",
"=>",
"r",
",",
":col",
"=>",
"message_col",
",",
":width",
"=>",
"display_length",
",",
":bgcolor",
"=>",
"bgclr",
",",
":color",
"=>",
"clr",
",",
":editable",
"=>",
"false",
"}",
"else",
"message_label",
"=",
"Canis",
"::",
"Label",
".",
"new",
"@form",
",",
"{",
":text",
"=>",
"message",
",",
":name",
"=>",
"\"message_label\"",
",",
":row",
"=>",
"r",
",",
":col",
"=>",
"message_col",
",",
":width",
"=>",
"display_length",
",",
":height",
"=>",
"message_height",
",",
":bgcolor",
"=>",
"bgclr",
",",
":color",
"=>",
"clr",
"}",
"end",
"@maxrow",
"=",
"3",
"yield",
"message_label",
"if",
"block_given?",
"end"
]
| Pass a short message to be printed.
This creates a label for a short message, and a field for a long one.
@yield field created
@param [String] text to display | [
"Pass",
"a",
"short",
"message",
"to",
"be",
"printed",
".",
"This",
"creates",
"a",
"label",
"for",
"a",
"short",
"message",
"and",
"a",
"field",
"for",
"a",
"long",
"one",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmessagebox.rb#L151-L179 | train |
mare-imbrium/canis | lib/canis/core/widgets/rmessagebox.rb | Canis.MessageBox.text | 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 = longest_in_list message
if l > @suggested_w
if l < FFI::NCurses.COLS
#@suggested_w = l
@suggested_w = FFI::NCurses.COLS-2
else
@suggested_w = FFI::NCurses.COLS-2
end
display_length = @suggested_w-6
end
# reduce width and height if you can based on array contents
else
message = wrap_text(message, display_length).split("\n")
end
# now that we have moved to textpad that +8 was causing black lines to remain after the text
message_height = message.size #+ 8
# reduce if possible if its not required.
#
r1 = (FFI::NCurses.LINES-@suggested_h)/2
r1 = r1.floor
w = @suggested_w
c1 = (FFI::NCurses.COLS-w)/2
c1 = c1.floor
@suggested_row = r1
@suggested_col = c1
brow = @button_row || @suggested_h-4
available_ht = brow - r + 1
message_height = [message_height, available_ht].min
# replaced 2014-04-14 - 23:51
message_label = Canis::TextPad.new @form, {:name=>"message_label", :text => message,
:row => r, :col => message_col, :width => display_length, :suppress_borders => true,
:height => message_height, :bgcolor => bgclr , :color => clr}
#message_label.set_content message
yield message_label if block_given?
end | ruby | 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 = longest_in_list message
if l > @suggested_w
if l < FFI::NCurses.COLS
#@suggested_w = l
@suggested_w = FFI::NCurses.COLS-2
else
@suggested_w = FFI::NCurses.COLS-2
end
display_length = @suggested_w-6
end
# reduce width and height if you can based on array contents
else
message = wrap_text(message, display_length).split("\n")
end
# now that we have moved to textpad that +8 was causing black lines to remain after the text
message_height = message.size #+ 8
# reduce if possible if its not required.
#
r1 = (FFI::NCurses.LINES-@suggested_h)/2
r1 = r1.floor
w = @suggested_w
c1 = (FFI::NCurses.COLS-w)/2
c1 = c1.floor
@suggested_row = r1
@suggested_col = c1
brow = @button_row || @suggested_h-4
available_ht = brow - r + 1
message_height = [message_height, available_ht].min
# replaced 2014-04-14 - 23:51
message_label = Canis::TextPad.new @form, {:name=>"message_label", :text => message,
:row => r, :col => message_col, :width => display_length, :suppress_borders => true,
:height => message_height, :bgcolor => bgclr , :color => clr}
#message_label.set_content message
yield message_label if block_given?
end | [
"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",
"=",
"longest_in_list",
"message",
"if",
"l",
">",
"@suggested_w",
"if",
"l",
"<",
"FFI",
"::",
"NCurses",
".",
"COLS",
"@suggested_w",
"=",
"FFI",
"::",
"NCurses",
".",
"COLS",
"-",
"2",
"else",
"@suggested_w",
"=",
"FFI",
"::",
"NCurses",
".",
"COLS",
"-",
"2",
"end",
"display_length",
"=",
"@suggested_w",
"-",
"6",
"end",
"else",
"message",
"=",
"wrap_text",
"(",
"message",
",",
"display_length",
")",
".",
"split",
"(",
"\"\\n\"",
")",
"end",
"message_height",
"=",
"message",
".",
"size",
"r1",
"=",
"(",
"FFI",
"::",
"NCurses",
".",
"LINES",
"-",
"@suggested_h",
")",
"/",
"2",
"r1",
"=",
"r1",
".",
"floor",
"w",
"=",
"@suggested_w",
"c1",
"=",
"(",
"FFI",
"::",
"NCurses",
".",
"COLS",
"-",
"w",
")",
"/",
"2",
"c1",
"=",
"c1",
".",
"floor",
"@suggested_row",
"=",
"r1",
"@suggested_col",
"=",
"c1",
"brow",
"=",
"@button_row",
"||",
"@suggested_h",
"-",
"4",
"available_ht",
"=",
"brow",
"-",
"r",
"+",
"1",
"message_height",
"=",
"[",
"message_height",
",",
"available_ht",
"]",
".",
"min",
"message_label",
"=",
"Canis",
"::",
"TextPad",
".",
"new",
"@form",
",",
"{",
":name",
"=>",
"\"message_label\"",
",",
":text",
"=>",
"message",
",",
":row",
"=>",
"r",
",",
":col",
"=>",
"message_col",
",",
":width",
"=>",
"display_length",
",",
":suppress_borders",
"=>",
"true",
",",
":height",
"=>",
"message_height",
",",
":bgcolor",
"=>",
"bgclr",
",",
":color",
"=>",
"clr",
"}",
"yield",
"message_label",
"if",
"block_given?",
"end"
]
| This is for larger messages, or messages where the size is not known.
A textview object is created and yielded. | [
"This",
"is",
"for",
"larger",
"messages",
"or",
"messages",
"where",
"the",
"size",
"is",
"not",
"known",
".",
"A",
"textview",
"object",
"is",
"created",
"and",
"yielded",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmessagebox.rb#L185-L232 | train |
mare-imbrium/canis | lib/canis/core/util/oldwidgetshortcuts.rb | Canis.WidgetShortcuts.textarea | def textarea config={}, &block
require 'canis/rtextarea'
# TODO confirm events many more
events = [ :CHANGE, :LEAVE, :ENTER ]
block_event = events[0]
#_process_args args, config, block_event, events
#config[:width] = config[:display_length] unless config.has_key? :width
# if no width given, expand to flows width
#config[:width] ||= @stack.last.width if @stack.last
useform = nil
#useform = @form if @current_object.empty?
w = TextArea.new useform, config
w.width = :expand unless w.width
w.height ||= 8 # TODO
_position(w)
# need to expand to stack's width or flows itemwidth if given
if block
w.bind(block_event, &block)
end
return w
end | ruby | def textarea config={}, &block
require 'canis/rtextarea'
# TODO confirm events many more
events = [ :CHANGE, :LEAVE, :ENTER ]
block_event = events[0]
#_process_args args, config, block_event, events
#config[:width] = config[:display_length] unless config.has_key? :width
# if no width given, expand to flows width
#config[:width] ||= @stack.last.width if @stack.last
useform = nil
#useform = @form if @current_object.empty?
w = TextArea.new useform, config
w.width = :expand unless w.width
w.height ||= 8 # TODO
_position(w)
# need to expand to stack's width or flows itemwidth if given
if block
w.bind(block_event, &block)
end
return w
end | [
"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 | [
"editable",
"text",
"area"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/oldwidgetshortcuts.rb#L111-L131 | train |
mare-imbrium/canis | lib/canis/core/util/oldwidgetshortcuts.rb | Canis.WidgetShortcuts.stack | def stack config={}, &block
s = WsStack.new config
_configure s
@_ws_active << s
yield_or_eval &block if block_given?
@_ws_active.pop
# ---- stack is finished now
last = @_ws_active.last
if last
case last
when WsStack
when WsFlow
last[:col] += last[:item_width] || 0
# this tries to set height of outer flow based on highest row
# printed, however that does not account for height of object,
# so user should give a height to the flow.
last[:height] = s[:row] if s[:row] > (last[:height]||0)
$log.debug "XXX: STACK setting col to #{s[:col]} "
end
end
end | ruby | def stack config={}, &block
s = WsStack.new config
_configure s
@_ws_active << s
yield_or_eval &block if block_given?
@_ws_active.pop
# ---- stack is finished now
last = @_ws_active.last
if last
case last
when WsStack
when WsFlow
last[:col] += last[:item_width] || 0
# this tries to set height of outer flow based on highest row
# printed, however that does not account for height of object,
# so user should give a height to the flow.
last[:height] = s[:row] if s[:row] > (last[:height]||0)
$log.debug "XXX: STACK setting col to #{s[:col]} "
end
end
end | [
"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",
"]",
"||",
"0",
")",
"$log",
".",
"debug",
"\"XXX: STACK setting col to #{s[:col]} \"",
"end",
"end",
"end"
]
| make it as simple as possible, don't try to be intelligent or
clever, put as much on the user | [
"make",
"it",
"as",
"simple",
"as",
"possible",
"don",
"t",
"try",
"to",
"be",
"intelligent",
"or",
"clever",
"put",
"as",
"much",
"on",
"the",
"user"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/oldwidgetshortcuts.rb#L195-L217 | train |
mare-imbrium/canis | lib/canis/core/util/oldwidgetshortcuts.rb | Canis.WidgetShortcuts.flow | 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] += last[:highest_row]
last[:row] += 1
end
when WsFlow
last[:col] += last[:item_width] || 0
end
end
end | ruby | 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] += last[:highest_row]
last[:row] += 1
end
when WsFlow
last[:col] += last[:item_width] || 0
end
end
end | [
"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_width",
"]",
"||",
"0",
"end",
"end",
"end"
]
| item_width - width to use per item
but the item width may apply to stacks inside not to items | [
"item_width",
"-",
"width",
"to",
"use",
"per",
"item",
"but",
"the",
"item",
"width",
"may",
"apply",
"to",
"stacks",
"inside",
"not",
"to",
"items"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/oldwidgetshortcuts.rb#L221-L241 | train |
mare-imbrium/canis | lib/canis/core/util/oldwidgetshortcuts.rb | Canis.WidgetShortcuts.box | def box config={}, &block
require 'canis/core/widgets/box'
# take current stacks row and col
# advance row by one and col by one
# at end note row and advance by one
# draw a box around using these coordinates. width should be
# provided unless we have item width or something.
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 # needs to be created first or will overwrite area after others painted
yield_or_eval &block if block_given?
h = config[:height] || last[:height] || (last[:row] - r)
h = 2 if h < 2
w = config[:width] || last[:width] || 15 # tmp
case last
when WsFlow
w = last[:col]
when WsStack
#h += 1
end
config[:row] = r
config[:col] = c
config[:height] = h
config[:width] = w
_box.row r
_box.col c
_box.height h
_box.width w
last[:row] += 1
last[:col] += 1 # ??? XXX if flow we need to increment properly or not ?
end
end | ruby | def box config={}, &block
require 'canis/core/widgets/box'
# take current stacks row and col
# advance row by one and col by one
# at end note row and advance by one
# draw a box around using these coordinates. width should be
# provided unless we have item width or something.
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 # needs to be created first or will overwrite area after others painted
yield_or_eval &block if block_given?
h = config[:height] || last[:height] || (last[:row] - r)
h = 2 if h < 2
w = config[:width] || last[:width] || 15 # tmp
case last
when WsFlow
w = last[:col]
when WsStack
#h += 1
end
config[:row] = r
config[:col] = c
config[:height] = h
config[:width] = w
_box.row r
_box.col c
_box.height h
_box.width w
last[:row] += 1
last[:col] += 1 # ??? XXX if flow we need to increment properly or not ?
end
end | [
"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",
"if",
"block_given?",
"h",
"=",
"config",
"[",
":height",
"]",
"||",
"last",
"[",
":height",
"]",
"||",
"(",
"last",
"[",
":row",
"]",
"-",
"r",
")",
"h",
"=",
"2",
"if",
"h",
"<",
"2",
"w",
"=",
"config",
"[",
":width",
"]",
"||",
"last",
"[",
":width",
"]",
"||",
"15",
"case",
"last",
"when",
"WsFlow",
"w",
"=",
"last",
"[",
":col",
"]",
"when",
"WsStack",
"end",
"config",
"[",
":row",
"]",
"=",
"r",
"config",
"[",
":col",
"]",
"=",
"c",
"config",
"[",
":height",
"]",
"=",
"h",
"config",
"[",
":width",
"]",
"=",
"w",
"_box",
".",
"row",
"r",
"_box",
".",
"col",
"c",
"_box",
".",
"height",
"h",
"_box",
".",
"width",
"w",
"last",
"[",
":row",
"]",
"+=",
"1",
"last",
"[",
":col",
"]",
"+=",
"1",
"end",
"end"
]
| flow and stack could have a border option | [
"flow",
"and",
"stack",
"could",
"have",
"a",
"border",
"option"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/oldwidgetshortcuts.rb#L243-L280 | train |
mare-imbrium/canis | lib/canis/core/util/promptmenu.rb | Canis.PromptMenu.menu_tree | 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 | ruby | 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 | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/promptmenu.rb#L107-L118 | train |
mare-imbrium/canis | lib/canis/core/util/promptmenu.rb | Canis.PromptMenu.submenu | def submenu key, label, &block
item = CMenuItem.new(key, label)
@options << item
item.action = PromptMenu.new @caller, label, &block
end | ruby | def submenu key, label, &block
item = CMenuItem.new(key, label)
@options << item
item.action = PromptMenu.new @caller, label, &block
end | [
"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 | [
"To",
"allow",
"a",
"more",
"rubyesque",
"way",
"of",
"defining",
"menus",
"and",
"submenus"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/promptmenu.rb#L121-L125 | train |
mare-imbrium/canis | lib/canis/core/util/promptmenu.rb | Canis.PromptMenu.display_columns | 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"
w = rc.window
r = 4
c = 1
color = $datacolor
begin
menu = @options
$log.debug " DISP MENU "
ret = 0
len = 80
while true
h = {}
valid = []
labels = []
menu.each{ |item|
if item.respond_to? :hotkey
hk = item.hotkey.to_s
else
raise ArgumentError, "Promptmenu needs hotkey or mnemonic"
end
# 187compat 2013-03-20 - 19:00 throws up
labels << "%c. %s " % [ hk.getbyte(0), item.label ]
h[hk] = item
valid << hk
}
#$log.debug " valid are #{valid} "
color = $datacolor
#print_this(win, str, color, r, c)
rc.display_menu labels, :indexing => :custom
ch=w.getchar()
rc.clear
#$log.debug " got ch #{ch} "
next if ch < 0 or ch > 255
if ch == 3 || ch == ?\C-g.getbyte(0)
clear_this w, r, c, color, len
print_this(w, "Aborted.", color, r,c)
break
end
ch = ch.chr
index = valid.index ch
if index.nil?
clear_this w, r, c, color, len
print_this(w, "Not valid. Valid are #{valid}. C-c/C-g to abort.", color, r,c)
sleep 1
next
end
#$log.debug " index is #{index} "
item = h[ch]
# I don;t think this even shows now, its useless
if item.respond_to? :desc
desc = item.desc
#desc ||= "Could not find desc for #{ch} "
desc ||= ""
clear_this w, r, c, color, len
print_this(w, desc, color, r,c)
end
action = item.action
case action
#when Array
when PromptMenu
# submenu
menu = action.options
title = rc.title
rc.title title +" => " + action.text # set title of window to submenu
when Proc
#rc.destroy
##bottom needs to be refreshed somehow
#FFI::NCurses.ungetch ?j
rc.hide
ret = action.call
break
when Symbol
if @caller.respond_to?(action, true)
rc.hide
$log.debug "XXX: IO caller responds to action #{action} "
ret = @caller.send(action)
elsif @caller.respond_to?(:execute_this, true)
rc.hide
ret = @caller.send(:execute_this, action)
else
alert "PromptMenu: unidentified action #{action} for #{@caller.class} "
raise "PromptMenu: unidentified action #{action} for #{@caller.class} "
end
break
else
$log.debug " Unidentified flying class #{action.class} "
break
end
end # while
ensure
rc.destroy
rc = nil
end
end | ruby | 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"
w = rc.window
r = 4
c = 1
color = $datacolor
begin
menu = @options
$log.debug " DISP MENU "
ret = 0
len = 80
while true
h = {}
valid = []
labels = []
menu.each{ |item|
if item.respond_to? :hotkey
hk = item.hotkey.to_s
else
raise ArgumentError, "Promptmenu needs hotkey or mnemonic"
end
# 187compat 2013-03-20 - 19:00 throws up
labels << "%c. %s " % [ hk.getbyte(0), item.label ]
h[hk] = item
valid << hk
}
#$log.debug " valid are #{valid} "
color = $datacolor
#print_this(win, str, color, r, c)
rc.display_menu labels, :indexing => :custom
ch=w.getchar()
rc.clear
#$log.debug " got ch #{ch} "
next if ch < 0 or ch > 255
if ch == 3 || ch == ?\C-g.getbyte(0)
clear_this w, r, c, color, len
print_this(w, "Aborted.", color, r,c)
break
end
ch = ch.chr
index = valid.index ch
if index.nil?
clear_this w, r, c, color, len
print_this(w, "Not valid. Valid are #{valid}. C-c/C-g to abort.", color, r,c)
sleep 1
next
end
#$log.debug " index is #{index} "
item = h[ch]
# I don;t think this even shows now, its useless
if item.respond_to? :desc
desc = item.desc
#desc ||= "Could not find desc for #{ch} "
desc ||= ""
clear_this w, r, c, color, len
print_this(w, desc, color, r,c)
end
action = item.action
case action
#when Array
when PromptMenu
# submenu
menu = action.options
title = rc.title
rc.title title +" => " + action.text # set title of window to submenu
when Proc
#rc.destroy
##bottom needs to be refreshed somehow
#FFI::NCurses.ungetch ?j
rc.hide
ret = action.call
break
when Symbol
if @caller.respond_to?(action, true)
rc.hide
$log.debug "XXX: IO caller responds to action #{action} "
ret = @caller.send(action)
elsif @caller.respond_to?(:execute_this, true)
rc.hide
ret = @caller.send(:execute_this, action)
else
alert "PromptMenu: unidentified action #{action} for #{@caller.class} "
raise "PromptMenu: unidentified action #{action} for #{@caller.class} "
end
break
else
$log.debug " Unidentified flying class #{action.class} "
break
end
end # while
ensure
rc.destroy
rc = nil
end
end | [
"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\"",
"w",
"=",
"rc",
".",
"window",
"r",
"=",
"4",
"c",
"=",
"1",
"color",
"=",
"$datacolor",
"begin",
"menu",
"=",
"@options",
"$log",
".",
"debug",
"\" DISP MENU \"",
"ret",
"=",
"0",
"len",
"=",
"80",
"while",
"true",
"h",
"=",
"{",
"}",
"valid",
"=",
"[",
"]",
"labels",
"=",
"[",
"]",
"menu",
".",
"each",
"{",
"|",
"item",
"|",
"if",
"item",
".",
"respond_to?",
":hotkey",
"hk",
"=",
"item",
".",
"hotkey",
".",
"to_s",
"else",
"raise",
"ArgumentError",
",",
"\"Promptmenu needs hotkey or mnemonic\"",
"end",
"labels",
"<<",
"\"%c. %s \"",
"%",
"[",
"hk",
".",
"getbyte",
"(",
"0",
")",
",",
"item",
".",
"label",
"]",
"h",
"[",
"hk",
"]",
"=",
"item",
"valid",
"<<",
"hk",
"}",
"color",
"=",
"$datacolor",
"rc",
".",
"display_menu",
"labels",
",",
":indexing",
"=>",
":custom",
"ch",
"=",
"w",
".",
"getchar",
"(",
")",
"rc",
".",
"clear",
"next",
"if",
"ch",
"<",
"0",
"or",
"ch",
">",
"255",
"if",
"ch",
"==",
"3",
"||",
"ch",
"==",
"?\\C-g",
".",
"getbyte",
"(",
"0",
")",
"clear_this",
"w",
",",
"r",
",",
"c",
",",
"color",
",",
"len",
"print_this",
"(",
"w",
",",
"\"Aborted.\"",
",",
"color",
",",
"r",
",",
"c",
")",
"break",
"end",
"ch",
"=",
"ch",
".",
"chr",
"index",
"=",
"valid",
".",
"index",
"ch",
"if",
"index",
".",
"nil?",
"clear_this",
"w",
",",
"r",
",",
"c",
",",
"color",
",",
"len",
"print_this",
"(",
"w",
",",
"\"Not valid. Valid are #{valid}. C-c/C-g to abort.\"",
",",
"color",
",",
"r",
",",
"c",
")",
"sleep",
"1",
"next",
"end",
"item",
"=",
"h",
"[",
"ch",
"]",
"if",
"item",
".",
"respond_to?",
":desc",
"desc",
"=",
"item",
".",
"desc",
"desc",
"||=",
"\"\"",
"clear_this",
"w",
",",
"r",
",",
"c",
",",
"color",
",",
"len",
"print_this",
"(",
"w",
",",
"desc",
",",
"color",
",",
"r",
",",
"c",
")",
"end",
"action",
"=",
"item",
".",
"action",
"case",
"action",
"when",
"PromptMenu",
"menu",
"=",
"action",
".",
"options",
"title",
"=",
"rc",
".",
"title",
"rc",
".",
"title",
"title",
"+",
"\" => \"",
"+",
"action",
".",
"text",
"when",
"Proc",
"rc",
".",
"hide",
"ret",
"=",
"action",
".",
"call",
"break",
"when",
"Symbol",
"if",
"@caller",
".",
"respond_to?",
"(",
"action",
",",
"true",
")",
"rc",
".",
"hide",
"$log",
".",
"debug",
"\"XXX: IO caller responds to action #{action} \"",
"ret",
"=",
"@caller",
".",
"send",
"(",
"action",
")",
"elsif",
"@caller",
".",
"respond_to?",
"(",
":execute_this",
",",
"true",
")",
"rc",
".",
"hide",
"ret",
"=",
"@caller",
".",
"send",
"(",
":execute_this",
",",
"action",
")",
"else",
"alert",
"\"PromptMenu: unidentified action #{action} for #{@caller.class} \"",
"raise",
"\"PromptMenu: unidentified action #{action} for #{@caller.class} \"",
"end",
"break",
"else",
"$log",
".",
"debug",
"\" Unidentified flying class #{action.class} \"",
"break",
"end",
"end",
"ensure",
"rc",
".",
"destroy",
"rc",
"=",
"nil",
"end",
"end"
]
| 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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/promptmenu.rb#L131-L229 | train |
mare-imbrium/canis | lib/canis/core/include/deprecated/listcellrenderer.rb | Canis.ListCellRenderer.create_color_pairs | 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] = @pairs[:normal]
@attrs[:selected] = $row_selected_attr
@attrs[:focussed] = $row_focussed_attr
end | ruby | 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] = @pairs[:normal]
@attrs[:selected] = $row_selected_attr
@attrs[:focussed] = $row_focussed_attr
end | [
"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",
"]",
"=",
"@pairs",
"[",
":normal",
"]",
"@attrs",
"[",
":selected",
"]",
"=",
"$row_selected_attr",
"@attrs",
"[",
":focussed",
"]",
"=",
"$row_focussed_attr",
"end"
]
| creates pairs of colors at start
since often classes are overriding init_vars, so not gettin created | [
"creates",
"pairs",
"of",
"colors",
"at",
"start",
"since",
"often",
"classes",
"are",
"overriding",
"init_vars",
"so",
"not",
"gettin",
"created"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/deprecated/listcellrenderer.rb#L48-L59 | train |
mare-imbrium/canis | lib/canis/core/include/deprecated/listcellrenderer.rb | Canis.ListCellRenderer.repaint | def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
select_colors focussed, selected
# if listboxes width is reduced, display_len remains the same
# XXX FIXME parent may not be the list but a container like rfe !!
# maybe caller should update at start of repain loop.
#@display_length = @parent.width - 2 - @parent.left_margin
value=value.to_s
if !@display_length.nil?
if value.length > @display_length
value = value[0..@display_length-1]
end
# added 2010-09-27 11:05 TO UNCOMMENT AND TEST IT OUT
if @justify == :center
value = value.center(@display_length)
end
end
len = @display_length || value.length
#$log.debug " XXX @display_length: #{@display_length}, #{value.length}, L:#{len}, pw:#{@parent.width} ::attr:: #{@attr} "
graphic.printstring r, c, @format % [len, value], @color_pair, @attr
end | ruby | def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
select_colors focussed, selected
# if listboxes width is reduced, display_len remains the same
# XXX FIXME parent may not be the list but a container like rfe !!
# maybe caller should update at start of repain loop.
#@display_length = @parent.width - 2 - @parent.left_margin
value=value.to_s
if !@display_length.nil?
if value.length > @display_length
value = value[0..@display_length-1]
end
# added 2010-09-27 11:05 TO UNCOMMENT AND TEST IT OUT
if @justify == :center
value = value.center(@display_length)
end
end
len = @display_length || value.length
#$log.debug " XXX @display_length: #{@display_length}, #{value.length}, L:#{len}, pw:#{@parent.width} ::attr:: #{@attr} "
graphic.printstring r, c, @format % [len, value], @color_pair, @attr
end | [
"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",
".",
"center",
"(",
"@display_length",
")",
"end",
"end",
"len",
"=",
"@display_length",
"||",
"value",
".",
"length",
"graphic",
".",
"printstring",
"r",
",",
"c",
",",
"@format",
"%",
"[",
"len",
",",
"value",
"]",
",",
"@color_pair",
",",
"@attr",
"end"
]
| paint a list box cell
@param [Buffer] window or buffer object used for printing
@param [Fixnum] row
@param [Fixnum] column
@param [Fixnum] actual index into data, some lists may have actual data elsewhere and
display data separate. e.g. rfe_renderer (directory listing)
@param [String] text to print in cell
@param [Boolean, cell focussed, not focussed
@param [Boolean] cell selected or not | [
"paint",
"a",
"list",
"box",
"cell"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/deprecated/listcellrenderer.rb#L92-L113 | train |
mare-imbrium/canis | lib/canis/core/include/io.rb | Canis.Io.rb_getchar | def rb_getchar(prompt, config={}) # yield field
begin
win = __create_footer_window
#form = Form.new win
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.printstring r, c + prompt.size + 2, " ", color_pair
win.wrefresh
prevchar = 0
entries = nil
while ((ch = win.getchar()) != 999)
return default.ord if default && (ch == 13 || ch == KEY_ENTER)
return nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
if ch == KEY_F1
help_text = config[:help_text] || "No help provided. C-c/C-g aborts."
print_status_message help_text, :wait => 7
win.wrefresh # nevr had to do this with ncurses, but have to with ffi-ncurses ??
next
end
if config[:regexp]
reg = config[:regexp]
if ch > 0 && ch < 256
chs = ch.chr
return ch if chs =~ reg
alert "Wrong character. #{reg} "
else
alert "Wrong character. #{reg} "
end
else
return ch
end
#form.handle_key ch
win.wrefresh
end
rescue => err
Ncurses.beep
$log.error "EXC in rb_getstr #{err} "
$log.error(err.backtrace.join("\n"))
ensure
win.destroy if win
end
return nil
end | ruby | def rb_getchar(prompt, config={}) # yield field
begin
win = __create_footer_window
#form = Form.new win
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.printstring r, c + prompt.size + 2, " ", color_pair
win.wrefresh
prevchar = 0
entries = nil
while ((ch = win.getchar()) != 999)
return default.ord if default && (ch == 13 || ch == KEY_ENTER)
return nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
if ch == KEY_F1
help_text = config[:help_text] || "No help provided. C-c/C-g aborts."
print_status_message help_text, :wait => 7
win.wrefresh # nevr had to do this with ncurses, but have to with ffi-ncurses ??
next
end
if config[:regexp]
reg = config[:regexp]
if ch > 0 && ch < 256
chs = ch.chr
return ch if chs =~ reg
alert "Wrong character. #{reg} "
else
alert "Wrong character. #{reg} "
end
else
return ch
end
#form.handle_key ch
win.wrefresh
end
rescue => err
Ncurses.beep
$log.error "EXC in rb_getstr #{err} "
$log.error(err.backtrace.join("\n"))
ensure
win.destroy if win
end
return nil
end | [
"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",
".",
"printstring",
"r",
",",
"c",
"+",
"prompt",
".",
"size",
"+",
"2",
",",
"\" \"",
",",
"color_pair",
"win",
".",
"wrefresh",
"prevchar",
"=",
"0",
"entries",
"=",
"nil",
"while",
"(",
"(",
"ch",
"=",
"win",
".",
"getchar",
"(",
")",
")",
"!=",
"999",
")",
"return",
"default",
".",
"ord",
"if",
"default",
"&&",
"(",
"ch",
"==",
"13",
"||",
"ch",
"==",
"KEY_ENTER",
")",
"return",
"nil",
"if",
"ch",
"==",
"?\\C-c",
".",
"getbyte",
"(",
"0",
")",
"||",
"ch",
"==",
"?\\C-g",
".",
"getbyte",
"(",
"0",
")",
"if",
"ch",
"==",
"KEY_F1",
"help_text",
"=",
"config",
"[",
":help_text",
"]",
"||",
"\"No help provided. C-c/C-g aborts.\"",
"print_status_message",
"help_text",
",",
":wait",
"=>",
"7",
"win",
".",
"wrefresh",
"next",
"end",
"if",
"config",
"[",
":regexp",
"]",
"reg",
"=",
"config",
"[",
":regexp",
"]",
"if",
"ch",
">",
"0",
"&&",
"ch",
"<",
"256",
"chs",
"=",
"ch",
".",
"chr",
"return",
"ch",
"if",
"chs",
"=~",
"reg",
"alert",
"\"Wrong character. #{reg} \"",
"else",
"alert",
"\"Wrong character. #{reg} \"",
"end",
"else",
"return",
"ch",
"end",
"win",
".",
"wrefresh",
"end",
"rescue",
"=>",
"err",
"Ncurses",
".",
"beep",
"$log",
".",
"error",
"\"EXC in rb_getstr #{err} \"",
"$log",
".",
"error",
"(",
"err",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"win",
".",
"destroy",
"if",
"win",
"end",
"return",
"nil",
"end"
]
| get a character.
unlike rb_gets allows user to enter control or alt or function character too.
@param [String] prompt or label to show.
@param [Hash] configuration such as default or regexp for validation
@return [Integer] nil if canceled, or ret value of getchar which is numeric
If default provided, then ENTER returns the default | [
"get",
"a",
"character",
".",
"unlike",
"rb_gets",
"allows",
"user",
"to",
"enter",
"control",
"or",
"alt",
"or",
"function",
"character",
"too",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/io.rb#L188-L235 | train |
mare-imbrium/canis | lib/canis/core/include/io.rb | Canis.Io.get_file | def get_file prompt, config={} #:nodoc:
maxlen = 70
tabc = Proc.new {|str| Dir.glob(str +"*") }
config[:tab_completion] ||= tabc
config[:maxlen] ||= maxlen
#config[:default] = "test"
#ret, str = rb_getstr(nil,0,0, prompt, maxlen, config)
# 2014-04-25 - 12:42 removed call to deprecated method
str = rb_gets(prompt, config)
#$log.debug " get_file returned #{ret} , #{str} "
str ||= ""
return str
end | ruby | def get_file prompt, config={} #:nodoc:
maxlen = 70
tabc = Proc.new {|str| Dir.glob(str +"*") }
config[:tab_completion] ||= tabc
config[:maxlen] ||= maxlen
#config[:default] = "test"
#ret, str = rb_getstr(nil,0,0, prompt, maxlen, config)
# 2014-04-25 - 12:42 removed call to deprecated method
str = rb_gets(prompt, config)
#$log.debug " get_file returned #{ret} , #{str} "
str ||= ""
return str
end | [
"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
@see #choose_file from rcommandwindow.rb
@param [String] label to print before field
@param [Integer] max length of field
@return [String] filename or blank if user cancelled | [
"This",
"is",
"just",
"experimental",
"trying",
"out",
"tab_completion",
"Prompt",
"user",
"for",
"a",
"file",
"name",
"allowing",
"him",
"to",
"tab",
"to",
"complete",
"filenames"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/io.rb#L243-L255 | train |
mare-imbrium/canis | lib/canis/core/include/io.rb | Canis.Io.print_this | 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, "%-40s" % text);
win.mvprintw(x, y, "%s" % text);
win.attroff(color);
win.refresh
end | ruby | 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, "%-40s" % text);
win.mvprintw(x, y, "%s" % text);
win.attroff(color);
win.refresh
end | [
"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
@param [Window] window to write to
@param [String] text to print
@param [int] color pair such as $datacolor or $promptcolor
@param [int] x row
@param [int] y col
@see Window#printstring | [
"prints",
"given",
"text",
"to",
"window",
"in",
"color",
"at",
"x",
"and",
"y",
"coordinates"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/io.rb#L270-L278 | train |
mare-imbrium/canis | lib/canis/core/include/io.rb | Canis.Io.rb_getstr | 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 | ruby | 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 | [
"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.
@param [String] prompt - label to show
@param [Integer] maxlen - max length of input
@param [Hash] config - :default, :width of Field, :help_text, :tab_completion
help_text is displayed on F1
tab_completion is a proc which helps to complete user input
NOTE : This method is now only for **backward compatibility**
rb_getstr had various return codes based on whether user asked for help
possibly mimicking alpine, or because i could do nothing about it.
Now, rb_getstr handles that and only returns if the user cancels or enters
a string, so rb_getstr does not need to return other codes.
@deprecated | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/io.rb#L307-L315 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.columns= | def columns=(array)
@_header_adjustment = 1
@columns = array
@columns.each_with_index { |c,i|
@cw[i] ||= c.to_s.length
@calign[i] ||= :left
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new @columns.size()-1
end | ruby | def columns=(array)
@_header_adjustment = 1
@columns = array
@columns.each_with_index { |c,i|
@cw[i] ||= c.to_s.length
@calign[i] ||= :left
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new @columns.size()-1
end | [
"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
@param [Array] column names or headings | [
"set",
"column",
"names"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L160-L169 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.OLDprint_borders | def OLDprint_borders #:nodoc:
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, @width, bordercolor, borderatt
print_title
end | ruby | def OLDprint_borders #:nodoc:
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, @width, bordercolor, borderatt
print_title
end | [
"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",
",",
"@width",
",",
"bordercolor",
",",
"borderatt",
"print_title",
"end"
]
| print a border
Note that print_border clears the area too, so should be used sparingly. | [
"print",
"a",
"border",
"Note",
"that",
"print_border",
"clears",
"the",
"area",
"too",
"so",
"should",
"be",
"used",
"sparingly",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L363-L373 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.set_form_col | def set_form_col col1=@curpos #:nodoc:
@cols_panned ||= 0
@pad_offset ||= 0 # added 2010-02-11 21:54 since padded widgets get an offset.
@curpos = col1
maxlen = @maxlen || @width-@internal_width
#@curpos = maxlen if @curpos > maxlen
if @curpos > maxlen
@pcol = @curpos - maxlen
@curpos = maxlen - 1
@repaint_required = true # this is required so C-e can pan screen
else
@pcol = 0
end
# the rest only determines cursor placement
win_col = 0 # 2010-02-07 23:19 new cursor stuff
col2 = win_col + @col + @col_offset + @curpos + @cols_panned + @pad_offset
#$log.debug "TV SFC #{@name} setting c to #{col2} #{win_col} #{@col} #{@col_offset} #{@curpos} "
#@form.setrowcol @form.row, col
setrowcol nil, col2
@repaint_footer_required = true
end | ruby | def set_form_col col1=@curpos #:nodoc:
@cols_panned ||= 0
@pad_offset ||= 0 # added 2010-02-11 21:54 since padded widgets get an offset.
@curpos = col1
maxlen = @maxlen || @width-@internal_width
#@curpos = maxlen if @curpos > maxlen
if @curpos > maxlen
@pcol = @curpos - maxlen
@curpos = maxlen - 1
@repaint_required = true # this is required so C-e can pan screen
else
@pcol = 0
end
# the rest only determines cursor placement
win_col = 0 # 2010-02-07 23:19 new cursor stuff
col2 = win_col + @col + @col_offset + @curpos + @cols_panned + @pad_offset
#$log.debug "TV SFC #{@name} setting c to #{col2} #{win_col} #{@col} #{@col_offset} #{@curpos} "
#@form.setrowcol @form.row, col
setrowcol nil, col2
@repaint_footer_required = true
end | [
"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_offset",
"setrowcol",
"nil",
",",
"col2",
"@repaint_footer_required",
"=",
"true",
"end"
]
| set cursor on correct column tview | [
"set",
"cursor",
"on",
"correct",
"column",
"tview"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L540-L560 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.print_data_row | def print_data_row r, c, len, value, color, attr
@graphic.printstring r, c, "%-*s" % [len,value], color, attr
end | ruby | def print_data_row r, c, len, value, color, attr
@graphic.printstring r, c, "%-*s" % [len,value], color, attr
end | [
"def",
"print_data_row",
"r",
",",
"c",
",",
"len",
",",
"value",
",",
"color",
",",
"attr",
"@graphic",
".",
"printstring",
"r",
",",
"c",
",",
"\"%-*s\"",
"%",
"[",
"len",
",",
"value",
"]",
",",
"color",
",",
"attr",
"end"
]
| print data rows | [
"print",
"data",
"rows"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L675-L677 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.truncate | def truncate content #:nodoc:
#maxlen = @maxlen || @width-2
_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 # only show maxlen
@longest_line = cl if cl > @longest_line
## taking care of when scrolling is needed but longest_line is misreported
# So we scroll always and need to check 2013-03-06 - 00:09
#content.replace content[@pcol..@pcol+_maxlen-1]
content.replace(content[@pcol..@pcol+maxlen-1] || " ")
else
#content.replace content[@pcol..-1] if @pcol > 0
content.replace(content[@pcol..-1]||" ") if @pcol > 0
end
end
content
end | ruby | def truncate content #:nodoc:
#maxlen = @maxlen || @width-2
_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 # only show maxlen
@longest_line = cl if cl > @longest_line
## taking care of when scrolling is needed but longest_line is misreported
# So we scroll always and need to check 2013-03-06 - 00:09
#content.replace content[@pcol..@pcol+_maxlen-1]
content.replace(content[@pcol..@pcol+maxlen-1] || " ")
else
#content.replace content[@pcol..-1] if @pcol > 0
content.replace(content[@pcol..-1]||" ") if @pcol > 0
end
end
content
end | [
"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",
"]",
"||",
"\" \"",
")",
"else",
"content",
".",
"replace",
"(",
"content",
"[",
"@pcol",
"..",
"-",
"1",
"]",
"||",
"\" \"",
")",
"if",
"@pcol",
">",
"0",
"end",
"end",
"content",
"end"
]
| 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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L682-L701 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.print_header_row | def print_header_row r, c, len, value, color, attr
#acolor = $promptcolor
@graphic.printstring r, c+@left_margin, "%-*s" % [len-@left_margin ,value], color, attr
end | ruby | def print_header_row r, c, len, value, color, attr
#acolor = $promptcolor
@graphic.printstring r, c+@left_margin, "%-*s" % [len-@left_margin ,value], color, attr
end | [
"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 | [
"print",
"header",
"row",
"allows",
"user",
"to",
"override"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L705-L708 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.print_header | def print_header
r,c = rowcol
value = convert_value_to_text :columns, 0
len = @width - @internal_width
truncate value # else it can later suddenly exceed line
@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 | ruby | def print_header
r,c = rowcol
value = convert_value_to_text :columns, 0
len = @width - @internal_width
truncate value # else it can later suddenly exceed line
@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 | [
"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+ | [
"prints",
"the",
"column",
"headers",
"Uses",
"+",
"convert_value_to_text",
"+",
"and",
"+",
"print_header_row",
"+"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L721-L729 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget._guess_col_widths | def _guess_col_widths #:nodoc:
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
}
}
#sum = @cw.values.inject(0) { |mem, var| mem + var }
#$log.debug " SUM is #{sum} "
total = 0
@cw.each_pair { |name, val| total += val }
@preferred_width = total + (@cw.size() *2)
@preferred_width += 4 if @numbering # FIXME this 4 is rough
end | ruby | def _guess_col_widths #:nodoc:
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
}
}
#sum = @cw.values.inject(0) { |mem, var| mem + var }
#$log.debug " SUM is #{sum} "
total = 0
@cw.each_pair { |name, val| total += val }
@preferred_width = total + (@cw.size() *2)
@preferred_width += 4 if @numbering # FIXME this 4 is rough
end | [
"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",
"{",
"|",
"name",
",",
"val",
"|",
"total",
"+=",
"val",
"}",
"@preferred_width",
"=",
"total",
"+",
"(",
"@cw",
".",
"size",
"(",
")",
"*",
"2",
")",
"@preferred_width",
"+=",
"4",
"if",
"@numbering",
"end"
]
| perhaps we can delete this since it does not respect @pw
@deprecated (see _estimate_column_widths) | [
"perhaps",
"we",
"can",
"delete",
"this",
"since",
"it",
"does",
"not",
"respect"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L784-L805 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/tabularwidget.rb | Canis.TabularWidget.next_column | def next_column
c = @column_pointer.next
cp = @coffsets[c]
#$log.debug " next_column #{c} , #{cp} "
@curpos = cp if cp
next_row() if c < @column_pointer.last_index
#addcol cp
set_form_col
end | ruby | def next_column
c = @column_pointer.next
cp = @coffsets[c]
#$log.debug " next_column #{c} , #{cp} "
@curpos = cp if cp
next_row() if c < @column_pointer.last_index
#addcol cp
set_form_col
end | [
"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 | [
"move",
"cursor",
"to",
"next",
"column",
"FIXME",
"need",
"to",
"account",
"for",
"hidden",
"columns",
"and",
"numbering"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/tabularwidget.rb#L936-L944 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_server | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"server",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L79-L92 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_server_public_ip | def get_server_public_ip(server, cached_rules=nil, cached_nat=nil)
return nil unless server
# find the public ip
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)
return winrm_rule['ipaddress'] if winrm_rule
#check for static NAT
if cached_nat
ip_addr = cached_nat.find {|v| v['virtualmachineid'] == server['id']}
else
ip_addr = list_public_ip_addresses.find {|v| v['virtualmachineid'] == server['id']}
end
if ip_addr
return ip_addr['ipaddress']
end
if nic.empty?
return []
end
nic['ipaddress'] || []
end | ruby | def get_server_public_ip(server, cached_rules=nil, cached_nat=nil)
return nil unless server
# find the public ip
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)
return winrm_rule['ipaddress'] if winrm_rule
#check for static NAT
if cached_nat
ip_addr = cached_nat.find {|v| v['virtualmachineid'] == server['id']}
else
ip_addr = list_public_ip_addresses.find {|v| v['virtualmachineid'] == server['id']}
end
if ip_addr
return ip_addr['ipaddress']
end
if nic.empty?
return []
end
nic['ipaddress'] || []
end | [
"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",
")",
"return",
"winrm_rule",
"[",
"'ipaddress'",
"]",
"if",
"winrm_rule",
"if",
"cached_nat",
"ip_addr",
"=",
"cached_nat",
".",
"find",
"{",
"|",
"v",
"|",
"v",
"[",
"'virtualmachineid'",
"]",
"==",
"server",
"[",
"'id'",
"]",
"}",
"else",
"ip_addr",
"=",
"list_public_ip_addresses",
".",
"find",
"{",
"|",
"v",
"|",
"v",
"[",
"'virtualmachineid'",
"]",
"==",
"server",
"[",
"'id'",
"]",
"}",
"end",
"if",
"ip_addr",
"return",
"ip_addr",
"[",
"'ipaddress'",
"]",
"end",
"if",
"nic",
".",
"empty?",
"return",
"[",
"]",
"end",
"nic",
"[",
"'ipaddress'",
"]",
"||",
"[",
"]",
"end"
]
| Finds the public ip for a server | [
"Finds",
"the",
"public",
"ip",
"for",
"a",
"server"
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L97-L121 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_server_fqdn | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"fully",
"qualified",
"domain",
"name",
"for",
"a",
"server",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L126-L139 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.list_object | 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 | ruby | 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 | [
"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. | [
"List",
"all",
"the",
"objects",
"based",
"on",
"the",
"command",
"that",
"is",
"specified",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L150-L157 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.create_server | 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 then
puts "\nError: Service offering '#{service_name}' is invalid"
exit 1
end
template = get_template(template_name, zone_name)
template = get_iso(template_name, zone_name) unless template
if !template then
puts "\nError: Template / ISO name: '#{template_name}' is invalid"
exit 1
end
if disk_name then
disk = get_disk_offering(disk_name)
if !disk then
puts "\nError: Disk offering '#{disk_name}' is invalid"
exit 1
end
end
zone = zone_name ? get_zone(zone_name) : get_default_zone
if !zone then
msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
puts "\nError: #{msg}"
exit 1
end
if zone['networktype'] != 'Basic' then
# If this is a Basic zone no networkids are needed in the params
networks = []
if network_names.nil? then
networks << get_default_network(zone['id'])
else
network_names.each do |name|
network = get_network(name)
if !network then
puts "\nError: Network '#{name}' not found"
end
networks << get_network(name)
end
end
if networks.empty? then
networks << get_default_network(zone['id'])
end
if networks.empty? then
puts "\nError: No default network found"
exit 1
end
network_ids = networks.map { |network|
network['id']
}
params = {
'command' => 'deployVirtualMachine',
'serviceOfferingId' => service['id'],
'templateId' => template['id'],
'zoneId' => zone['id'],
'networkids' => network_ids.join(',')
}
else
params = {
'command' => 'deployVirtualMachine',
'serviceOfferingId' => service['id'],
'templateId' => template['id'],
'zoneId' => zone['id']
}
end
params.merge!(extra_params) if extra_params
params['name'] = host_name if host_name
params['diskOfferingId'] = disk['id'] if disk
json = send_async_request(params)
json['virtualmachine']
end | ruby | 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 then
puts "\nError: Service offering '#{service_name}' is invalid"
exit 1
end
template = get_template(template_name, zone_name)
template = get_iso(template_name, zone_name) unless template
if !template then
puts "\nError: Template / ISO name: '#{template_name}' is invalid"
exit 1
end
if disk_name then
disk = get_disk_offering(disk_name)
if !disk then
puts "\nError: Disk offering '#{disk_name}' is invalid"
exit 1
end
end
zone = zone_name ? get_zone(zone_name) : get_default_zone
if !zone then
msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
puts "\nError: #{msg}"
exit 1
end
if zone['networktype'] != 'Basic' then
# If this is a Basic zone no networkids are needed in the params
networks = []
if network_names.nil? then
networks << get_default_network(zone['id'])
else
network_names.each do |name|
network = get_network(name)
if !network then
puts "\nError: Network '#{name}' not found"
end
networks << get_network(name)
end
end
if networks.empty? then
networks << get_default_network(zone['id'])
end
if networks.empty? then
puts "\nError: No default network found"
exit 1
end
network_ids = networks.map { |network|
network['id']
}
params = {
'command' => 'deployVirtualMachine',
'serviceOfferingId' => service['id'],
'templateId' => template['id'],
'zoneId' => zone['id'],
'networkids' => network_ids.join(',')
}
else
params = {
'command' => 'deployVirtualMachine',
'serviceOfferingId' => service['id'],
'templateId' => template['id'],
'zoneId' => zone['id']
}
end
params.merge!(extra_params) if extra_params
params['name'] = host_name if host_name
params['diskOfferingId'] = disk['id'] if disk
json = send_async_request(params)
json['virtualmachine']
end | [
"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",
"then",
"puts",
"\"\\nError: Service offering '#{service_name}' is invalid\"",
"exit",
"1",
"end",
"template",
"=",
"get_template",
"(",
"template_name",
",",
"zone_name",
")",
"template",
"=",
"get_iso",
"(",
"template_name",
",",
"zone_name",
")",
"unless",
"template",
"if",
"!",
"template",
"then",
"puts",
"\"\\nError: Template / ISO name: '#{template_name}' is invalid\"",
"exit",
"1",
"end",
"if",
"disk_name",
"then",
"disk",
"=",
"get_disk_offering",
"(",
"disk_name",
")",
"if",
"!",
"disk",
"then",
"puts",
"\"\\nError: Disk offering '#{disk_name}' is invalid\"",
"exit",
"1",
"end",
"end",
"zone",
"=",
"zone_name",
"?",
"get_zone",
"(",
"zone_name",
")",
":",
"get_default_zone",
"if",
"!",
"zone",
"then",
"msg",
"=",
"zone_name",
"?",
"\"Zone '#{zone_name}' is invalid\"",
":",
"\"No default zone found\"",
"puts",
"\"\\nError: #{msg}\"",
"exit",
"1",
"end",
"if",
"zone",
"[",
"'networktype'",
"]",
"!=",
"'Basic'",
"then",
"networks",
"=",
"[",
"]",
"if",
"network_names",
".",
"nil?",
"then",
"networks",
"<<",
"get_default_network",
"(",
"zone",
"[",
"'id'",
"]",
")",
"else",
"network_names",
".",
"each",
"do",
"|",
"name",
"|",
"network",
"=",
"get_network",
"(",
"name",
")",
"if",
"!",
"network",
"then",
"puts",
"\"\\nError: Network '#{name}' not found\"",
"end",
"networks",
"<<",
"get_network",
"(",
"name",
")",
"end",
"end",
"if",
"networks",
".",
"empty?",
"then",
"networks",
"<<",
"get_default_network",
"(",
"zone",
"[",
"'id'",
"]",
")",
"end",
"if",
"networks",
".",
"empty?",
"then",
"puts",
"\"\\nError: No default network found\"",
"exit",
"1",
"end",
"network_ids",
"=",
"networks",
".",
"map",
"{",
"|",
"network",
"|",
"network",
"[",
"'id'",
"]",
"}",
"params",
"=",
"{",
"'command'",
"=>",
"'deployVirtualMachine'",
",",
"'serviceOfferingId'",
"=>",
"service",
"[",
"'id'",
"]",
",",
"'templateId'",
"=>",
"template",
"[",
"'id'",
"]",
",",
"'zoneId'",
"=>",
"zone",
"[",
"'id'",
"]",
",",
"'networkids'",
"=>",
"network_ids",
".",
"join",
"(",
"','",
")",
"}",
"else",
"params",
"=",
"{",
"'command'",
"=>",
"'deployVirtualMachine'",
",",
"'serviceOfferingId'",
"=>",
"service",
"[",
"'id'",
"]",
",",
"'templateId'",
"=>",
"template",
"[",
"'id'",
"]",
",",
"'zoneId'",
"=>",
"zone",
"[",
"'id'",
"]",
"}",
"end",
"params",
".",
"merge!",
"(",
"extra_params",
")",
"if",
"extra_params",
"params",
"[",
"'name'",
"]",
"=",
"host_name",
"if",
"host_name",
"params",
"[",
"'diskOfferingId'",
"]",
"=",
"disk",
"[",
"'id'",
"]",
"if",
"disk",
"json",
"=",
"send_async_request",
"(",
"params",
")",
"json",
"[",
"'virtualmachine'",
"]",
"end"
]
| Deploys a new server using the specified parameters. | [
"Deploys",
"a",
"new",
"server",
"using",
"the",
"specified",
"parameters",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L173-L264 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.delete_server | 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['virtualmachine']
end | ruby | 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['virtualmachine']
end | [
"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",
"[",
"'virtualmachine'",
"]",
"end"
]
| Deletes the server with the specified name. | [
"Deletes",
"the",
"server",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L270-L285 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.stop_server | 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)
json['virtualmachine']
end | ruby | 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)
json['virtualmachine']
end | [
"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",
")",
"json",
"[",
"'virtualmachine'",
"]",
"end"
]
| Stops the server with the specified name. | [
"Stops",
"the",
"server",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L291-L306 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.start_server | 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 | ruby | 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 | [
"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. | [
"Start",
"the",
"server",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L312-L326 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_service_offering | def get_service_offering(name)
# TODO: use name parameter
# listServiceOfferings in CloudStack 2.2 doesn't seem to work
# when the name parameter is specified. When this is fixed,
# the name parameter should be added to the request.
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 | ruby | def get_service_offering(name)
# TODO: use name parameter
# listServiceOfferings in CloudStack 2.2 doesn't seem to work
# when the name parameter is specified. When this is fixed,
# the name parameter should be added to the request.
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 | [
"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. | [
"Finds",
"the",
"service",
"offering",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L351-L373 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_template | def get_template(name, zone_name=nil)
# TODO: use name parameter
# listTemplates in CloudStack 2.2 doesn't seem to work
# when the name parameter is specified. When this is fixed,
# the name parameter should be added to the request.
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
templates.each { |t|
if name.is_uuid? then
return t if t['id'] == name
else
return t if t['name'] == name
end
}
nil
end | ruby | def get_template(name, zone_name=nil)
# TODO: use name parameter
# listTemplates in CloudStack 2.2 doesn't seem to work
# when the name parameter is specified. When this is fixed,
# the name parameter should be added to the request.
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
templates.each { |t|
if name.is_uuid? then
return t if t['id'] == name
else
return t if t['name'] == name
end
}
nil
end | [
"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",
"templates",
".",
"each",
"{",
"|",
"t",
"|",
"if",
"name",
".",
"is_uuid?",
"then",
"return",
"t",
"if",
"t",
"[",
"'id'",
"]",
"==",
"name",
"else",
"return",
"t",
"if",
"t",
"[",
"'name'",
"]",
"==",
"name",
"end",
"}",
"nil",
"end"
]
| Finds the template with the specified name. | [
"Finds",
"the",
"template",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L398-L426 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_iso | 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_uuid? then
return i if i['id'] == name
else
return i if i['name'] == name
end
}
nil
end | ruby | 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_uuid? then
return i if i['id'] == name
else
return i if i['name'] == name
end
}
nil
end | [
"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_uuid?",
"then",
"return",
"i",
"if",
"i",
"[",
"'id'",
"]",
"==",
"name",
"else",
"return",
"i",
"if",
"i",
"[",
"'name'",
"]",
"==",
"name",
"end",
"}",
"nil",
"end"
]
| Finds the iso with the specified name. | [
"Finds",
"the",
"iso",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L431-L452 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_disk_offering | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"disk",
"offering",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L459-L472 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_volume | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"volume",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L478-L491 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.delete_volume | 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 | ruby | 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 | [
"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. | [
"Deletes",
"the",
"volume",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L497-L511 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_project | 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 | ruby | 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 | [
"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 | [
"Fetch",
"project",
"with",
"the",
"specified",
"name"
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L535-L553 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.data_filter | 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 = data.find_all { |k| k["#{field}"].to_s == "#{search}" } if field && search
end
end
data
end | ruby | 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 = data.find_all { |k| k["#{field}"].to_s == "#{search}" } if field && search
end
end
data
end | [
"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",
"=",
"data",
".",
"find_all",
"{",
"|",
"k",
"|",
"k",
"[",
"\"#{field}\"",
"]",
".",
"to_s",
"==",
"\"#{search}\"",
"}",
"if",
"field",
"&&",
"search",
"end",
"end",
"data",
"end"
]
| Filter data on regex or just on string | [
"Filter",
"data",
"on",
"regex",
"or",
"just",
"on",
"string"
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L558-L569 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_network | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"network",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L575-L592 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_default_network | 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['type'] == 'Direct' then
default = n
break
end
}
default
end | ruby | 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['type'] == 'Direct' then
default = n
break
end
}
default
end | [
"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",
"[",
"'type'",
"]",
"==",
"'Direct'",
"then",
"default",
"=",
"n",
"break",
"end",
"}",
"default",
"end"
]
| Finds the default network. | [
"Finds",
"the",
"default",
"network",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L597-L619 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_zone | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"zone",
"with",
"the",
"specified",
"name",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L635-L653 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_default_zone | def get_default_zone
params = {
'command' => 'listZones',
'available' => 'true'
}
json = send_request(params)
zones = json['zone']
return nil unless zones
# zones.sort! # sort zones so we always return the same zone
# !this gives error in our production environment so need to retest this
zones.first
end | ruby | def get_default_zone
params = {
'command' => 'listZones',
'available' => 'true'
}
json = send_request(params)
zones = json['zone']
return nil unless zones
# zones.sort! # sort zones so we always return the same zone
# !this gives error in our production environment so need to retest this
zones.first
end | [
"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. | [
"Finds",
"the",
"default",
"zone",
"for",
"your",
"account",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L684-L696 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_public_ip_address | 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 | ruby | 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 | [
"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. | [
"Finds",
"the",
"public",
"ip",
"address",
"for",
"a",
"given",
"ip",
"address",
"string",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L713-L721 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.associate_ip_address | def associate_ip_address(zone_id, networks)
params = {
'command' => 'associateIpAddress',
'zoneId' => zone_id
}
#Choose the first network from the list
if networks.nil? || networks.empty?
default_network = get_default_network(zone_id)
params['networkId'] = default_network['id']
else
params['networkId'] = get_network(networks.first)['id']
end
Chef::Log.debug("associate ip params: #{params}")
json = send_async_request(params)
json['ipaddress']
end | ruby | def associate_ip_address(zone_id, networks)
params = {
'command' => 'associateIpAddress',
'zoneId' => zone_id
}
#Choose the first network from the list
if networks.nil? || networks.empty?
default_network = get_default_network(zone_id)
params['networkId'] = default_network['id']
else
params['networkId'] = get_network(networks.first)['id']
end
Chef::Log.debug("associate ip params: #{params}")
json = send_async_request(params)
json['ipaddress']
end | [
"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",
")",
"[",
"'id'",
"]",
"end",
"Chef",
"::",
"Log",
".",
"debug",
"(",
"\"associate ip params: #{params}\"",
")",
"json",
"=",
"send_async_request",
"(",
"params",
")",
"json",
"[",
"'ipaddress'",
"]",
"end"
]
| Acquires and associates a public IP to an account. | [
"Acquires",
"and",
"associates",
"a",
"public",
"IP",
"to",
"an",
"account",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L733-L748 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.list_port_forwarding_rules | 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 | ruby | 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 | [
"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. | [
"Lists",
"all",
"port",
"forwarding",
"rules",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L819-L825 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_ssh_port_forwarding_rule | 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 | ruby | 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 | [
"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. | [
"Gets",
"the",
"SSH",
"port",
"forwarding",
"rule",
"for",
"the",
"specified",
"server",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L830-L837 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.get_winrm_port_forwarding_rule | 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'] == '5986')
}.first
end | ruby | 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'] == '5986')
}.first
end | [
"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'",
"]",
"==",
"'5986'",
")",
"}",
".",
"first",
"end"
]
| Gets the WINRM port forwarding rule for the specified server. | [
"Gets",
"the",
"WINRM",
"port",
"forwarding",
"rule",
"for",
"the",
"specified",
"server",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L842-L851 | train |
CloudStack-extras/knife-cloudstack | lib/knife-cloudstack/connection.rb | CloudstackClient.Connection.create_port_forwarding_rule | 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_machine_id
}
json = send_async_request(params)
json['portforwardingrule']
end | ruby | 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_machine_id
}
json = send_async_request(params)
json['portforwardingrule']
end | [
"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_machine_id",
"}",
"json",
"=",
"send_async_request",
"(",
"params",
")",
"json",
"[",
"'portforwardingrule'",
"]",
"end"
]
| Creates a port forwarding rule. | [
"Creates",
"a",
"port",
"forwarding",
"rule",
"."
]
| 7fa996cabac740b8c29e7b0c84508134372823bd | https://github.com/CloudStack-extras/knife-cloudstack/blob/7fa996cabac740b8c29e7b0c84508134372823bd/lib/knife-cloudstack/connection.rb#L856-L867 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Utils.key_tos | 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
#"<M-C-#{x.chr}>"
xx = key_tos(x).gsub(/[<>]/,"")
"<M-#{xx}>"
when 160..255
x = ch - 128
xx = key_tos(x).gsub(/[<>]/,"")
"<M-#{xx}>"
when 255
"<M-BACKSPACE>"
when 2727
"<ESC-ESC>"
else
chs = FFI::NCurses::keyname(ch)
# remove those ugly brackets around function keys
if chs && chs[-1]==')'
chs = chs.gsub(/[()]/,'')
end
if chs
chs = chs.gsub("KEY_","")
"<#{chs}>"
else
"UNKNOWN:#{ch}"
end
end
$key_cache[ch] = chr
return chr
end | ruby | 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
#"<M-C-#{x.chr}>"
xx = key_tos(x).gsub(/[<>]/,"")
"<M-#{xx}>"
when 160..255
x = ch - 128
xx = key_tos(x).gsub(/[<>]/,"")
"<M-#{xx}>"
when 255
"<M-BACKSPACE>"
when 2727
"<ESC-ESC>"
else
chs = FFI::NCurses::keyname(ch)
# remove those ugly brackets around function keys
if chs && chs[-1]==')'
chs = chs.gsub(/[()]/,'')
end
if chs
chs = chs.gsub("KEY_","")
"<#{chs}>"
else
"UNKNOWN:#{ch}"
end
end
$key_cache[ch] = chr
return chr
end | [
"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",
"=",
"key_tos",
"(",
"x",
")",
".",
"gsub",
"(",
"/",
"/",
",",
"\"\"",
")",
"\"<M-#{xx}>\"",
"when",
"160",
"..",
"255",
"x",
"=",
"ch",
"-",
"128",
"xx",
"=",
"key_tos",
"(",
"x",
")",
".",
"gsub",
"(",
"/",
"/",
",",
"\"\"",
")",
"\"<M-#{xx}>\"",
"when",
"255",
"\"<M-BACKSPACE>\"",
"when",
"2727",
"\"<ESC-ESC>\"",
"else",
"chs",
"=",
"FFI",
"::",
"NCurses",
"::",
"keyname",
"(",
"ch",
")",
"if",
"chs",
"&&",
"chs",
"[",
"-",
"1",
"]",
"==",
"')'",
"chs",
"=",
"chs",
".",
"gsub",
"(",
"/",
"/",
",",
"''",
")",
"end",
"if",
"chs",
"chs",
"=",
"chs",
".",
"gsub",
"(",
"\"KEY_\"",
",",
"\"\"",
")",
"\"<#{chs}>\"",
"else",
"\"UNKNOWN:#{ch}\"",
"end",
"end",
"$key_cache",
"[",
"ch",
"]",
"=",
"chr",
"return",
"chr",
"end"
]
| returns a string representation of a given int keycode
@param [Integer] keycode read by window
In some case, such as Meta/Alt codes, the window reads two ints, but still we are using the param
as the value returned by ?\M-a.getbyte(0) and such, which is typically 128 + key
@return [String] a string representation which is what is to be used when binding a key to an
action or Proc. This is close to what vimrc recognizes such as <CR> <C-a> a-zA-z0-9 <SPACE>
Hopefully it should be identical to what vim recognizes in the map command.
If the key is not known to this program it returns "UNKNOWN:key" which means this program
needs to take care of that combination. FIXME some numbers are missing in between.
NOTE do we really need to cache everything ? Only the computed ones should be cached ? | [
"returns",
"a",
"string",
"representation",
"of",
"a",
"given",
"int",
"keycode"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L188-L242 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Utils.get_color | def get_color default=$datacolor, color=color(), bgcolor=bgcolor()
return default if color.nil? || bgcolor.nil?
#raise ArgumentError, "Color not valid: #{color}: #{ColorMap.colors} " if !ColorMap.is_color? color
#raise ArgumentError, "Bgolor not valid: #{bgcolor} : #{ColorMap.colors} " if !ColorMap.is_color? bgcolor
acolor = ColorMap.get_color(color, bgcolor)
return acolor
end | ruby | def get_color default=$datacolor, color=color(), bgcolor=bgcolor()
return default if color.nil? || bgcolor.nil?
#raise ArgumentError, "Color not valid: #{color}: #{ColorMap.colors} " if !ColorMap.is_color? color
#raise ArgumentError, "Bgolor not valid: #{bgcolor} : #{ColorMap.colors} " if !ColorMap.is_color? bgcolor
acolor = ColorMap.get_color(color, bgcolor)
return acolor
end | [
"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.
@param [Integer] color_pair created by ncurses
@param [Symbol] color name such as white black cyan magenta red green yellow
@param [Symbol] bgcolor name such as white black cyan magenta red green yellow
@example get_color $promptcolor, :white, :cyan | [
"}}}",
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L321-L327 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Utils.print_key_bindings | def print_key_bindings *args
f = get_current_field
#labels = [@key_label, f.key_label]
#labels = [@key_label]
#labels << f.key_label if f.key_label
labels = []
labels << (f.key_label || {}) #if 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 << " === Form bindings ==="
end
h.each_pair { |name, val|
if name.is_a? Integer
name = keycode_tos name
elsif name.is_a? String
name = keycode_tos(name.getbyte(0))
elsif name.is_a? Array
s = []
name.each { |e|
s << keycode_tos(e.getbyte(0))
}
name = s
else
#$log.debug "XXX: KEY #{name} #{name.class} "
end
arr << " %-30s %s" % [name ,val]
$log.debug "KEY: #{name} : #{val} "
}
}
textdialog arr, :title => "Key Bindings"
end | ruby | def print_key_bindings *args
f = get_current_field
#labels = [@key_label, f.key_label]
#labels = [@key_label]
#labels << f.key_label if f.key_label
labels = []
labels << (f.key_label || {}) #if 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 << " === Form bindings ==="
end
h.each_pair { |name, val|
if name.is_a? Integer
name = keycode_tos name
elsif name.is_a? String
name = keycode_tos(name.getbyte(0))
elsif name.is_a? Array
s = []
name.each { |e|
s << keycode_tos(e.getbyte(0))
}
name = s
else
#$log.debug "XXX: KEY #{name} #{name.class} "
end
arr << " %-30s %s" % [name ,val]
$log.debug "KEY: #{name} : #{val} "
}
}
textdialog arr, :title => "Key Bindings"
end | [
"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",
"<<",
"\" === Form bindings ===\"",
"end",
"h",
".",
"each_pair",
"{",
"|",
"name",
",",
"val",
"|",
"if",
"name",
".",
"is_a?",
"Integer",
"name",
"=",
"keycode_tos",
"name",
"elsif",
"name",
".",
"is_a?",
"String",
"name",
"=",
"keycode_tos",
"(",
"name",
".",
"getbyte",
"(",
"0",
")",
")",
"elsif",
"name",
".",
"is_a?",
"Array",
"s",
"=",
"[",
"]",
"name",
".",
"each",
"{",
"|",
"e",
"|",
"s",
"<<",
"keycode_tos",
"(",
"e",
".",
"getbyte",
"(",
"0",
")",
")",
"}",
"name",
"=",
"s",
"else",
"end",
"arr",
"<<",
"\" %-30s %s\"",
"%",
"[",
"name",
",",
"val",
"]",
"$log",
".",
"debug",
"\"KEY: #{name} : #{val} \"",
"}",
"}",
"textdialog",
"arr",
",",
":title",
"=>",
"\"Key Bindings\"",
"end"
]
| Display key bindings for current widget and form in dialog | [
"Display",
"key",
"bindings",
"for",
"current",
"widget",
"and",
"form",
"in",
"dialog"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L714-L753 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Utils.view | def view what, config={}, &block # :yields: textview for further configuration
require 'canis/core/util/viewer'
Canis::Viewer.view what, config, &block
end | ruby | def view what, config={}, &block # :yields: textview for further configuration
require 'canis/core/util/viewer'
Canis::Viewer.view what, config, &block
end | [
"def",
"view",
"what",
",",
"config",
"=",
"{",
"}",
",",
"&",
"block",
"require",
"'canis/core/util/viewer'",
"Canis",
"::",
"Viewer",
".",
"view",
"what",
",",
"config",
",",
"&",
"block",
"end"
]
| view a file or array of strings | [
"view",
"a",
"file",
"or",
"array",
"of",
"strings"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L904-L907 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Utils.create_logger | def create_logger path
#path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
_path = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
logg = Logger.new(_path)
raise "Could not create logger: #{path}" unless logg
# if not set, will default to 0 which is debug. Other values are 1 - info, 2 - warn
logg.level = ENV["CANIS_LOG_LEVEL"].to_i
colors = Ncurses.COLORS
logg.info "START #{colors} colors -- #{$0} win: #{@window} : log level: #{logg.level}. To change log level, increase CANIS_LOG_LEVEL in your environment to 1 or 2 or 3."
return logg
end | ruby | def create_logger path
#path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
_path = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
logg = Logger.new(_path)
raise "Could not create logger: #{path}" unless logg
# if not set, will default to 0 which is debug. Other values are 1 - info, 2 - warn
logg.level = ENV["CANIS_LOG_LEVEL"].to_i
colors = Ncurses.COLORS
logg.info "START #{colors} colors -- #{$0} win: #{@window} : log level: #{logg.level}. To change log level, increase CANIS_LOG_LEVEL in your environment to 1 or 2 or 3."
return logg
end | [
"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} : log level: #{logg.level}. To change log level, increase CANIS_LOG_LEVEL in your environment to 1 or 2 or 3.\"",
"return",
"logg",
"end"
]
| create a logger giving a path. | [
"create",
"a",
"logger",
"giving",
"a",
"path",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L909-L919 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.EventHandler.fire_property_change | def fire_property_change text, oldvalue, newvalue
return if @_object_created.nil? # 2018-05-15 - removed check for nil, as object can be nil on creation
# but set later.
#$log.debug " FPC #{self}: #{text} #{oldvalue}, #{newvalue}"
$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_required = true
repaint_all(true) # for repainting borders, headers etc 2011-09-28 V1.3.1
end | ruby | def fire_property_change text, oldvalue, newvalue
return if @_object_created.nil? # 2018-05-15 - removed check for nil, as object can be nil on creation
# but set later.
#$log.debug " FPC #{self}: #{text} #{oldvalue}, #{newvalue}"
$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_required = true
repaint_all(true) # for repainting borders, headers etc 2011-09-28 V1.3.1
end | [
"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_required",
"=",
"true",
"repaint_all",
"(",
"true",
")",
"end"
]
| goes with dsl_property
Can throw a FieldValidationException or PropertyVetoException | [
"goes",
"with",
"dsl_property",
"Can",
"throw",
"a",
"FieldValidationException",
"or",
"PropertyVetoException"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1027-L1040 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Widget.property_set | 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?
#@#{sym} = tmp
instance_variable_set "@#{sym}", tmp
end
return(self) if oldvalue.nil? || @_object_created.nil?
if oldvalue != newvalue
# trying to reduce calls to fire, when object is being created
begin
@property_changed = true
fire_property_change("#{sym}", oldvalue, newvalue) if !oldvalue.nil?
#@#{sym} = tmp
instance_variable_set "@#{sym}", tmp
#@config["#{sym}"]=@#{sym}
rescue PropertyVetoException
$log.warn "PropertyVetoException for #{sym}:" + oldvalue.to_s + "-> "+ newvalue.to_s
end
end # if old
self
end | ruby | 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?
#@#{sym} = tmp
instance_variable_set "@#{sym}", tmp
end
return(self) if oldvalue.nil? || @_object_created.nil?
if oldvalue != newvalue
# trying to reduce calls to fire, when object is being created
begin
@property_changed = true
fire_property_change("#{sym}", oldvalue, newvalue) if !oldvalue.nil?
#@#{sym} = tmp
instance_variable_set "@#{sym}", tmp
#@config["#{sym}"]=@#{sym}
rescue PropertyVetoException
$log.warn "PropertyVetoException for #{sym}:" + oldvalue.to_s + "-> "+ newvalue.to_s
end
end # if old
self
end | [
"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_changed",
"=",
"true",
"fire_property_change",
"(",
"\"#{sym}\"",
",",
"oldvalue",
",",
"newvalue",
")",
"if",
"!",
"oldvalue",
".",
"nil?",
"instance_variable_set",
"\"@#{sym}\"",
",",
"tmp",
"rescue",
"PropertyVetoException",
"$log",
".",
"warn",
"\"PropertyVetoException for #{sym}:\"",
"+",
"oldvalue",
".",
"to_s",
"+",
"\"-> \"",
"+",
"newvalue",
".",
"to_s",
"end",
"end",
"self",
"end"
]
| 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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1172-L1195 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Widget.repaint | def repaint
r,c = rowcol
#@bgcolor ||= $def_bg_color # moved down 2011-11-5
#@color ||= $def_fg_color
_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], acolor, attr()
# next line should be in same color but only have @att so we can change att is nec
#@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, @bgcolor, nil)
end | ruby | def repaint
r,c = rowcol
#@bgcolor ||= $def_bg_color # moved down 2011-11-5
#@color ||= $def_fg_color
_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], acolor, attr()
# next line should be in same color but only have @att so we can change att is nec
#@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, @bgcolor, nil)
end | [
"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",
"]",
",",
"acolor",
",",
"attr",
"(",
")",
"end"
]
| default repaint method. Called by form for all widgets.
widget does not have display_length. | [
"default",
"repaint",
"method",
".",
"Called",
"by",
"form",
"for",
"all",
"widgets",
".",
"widget",
"does",
"not",
"have",
"display_length",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1274-L1287 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Widget.set_form | 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
# 2009-10-29 15:04 use form.window, unless buffer created
# should not use form.window so explicitly everywhere.
# added 2009-12-27 20:05 BUFFERED in case child object needs a form.
# We don;t wish to overwrite the graphic object
if @graphic.nil?
#$log.debug " setting graphic to form window for #{self.class}, #{form} "
@graphic = form.window unless form.nil? # use screen for writing, not buffer
end
# execute those actions delayed due to absence of form -- used internally
# mostly by buttons and labels to bind hotkey to form
fire_handler(:FORM_ATTACHED, self) if event? :FORM_ATTACHED
end | ruby | 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
# 2009-10-29 15:04 use form.window, unless buffer created
# should not use form.window so explicitly everywhere.
# added 2009-12-27 20:05 BUFFERED in case child object needs a form.
# We don;t wish to overwrite the graphic object
if @graphic.nil?
#$log.debug " setting graphic to form window for #{self.class}, #{form} "
@graphic = form.window unless form.nil? # use screen for writing, not buffer
end
# execute those actions delayed due to absence of form -- used internally
# mostly by buttons and labels to bind hotkey to form
fire_handler(:FORM_ATTACHED, self) if event? :FORM_ATTACHED
end | [
"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. | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1298-L1313 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Widget.color_pair | def color_pair(*val)
if val.empty?
#return @color_pair
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_for_pair @color_pair
when 2
@color = val.first if val.first
@bgcolor = val.last if val.last
@color_pair = get_color $datacolor, @color, @bgcolor
end
if oldvalue != @color_pair
fire_property_change(:color_pair, oldvalue, @color_pair)
@property_changed = true
repaint_all true
end
self
end | ruby | def color_pair(*val)
if val.empty?
#return @color_pair
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_for_pair @color_pair
when 2
@color = val.first if val.first
@bgcolor = val.last if val.last
@color_pair = get_color $datacolor, @color, @bgcolor
end
if oldvalue != @color_pair
fire_property_change(:color_pair, oldvalue, @color_pair)
@property_changed = true
repaint_all true
end
self
end | [
"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_for_pair",
"@color_pair",
"when",
"2",
"@color",
"=",
"val",
".",
"first",
"if",
"val",
".",
"first",
"@bgcolor",
"=",
"val",
".",
"last",
"if",
"val",
".",
"last",
"@color_pair",
"=",
"get_color",
"$datacolor",
",",
"@color",
",",
"@bgcolor",
"end",
"if",
"oldvalue",
"!=",
"@color_pair",
"fire_property_change",
"(",
":color_pair",
",",
"oldvalue",
",",
"@color_pair",
")",
"@property_changed",
"=",
"true",
"repaint_all",
"true",
"end",
"self",
"end"
]
| returns array of events defined for this object
@deprecated, should be in eventhandler
def event_list
return @_events if defined? @_events
nil
end
2011-11-12 trying to make color setting a bit sane
You may set as a color_pair using get_color which gives a fixnum
or you may give 2 color symbols so i can update color, bgcolor and colorpair in one shot
if one of them is nil, i just use the existing value | [
"returns",
"array",
"of",
"events",
"defined",
"for",
"this",
"object"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1472-L1495 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Widget.command | def command *args, &block
if event? :PRESS
bind :PRESS, *args, &block
else
bind :CHANGED, *args, &block
end
end | ruby | def command *args, &block
if event? :PRESS
bind :PRESS, *args, &block
else
bind :CHANGED, *args, &block
end
end | [
"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.
@since 1.5.0 2011-11-21 | [
"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",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1499-L1505 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.set_menu_bar | 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 | ruby | 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 | [
"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 ? | [
"set",
"this",
"menubar",
"as",
"the",
"form",
"s",
"menu",
"bar",
".",
"also",
"bind",
"the",
"toggle_key",
"for",
"popping",
"up",
".",
"Should",
"this",
"not",
"be",
"at",
"application",
"level",
"?"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1616-L1629 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.repaint | 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 # added 2008-12-09 12:17
#$log.debug "XXX: FORM CALLING REPAINT OF WIDGET #{f} IN LOOP"
#raise "Row or col nil #{f.row} #{f.col} for #{f}, #{f.name} " if f.row.nil? || f.col.nil?
f.repaint
f._object_created = true # added 2010-09-16 13:02 now prop handlers can be fired
end
_update_focusables if @focusable_modified
# this can bomb if someone sets row. We need a better way!
if @row == -1 and @_firsttime == true
select_first_field
@_firsttime = false
end
setpos
# XXX this creates a problem if window is a pad
# although this does show cursor movement etc.
### @window.wrefresh
#if @window.window_type == :WINDOW
#$log.debug " formrepaint #{@name} calling window.wrefresh #{@window} "
@window.wrefresh
Ncurses::Panel.update_panels ## added 2010-11-05 00:30 to see if clears the stdscr problems
#else
#$log.warn " XXX formrepaint #{@name} no refresh called 2011-09-19 #{@window} "
#end
end | ruby | 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 # added 2008-12-09 12:17
#$log.debug "XXX: FORM CALLING REPAINT OF WIDGET #{f} IN LOOP"
#raise "Row or col nil #{f.row} #{f.col} for #{f}, #{f.name} " if f.row.nil? || f.col.nil?
f.repaint
f._object_created = true # added 2010-09-16 13:02 now prop handlers can be fired
end
_update_focusables if @focusable_modified
# this can bomb if someone sets row. We need a better way!
if @row == -1 and @_firsttime == true
select_first_field
@_firsttime = false
end
setpos
# XXX this creates a problem if window is a pad
# although this does show cursor movement etc.
### @window.wrefresh
#if @window.window_type == :WINDOW
#$log.debug " formrepaint #{@name} calling window.wrefresh #{@window} "
@window.wrefresh
Ncurses::Panel.update_panels ## added 2010-11-05 00:30 to see if clears the stdscr problems
#else
#$log.warn " XXX formrepaint #{@name} no refresh called 2011-09-19 #{@window} "
#end
end | [
"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",
"f",
".",
"_object_created",
"=",
"true",
"end",
"_update_focusables",
"if",
"@focusable_modified",
"if",
"@row",
"==",
"-",
"1",
"and",
"@_firsttime",
"==",
"true",
"select_first_field",
"@_firsttime",
"=",
"false",
"end",
"setpos",
"@window",
".",
"wrefresh",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"end"
]
| form repaint,calls repaint on each widget which will repaint it only if it has been modified since last call.
called after each keypress. | [
"form",
"repaint",
"calls",
"repaint",
"on",
"each",
"widget",
"which",
"will",
"repaint",
"it",
"only",
"if",
"it",
"has",
"been",
"modified",
"since",
"last",
"call",
".",
"called",
"after",
"each",
"keypress",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1676-L1709 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.setpos | def setpos r=@row, c=@col
#$log.debug "setpos : (#{self.name}) #{r} #{c} XXX"
## adding just in case things are going out of bounds of a parent and no cursor to be shown
return if r.nil? or c.nil? # added 2009-12-29 23:28 BUFFERED
return if r<0 or c<0 # added 2010-01-02 18:49 stack too deep coming if goes above screen
@window.wmove r,c
end | ruby | def setpos r=@row, c=@col
#$log.debug "setpos : (#{self.name}) #{r} #{c} XXX"
## adding just in case things are going out of bounds of a parent and no cursor to be shown
return if r.nil? or c.nil? # added 2009-12-29 23:28 BUFFERED
return if r<0 or c<0 # added 2010-01-02 18:49 stack too deep coming if goes above screen
@window.wmove r,c
end | [
"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 | [
"move",
"cursor",
"to",
"where",
"the",
"fields",
"row",
"and",
"col",
"are",
"private"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1713-L1719 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.on_leave | def on_leave f
return if f.nil? || !f.focusable # added focusable, else label was firing
f.state = :NORMAL
# on leaving update text_variable if defined. Should happen on modified only
# should this not be f.text_var ... f.buffer ? 2008-11-25 18:58
#f.text_variable.value = f.buffer if !f.text_variable.nil? # 2008-12-20 23:36
f.on_leave if f.respond_to? :on_leave
# 2014-04-24 - 17:42 NO MORE ENTER LEAVE at FORM LEVEL
#fire_handler :LEAVE, f
## to test XXX in combo boxes the box may not be editable by be modified by selection.
if f.respond_to? :editable and f.modified?
$log.debug " Form about to fire CHANGED for #{f} "
f.fire_handler(:CHANGED, f)
end
end | ruby | def on_leave f
return if f.nil? || !f.focusable # added focusable, else label was firing
f.state = :NORMAL
# on leaving update text_variable if defined. Should happen on modified only
# should this not be f.text_var ... f.buffer ? 2008-11-25 18:58
#f.text_variable.value = f.buffer if !f.text_variable.nil? # 2008-12-20 23:36
f.on_leave if f.respond_to? :on_leave
# 2014-04-24 - 17:42 NO MORE ENTER LEAVE at FORM LEVEL
#fire_handler :LEAVE, f
## to test XXX in combo boxes the box may not be editable by be modified by selection.
if f.respond_to? :editable and f.modified?
$log.debug " Form about to fire CHANGED for #{f} "
f.fire_handler(:CHANGED, f)
end
end | [
"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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1765-L1779 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.on_enter | def on_enter f
return if f.nil? || !f.focusable # added focusable, else label was firing 2010-09
f.state = :HIGHLIGHTED
# If the widget has a color defined for focussed, set repaint
# otherwise it will not be repainted unless user edits !
if f.highlight_bgcolor || f.highlight_color
f.repaint_required true
end
f.modified false
#f.set_modified false
f.on_enter if f.respond_to? :on_enter
# 2014-04-24 - 17:42 NO MORE ENTER LEAVE at FORM LEVEL
#fire_handler :ENTER, f
end | ruby | def on_enter f
return if f.nil? || !f.focusable # added focusable, else label was firing 2010-09
f.state = :HIGHLIGHTED
# If the widget has a color defined for focussed, set repaint
# otherwise it will not be repainted unless user edits !
if f.highlight_bgcolor || f.highlight_color
f.repaint_required true
end
f.modified false
#f.set_modified false
f.on_enter if f.respond_to? :on_enter
# 2014-04-24 - 17:42 NO MORE ENTER LEAVE at FORM LEVEL
#fire_handler :ENTER, f
end | [
"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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L1783-L1798 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Form.map_keys | def map_keys
return if @keys_mapped
bind_key(KEY_F1, 'help') { hm = help_manager(); hm.display_help }
bind_keys([?\M-?,?\?], 'show field help') {
#if get_current_field.help_text
#textdialog(get_current_field.help_text, 'title' => 'Help Text', :bgcolor => 'green', :color => :white)
#else
print_key_bindings
#end
}
bind_key(FFI::NCurses::KEY_F9, "Print keys", :print_key_bindings) # show bindings, tentative on F9
bind_key(?\M-:, 'show menu') {
fld = get_current_field
am = fld.action_manager()
#fld.init_menu
am.show_actions
}
@keys_mapped = true
end | ruby | def map_keys
return if @keys_mapped
bind_key(KEY_F1, 'help') { hm = help_manager(); hm.display_help }
bind_keys([?\M-?,?\?], 'show field help') {
#if get_current_field.help_text
#textdialog(get_current_field.help_text, 'title' => 'Help Text', :bgcolor => 'green', :color => :white)
#else
print_key_bindings
#end
}
bind_key(FFI::NCurses::KEY_F9, "Print keys", :print_key_bindings) # show bindings, tentative on F9
bind_key(?\M-:, 'show menu') {
fld = get_current_field
am = fld.action_manager()
#fld.init_menu
am.show_actions
}
@keys_mapped = true
end | [
"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",
"=",
"fld",
".",
"action_manager",
"(",
")",
"am",
".",
"show_actions",
"}",
"@keys_mapped",
"=",
"true",
"end"
]
| These mappings will only trigger if the current field
does not use them. | [
"These",
"mappings",
"will",
"only",
"trigger",
"if",
"the",
"current",
"field",
"does",
"not",
"use",
"them",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L2063-L2081 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Field._set_buffer | def _set_buffer value #:nodoc:
@repaint_required = true
@datatype = value.class
@delete_buffer = @buffer.dup
@buffer = value.to_s.dup
# don't allow setting of value greater than maxlen
@buffer = @buffer[0,@maxlen] if @maxlen && @buffer.length > @maxlen
@curpos = 0
# hope @delete_buffer is not overwritten
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, @delete_buffer) # 2010-09-11 13:01
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :INSERT, 0, @buffer) # 2010-09-11 13:01
self # 2011-10-2
end | ruby | def _set_buffer value #:nodoc:
@repaint_required = true
@datatype = value.class
@delete_buffer = @buffer.dup
@buffer = value.to_s.dup
# don't allow setting of value greater than maxlen
@buffer = @buffer[0,@maxlen] if @maxlen && @buffer.length > @maxlen
@curpos = 0
# hope @delete_buffer is not overwritten
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, @delete_buffer) # 2010-09-11 13:01
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :INSERT, 0, @buffer) # 2010-09-11 13:01
self # 2011-10-2
end | [
"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_buffer",
")",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"@curpos",
",",
"@curpos",
",",
"self",
",",
":INSERT",
",",
"0",
",",
"@buffer",
")",
"self",
"end"
]
| 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 | [
"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"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L2441-L2453 | train |
mare-imbrium/canis | lib/canis/core/widgets/rwidget.rb | Canis.Field.set_label | def set_label label
# added case for user just using a string
case label
when String
# what if no form at this point
@label_unattached = true unless @form
label = Label.new @form, {:text => label}
end
@label = label
# in the case of app it won't be set yet FIXME
# So app sets label to 0 and t his won't trigger
# can this be delayed to when paint happens XXX
if @row
position_label
else
@label_unplaced = true
end
label
end | ruby | def set_label label
# added case for user just using a string
case label
when String
# what if no form at this point
@label_unattached = true unless @form
label = Label.new @form, {:text => label}
end
@label = label
# in the case of app it won't be set yet FIXME
# So app sets label to 0 and t his won't trigger
# can this be delayed to when paint happens XXX
if @row
position_label
else
@label_unplaced = true
end
label
end | [
"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 the label to be printed to the left of the field.
NOTE: 2011-10-20 when field attached to some container, label won't be attached
In such cases, use just +label()+ not +set_label()+.
@param [Label, String] label object to be associated with this field
@return label created which can be further customized.
FIXME this may not work since i have disabled -1, now i do not set row and col 2011-11-5 | [
"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",
"the",
"label",
"to",
"be",
"printed",
"to",
"the",
"left",
"of",
"the",
"field",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rwidget.rb#L2481-L2499 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.