id
int32 0
24.9k
| 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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
23,800 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.model_row | def model_row index
array = @list[index]
array.each_with_index { |c,i|
# if columns added later we could be overwriting the width
ch = get_column(i)
ch.width = c.to_s.length + 2
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new array.size()-1
self
end | ruby | def model_row index
array = @list[index]
array.each_with_index { |c,i|
# if columns added later we could be overwriting the width
ch = get_column(i)
ch.width = c.to_s.length + 2
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new array.size()-1
self
end | [
"def",
"model_row",
"index",
"array",
"=",
"@list",
"[",
"index",
"]",
"array",
".",
"each_with_index",
"{",
"|",
"c",
",",
"i",
"|",
"# if columns added later we could be overwriting the width",
"ch",
"=",
"get_column",
"(",
"i",
")",
"ch",
".",
"width",
"=",
"c",
".",
"to_s",
".",
"length",
"+",
"2",
"}",
"# maintains index in current pointer and gives next or prev",
"@column_pointer",
"=",
"Circular",
".",
"new",
"array",
".",
"size",
"(",
")",
"-",
"1",
"self",
"end"
] | size each column based on widths of this row of data. | [
"size",
"each",
"column",
"based",
"on",
"widths",
"of",
"this",
"row",
"of",
"data",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L661-L671 |
23,801 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.save_as | def save_as outfile
_t = "(all rows)"
if @selected_indices.size > 0
_t = "(selected rows)"
end
unless outfile
outfile = get_string "Enter file name to save #{_t} as "
return unless outfile
end
# if there is a selection, then write only selected rows
l = nil
if @selected_indices.size > 0
l = []
@list.each_with_index { |v,i| l << v if @selected_indices.include? i }
else
l = @list
end
File.open(outfile, 'w') {|f|
l.each {|r|
line = r.join "\t"
f.puts line
}
}
end | ruby | def save_as outfile
_t = "(all rows)"
if @selected_indices.size > 0
_t = "(selected rows)"
end
unless outfile
outfile = get_string "Enter file name to save #{_t} as "
return unless outfile
end
# if there is a selection, then write only selected rows
l = nil
if @selected_indices.size > 0
l = []
@list.each_with_index { |v,i| l << v if @selected_indices.include? i }
else
l = @list
end
File.open(outfile, 'w') {|f|
l.each {|r|
line = r.join "\t"
f.puts line
}
}
end | [
"def",
"save_as",
"outfile",
"_t",
"=",
"\"(all rows)\"",
"if",
"@selected_indices",
".",
"size",
">",
"0",
"_t",
"=",
"\"(selected rows)\"",
"end",
"unless",
"outfile",
"outfile",
"=",
"get_string",
"\"Enter file name to save #{_t} as \"",
"return",
"unless",
"outfile",
"end",
"# if there is a selection, then write only selected rows",
"l",
"=",
"nil",
"if",
"@selected_indices",
".",
"size",
">",
"0",
"l",
"=",
"[",
"]",
"@list",
".",
"each_with_index",
"{",
"|",
"v",
",",
"i",
"|",
"l",
"<<",
"v",
"if",
"@selected_indices",
".",
"include?",
"i",
"}",
"else",
"l",
"=",
"@list",
"end",
"File",
".",
"open",
"(",
"outfile",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"l",
".",
"each",
"{",
"|",
"r",
"|",
"line",
"=",
"r",
".",
"join",
"\"\\t\"",
"f",
".",
"puts",
"line",
"}",
"}",
"end"
] | save the table as a file
@param String name of output file. If nil, user is prompted
Currently, tabs are used as delimiter, but this could be based on input
separator, or prompted. | [
"save",
"the",
"table",
"as",
"a",
"file"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L768-L793 |
23,802 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.delete_at | def delete_at ix
return unless @list
raise ArgumentError, "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list.length
fire_dimension_changed
#@list.delete_at(ix + @_header_adjustment)
@list.delete_at(ix)
end | ruby | def delete_at ix
return unless @list
raise ArgumentError, "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list.length
fire_dimension_changed
#@list.delete_at(ix + @_header_adjustment)
@list.delete_at(ix)
end | [
"def",
"delete_at",
"ix",
"return",
"unless",
"@list",
"raise",
"ArgumentError",
",",
"\"Argument must be within 0 and #{@list.length}\"",
"if",
"ix",
"<",
"0",
"or",
"ix",
">=",
"@list",
".",
"length",
"fire_dimension_changed",
"#@list.delete_at(ix + @_header_adjustment)",
"@list",
".",
"delete_at",
"(",
"ix",
")",
"end"
] | delete a data row at index
NOTE : This does not adjust for header_adjustment. So zero will refer to the header if there is one.
This is to keep consistent with textpad which does not know of header_adjustment and uses the actual
index. Usually, programmers will be dealing with +@current_index+ | [
"delete",
"a",
"data",
"row",
"at",
"index"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L816-L822 |
23,803 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.set_value_at | def set_value_at row,col,val
actrow = row + @_header_adjustment
@list[actrow , col] = val
fire_row_changed actrow
self
end | ruby | def set_value_at row,col,val
actrow = row + @_header_adjustment
@list[actrow , col] = val
fire_row_changed actrow
self
end | [
"def",
"set_value_at",
"row",
",",
"col",
",",
"val",
"actrow",
"=",
"row",
"+",
"@_header_adjustment",
"@list",
"[",
"actrow",
",",
"col",
"]",
"=",
"val",
"fire_row_changed",
"actrow",
"self",
"end"
] | set value at the cell at row and col
@param int row
@param int col
@param String value
@return self | [
"set",
"value",
"at",
"the",
"cell",
"at",
"row",
"and",
"col"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L842-L847 |
23,804 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.move_column | def move_column ix, newix
acol = @chash.delete_at ix
@chash.insert newix, acol
_invalidate_width_cache
#tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE)
#fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce
end | ruby | def move_column ix, newix
acol = @chash.delete_at ix
@chash.insert newix, acol
_invalidate_width_cache
#tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE)
#fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce
end | [
"def",
"move_column",
"ix",
",",
"newix",
"acol",
"=",
"@chash",
".",
"delete_at",
"ix",
"@chash",
".",
"insert",
"newix",
",",
"acol",
"_invalidate_width_cache",
"#tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE)",
"#fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce",
"end"
] | should all this move into table column model or somepn
move a column from offset ix to offset newix | [
"should",
"all",
"this",
"move",
"into",
"table",
"column",
"model",
"or",
"somepn",
"move",
"a",
"column",
"from",
"offset",
"ix",
"to",
"offset",
"newix"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L879-L885 |
23,805 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.fire_action_event | def fire_action_event
if header_row?
if @table_row_sorter
x = _convert_curpos_to_column
c = @chash[x]
# convert to index in data model since sorter only has data_model
index = c.index
@table_row_sorter.toggle_sort_order index
@table_row_sorter.sort
fire_dimension_changed
end
end
super
end | ruby | def fire_action_event
if header_row?
if @table_row_sorter
x = _convert_curpos_to_column
c = @chash[x]
# convert to index in data model since sorter only has data_model
index = c.index
@table_row_sorter.toggle_sort_order index
@table_row_sorter.sort
fire_dimension_changed
end
end
super
end | [
"def",
"fire_action_event",
"if",
"header_row?",
"if",
"@table_row_sorter",
"x",
"=",
"_convert_curpos_to_column",
"c",
"=",
"@chash",
"[",
"x",
"]",
"# convert to index in data model since sorter only has data_model",
"index",
"=",
"c",
".",
"index",
"@table_row_sorter",
".",
"toggle_sort_order",
"index",
"@table_row_sorter",
".",
"sort",
"fire_dimension_changed",
"end",
"end",
"super",
"end"
] | called when ENTER is pressed.
Takes into account if user is on header_row | [
"called",
"when",
"ENTER",
"is",
"pressed",
".",
"Takes",
"into",
"account",
"if",
"user",
"is",
"on",
"header_row"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L961-L974 |
23,806 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.matching_indices | def matching_indices
raise "block required for matching_indices" unless block_given?
@indices = []
## content can be string or Chunkline, so we had to write <tt>index</tt> for this.
@list.each_with_index do |fields, ix|
flag = yield ix, fields
if flag
@indices << ix
end
end
#$log.debug "XXX: INDICES found #{@indices}"
if @indices.count > 0
fire_dimension_changed
init_vars
else
@indices = nil
end
#return @indices
end | ruby | def matching_indices
raise "block required for matching_indices" unless block_given?
@indices = []
## content can be string or Chunkline, so we had to write <tt>index</tt> for this.
@list.each_with_index do |fields, ix|
flag = yield ix, fields
if flag
@indices << ix
end
end
#$log.debug "XXX: INDICES found #{@indices}"
if @indices.count > 0
fire_dimension_changed
init_vars
else
@indices = nil
end
#return @indices
end | [
"def",
"matching_indices",
"raise",
"\"block required for matching_indices\"",
"unless",
"block_given?",
"@indices",
"=",
"[",
"]",
"## content can be string or Chunkline, so we had to write <tt>index</tt> for this.",
"@list",
".",
"each_with_index",
"do",
"|",
"fields",
",",
"ix",
"|",
"flag",
"=",
"yield",
"ix",
",",
"fields",
"if",
"flag",
"@indices",
"<<",
"ix",
"end",
"end",
"#$log.debug \"XXX: INDICES found #{@indices}\"",
"if",
"@indices",
".",
"count",
">",
"0",
"fire_dimension_changed",
"init_vars",
"else",
"@indices",
"=",
"nil",
"end",
"#return @indices",
"end"
] | yields each column to caller method
if yield returns true, collects index of row into array and returns the array
@returns array of indices which can be empty
Value yielded can be fixnum or date etc | [
"yields",
"each",
"column",
"to",
"caller",
"method",
"if",
"yield",
"returns",
"true",
"collects",
"index",
"of",
"row",
"into",
"array",
"and",
"returns",
"the",
"array"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L1013-L1031 |
23,807 | mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.render_all | def render_all
if @indices && @indices.count > 0
@indices.each_with_index do |ix, jx|
render @pad, jx, @list[ix]
end
else
@list.each_with_index { |line, ix|
# FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix].to_s)
render @pad, ix, line
}
end
end | ruby | def render_all
if @indices && @indices.count > 0
@indices.each_with_index do |ix, jx|
render @pad, jx, @list[ix]
end
else
@list.each_with_index { |line, ix|
# FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix].to_s)
render @pad, ix, line
}
end
end | [
"def",
"render_all",
"if",
"@indices",
"&&",
"@indices",
".",
"count",
">",
"0",
"@indices",
".",
"each_with_index",
"do",
"|",
"ix",
",",
"jx",
"|",
"render",
"@pad",
",",
"jx",
",",
"@list",
"[",
"ix",
"]",
"end",
"else",
"@list",
".",
"each_with_index",
"{",
"|",
"line",
",",
"ix",
"|",
"# FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix].to_s)",
"render",
"@pad",
",",
"ix",
",",
"line",
"}",
"end",
"end"
] | calls the renderer for all rows of data giving them pad, lineno, and line data | [
"calls",
"the",
"renderer",
"for",
"all",
"rows",
"of",
"data",
"giving",
"them",
"pad",
"lineno",
"and",
"line",
"data"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L1061-L1072 |
23,808 | osiro/enceladus | lib/enceladus/configuration/image.rb | Enceladus::Configuration.Image.reset! | def reset!
self.base_url = nil
self.secure_base_url = nil
self.backdrop_sizes = []
self.logo_sizes = []
self.logo_sizes = []
self.poster_sizes = []
self.profile_sizes = []
self.still_sizes = []
self.include_image_language = "en"
self
end | ruby | def reset!
self.base_url = nil
self.secure_base_url = nil
self.backdrop_sizes = []
self.logo_sizes = []
self.logo_sizes = []
self.poster_sizes = []
self.profile_sizes = []
self.still_sizes = []
self.include_image_language = "en"
self
end | [
"def",
"reset!",
"self",
".",
"base_url",
"=",
"nil",
"self",
".",
"secure_base_url",
"=",
"nil",
"self",
".",
"backdrop_sizes",
"=",
"[",
"]",
"self",
".",
"logo_sizes",
"=",
"[",
"]",
"self",
".",
"logo_sizes",
"=",
"[",
"]",
"self",
".",
"poster_sizes",
"=",
"[",
"]",
"self",
".",
"profile_sizes",
"=",
"[",
"]",
"self",
".",
"still_sizes",
"=",
"[",
"]",
"self",
".",
"include_image_language",
"=",
"\"en\"",
"self",
"end"
] | Reset or nullify all image configurations. | [
"Reset",
"or",
"nullify",
"all",
"image",
"configurations",
"."
] | 874a8f0ad55bf3528e3e193b298967f0997d66b3 | https://github.com/osiro/enceladus/blob/874a8f0ad55bf3528e3e193b298967f0997d66b3/lib/enceladus/configuration/image.rb#L32-L43 |
23,809 | osiro/enceladus | lib/enceladus/configuration/image.rb | Enceladus::Configuration.Image.valid? | def valid?
!base_url.nil? &&
!secure_base_url.nil? &&
backdrop_sizes.any? &&
logo_sizes.any? &&
poster_sizes.any? &&
profile_sizes.any? &&
still_sizes.any?
end | ruby | def valid?
!base_url.nil? &&
!secure_base_url.nil? &&
backdrop_sizes.any? &&
logo_sizes.any? &&
poster_sizes.any? &&
profile_sizes.any? &&
still_sizes.any?
end | [
"def",
"valid?",
"!",
"base_url",
".",
"nil?",
"&&",
"!",
"secure_base_url",
".",
"nil?",
"&&",
"backdrop_sizes",
".",
"any?",
"&&",
"logo_sizes",
".",
"any?",
"&&",
"poster_sizes",
".",
"any?",
"&&",
"profile_sizes",
".",
"any?",
"&&",
"still_sizes",
".",
"any?",
"end"
] | Returns a boolean indicating whether the Image configurations are valid or not. | [
"Returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"Image",
"configurations",
"are",
"valid",
"or",
"not",
"."
] | 874a8f0ad55bf3528e3e193b298967f0997d66b3 | https://github.com/osiro/enceladus/blob/874a8f0ad55bf3528e3e193b298967f0997d66b3/lib/enceladus/configuration/image.rb#L71-L79 |
23,810 | RestlessThinker/danger-pronto | lib/danger_pronto/plugin.rb | Danger.DangerPronto.lint | def lint(commit = nil)
files = pronto(commit)
return if files.empty?
markdown offenses_message(files)
end | ruby | def lint(commit = nil)
files = pronto(commit)
return if files.empty?
markdown offenses_message(files)
end | [
"def",
"lint",
"(",
"commit",
"=",
"nil",
")",
"files",
"=",
"pronto",
"(",
"commit",
")",
"return",
"if",
"files",
".",
"empty?",
"markdown",
"offenses_message",
"(",
"files",
")",
"end"
] | Runs files through Pronto. Generates a `markdown` list of warnings. | [
"Runs",
"files",
"through",
"Pronto",
".",
"Generates",
"a",
"markdown",
"list",
"of",
"warnings",
"."
] | 452f1565ea75f91f358c6ceed1ad06a3b794a7d4 | https://github.com/RestlessThinker/danger-pronto/blob/452f1565ea75f91f358c6ceed1ad06a3b794a7d4/lib/danger_pronto/plugin.rb#L17-L22 |
23,811 | CocoaPods/Cork | lib/cork/board.rb | Cork.Board.path | def path(pathname, relative_to = Pathname.pwd)
if pathname
path = Pathname(pathname).relative_path_from(relative_to)
"`#{path}`"
else
''
end
end | ruby | def path(pathname, relative_to = Pathname.pwd)
if pathname
path = Pathname(pathname).relative_path_from(relative_to)
"`#{path}`"
else
''
end
end | [
"def",
"path",
"(",
"pathname",
",",
"relative_to",
"=",
"Pathname",
".",
"pwd",
")",
"if",
"pathname",
"path",
"=",
"Pathname",
"(",
"pathname",
")",
".",
"relative_path_from",
"(",
"relative_to",
")",
"\"`#{path}`\"",
"else",
"''",
"end",
"end"
] | The returned path is quoted. If the argument is nil it returns an empty
string.
@param [#to_str,Nil] pathname
The path to return.
@param [Pathname] relative_to | [
"The",
"returned",
"path",
"is",
"quoted",
".",
"If",
"the",
"argument",
"is",
"nil",
"it",
"returns",
"an",
"empty",
"string",
"."
] | 4ce915065174ac7985e9b229072d4ac304d00839 | https://github.com/CocoaPods/Cork/blob/4ce915065174ac7985e9b229072d4ac304d00839/lib/cork/board.rb#L117-L124 |
23,812 | CocoaPods/Cork | lib/cork/board.rb | Cork.Board.labeled | def labeled(label, value, justification = 12)
if value
title = "- #{label}:"
if value.is_a?(Enumerable)
lines = [wrap_string(title, indentation_level)]
lines += value.map do |v|
wrap_string("- #{v}", indentation_level + 2)
end
puts lines.join("\n")
else
string = title.ljust(justification) + "#{value}"
puts wrap_string(string, indentation_level)
end
end
end | ruby | def labeled(label, value, justification = 12)
if value
title = "- #{label}:"
if value.is_a?(Enumerable)
lines = [wrap_string(title, indentation_level)]
lines += value.map do |v|
wrap_string("- #{v}", indentation_level + 2)
end
puts lines.join("\n")
else
string = title.ljust(justification) + "#{value}"
puts wrap_string(string, indentation_level)
end
end
end | [
"def",
"labeled",
"(",
"label",
",",
"value",
",",
"justification",
"=",
"12",
")",
"if",
"value",
"title",
"=",
"\"- #{label}:\"",
"if",
"value",
".",
"is_a?",
"(",
"Enumerable",
")",
"lines",
"=",
"[",
"wrap_string",
"(",
"title",
",",
"indentation_level",
")",
"]",
"lines",
"+=",
"value",
".",
"map",
"do",
"|",
"v",
"|",
"wrap_string",
"(",
"\"- #{v}\"",
",",
"indentation_level",
"+",
"2",
")",
"end",
"puts",
"lines",
".",
"join",
"(",
"\"\\n\"",
")",
"else",
"string",
"=",
"title",
".",
"ljust",
"(",
"justification",
")",
"+",
"\"#{value}\"",
"puts",
"wrap_string",
"(",
"string",
",",
"indentation_level",
")",
"end",
"end",
"end"
] | Prints a message with a label.
@param [String] label
The label to print.
@param [#to_s] value
The value to print.
@param [FixNum] justification
The justification of the label. | [
"Prints",
"a",
"message",
"with",
"a",
"label",
"."
] | 4ce915065174ac7985e9b229072d4ac304d00839 | https://github.com/CocoaPods/Cork/blob/4ce915065174ac7985e9b229072d4ac304d00839/lib/cork/board.rb#L137-L151 |
23,813 | CocoaPods/Cork | lib/cork/board.rb | Cork.Board.info | def info(message)
indentation = verbose? ? @indentation_level : 0
indented = wrap_string(message, indentation)
puts(indented)
if block_given?
@indentation_level += 2
@treat_titles_as_messages = true
yield
@treat_titles_as_messages = false
@indentation_level -= 2
end
end | ruby | def info(message)
indentation = verbose? ? @indentation_level : 0
indented = wrap_string(message, indentation)
puts(indented)
if block_given?
@indentation_level += 2
@treat_titles_as_messages = true
yield
@treat_titles_as_messages = false
@indentation_level -= 2
end
end | [
"def",
"info",
"(",
"message",
")",
"indentation",
"=",
"verbose?",
"?",
"@indentation_level",
":",
"0",
"indented",
"=",
"wrap_string",
"(",
"message",
",",
"indentation",
")",
"puts",
"(",
"indented",
")",
"if",
"block_given?",
"@indentation_level",
"+=",
"2",
"@treat_titles_as_messages",
"=",
"true",
"yield",
"@treat_titles_as_messages",
"=",
"false",
"@indentation_level",
"-=",
"2",
"end",
"end"
] | Prints an info to the user. The info is always displayed.
It respects the current indentation level only in verbose
mode.
Any title printed in the optional block is treated as a message.
@param [String] message
The message to print. | [
"Prints",
"an",
"info",
"to",
"the",
"user",
".",
"The",
"info",
"is",
"always",
"displayed",
".",
"It",
"respects",
"the",
"current",
"indentation",
"level",
"only",
"in",
"verbose",
"mode",
"."
] | 4ce915065174ac7985e9b229072d4ac304d00839 | https://github.com/CocoaPods/Cork/blob/4ce915065174ac7985e9b229072d4ac304d00839/lib/cork/board.rb#L198-L210 |
23,814 | CocoaPods/Cork | lib/cork/board.rb | Cork.Board.title | def title(title, verbose_prefix = '', relative_indentation = 2)
if @treat_titles_as_messages
message(title, verbose_prefix)
else
puts_title(title, verbose_prefix)
end
if block_given?
@indentation_level += relative_indentation
@title_level += 1
yield
@indentation_level -= relative_indentation
@title_level -= 1
end
end | ruby | def title(title, verbose_prefix = '', relative_indentation = 2)
if @treat_titles_as_messages
message(title, verbose_prefix)
else
puts_title(title, verbose_prefix)
end
if block_given?
@indentation_level += relative_indentation
@title_level += 1
yield
@indentation_level -= relative_indentation
@title_level -= 1
end
end | [
"def",
"title",
"(",
"title",
",",
"verbose_prefix",
"=",
"''",
",",
"relative_indentation",
"=",
"2",
")",
"if",
"@treat_titles_as_messages",
"message",
"(",
"title",
",",
"verbose_prefix",
")",
"else",
"puts_title",
"(",
"title",
",",
"verbose_prefix",
")",
"end",
"if",
"block_given?",
"@indentation_level",
"+=",
"relative_indentation",
"@title_level",
"+=",
"1",
"yield",
"@indentation_level",
"-=",
"relative_indentation",
"@title_level",
"-=",
"1",
"end",
"end"
] | A title opposed to a section is always visible
@param [String] title
The title to print
@param [String] verbose_prefix
See #message
@param [FixNum] relative_indentation
The indentation level relative to the current,
when the message is printed. | [
"A",
"title",
"opposed",
"to",
"a",
"section",
"is",
"always",
"visible"
] | 4ce915065174ac7985e9b229072d4ac304d00839 | https://github.com/CocoaPods/Cork/blob/4ce915065174ac7985e9b229072d4ac304d00839/lib/cork/board.rb#L224-L238 |
23,815 | CocoaPods/Cork | lib/cork/board.rb | Cork.Board.message | def message(message, verbose_prefix = '', relative_indentation = 2)
message = verbose_prefix + message if verbose?
puts_indented message if verbose?
@indentation_level += relative_indentation
yield if block_given?
@indentation_level -= relative_indentation
end | ruby | def message(message, verbose_prefix = '', relative_indentation = 2)
message = verbose_prefix + message if verbose?
puts_indented message if verbose?
@indentation_level += relative_indentation
yield if block_given?
@indentation_level -= relative_indentation
end | [
"def",
"message",
"(",
"message",
",",
"verbose_prefix",
"=",
"''",
",",
"relative_indentation",
"=",
"2",
")",
"message",
"=",
"verbose_prefix",
"+",
"message",
"if",
"verbose?",
"puts_indented",
"message",
"if",
"verbose?",
"@indentation_level",
"+=",
"relative_indentation",
"yield",
"if",
"block_given?",
"@indentation_level",
"-=",
"relative_indentation",
"end"
] | Prints a verbose message taking an optional verbose prefix and
a relative indentation valid for the UI action in the passed
block.
@todo Clean interface. | [
"Prints",
"a",
"verbose",
"message",
"taking",
"an",
"optional",
"verbose",
"prefix",
"and",
"a",
"relative",
"indentation",
"valid",
"for",
"the",
"UI",
"action",
"in",
"the",
"passed",
"block",
"."
] | 4ce915065174ac7985e9b229072d4ac304d00839 | https://github.com/CocoaPods/Cork/blob/4ce915065174ac7985e9b229072d4ac304d00839/lib/cork/board.rb#L290-L297 |
23,816 | mare-imbrium/canis | lib/canis/core/widgets/rcontainer.rb | Canis.Container.correct_component | def correct_component c
raise "Form is still not set in Container" unless @form
attach_form(c) unless c.form
@last_row ||= @row + 1
inset = 2
# 2011-10-20 current default behaviour is to stack
if @positioning == :stack
c.row = @last_row
c.col = @col + inset
# do not advance row, save col for next row
@last_row += 1
elsif @positioning == :relative # UNTESTED NOTE
if (c.row || 0) <= 0
$log.warn "c.row in CONTAINER is #{c.row} "
c.row = @last_row
@last_row += 1
elsif c.row > @row + @height -1
$log.warn "c.row in CONTAINER exceeds container. #{c.row} "
c.row -= @height - @row_offset
else
# this is where it should come
c.row += @row + @row_offset
@last_row = c.row + 1
end
if (c.col || 0) <= 0
c.col = @col + inset + @col_offset
elsif c.col > @col + @width -1
c.col -= @width
elsif c.col == @col
c.col += @col_offset + inset
else #f c.col < @col
c.col += @col+@col_offset
end
$log.debug "XXX: CORRECT #{c.name} r:#{c.row} c:#{c.col} "
end
@first_time = false
end | ruby | def correct_component c
raise "Form is still not set in Container" unless @form
attach_form(c) unless c.form
@last_row ||= @row + 1
inset = 2
# 2011-10-20 current default behaviour is to stack
if @positioning == :stack
c.row = @last_row
c.col = @col + inset
# do not advance row, save col for next row
@last_row += 1
elsif @positioning == :relative # UNTESTED NOTE
if (c.row || 0) <= 0
$log.warn "c.row in CONTAINER is #{c.row} "
c.row = @last_row
@last_row += 1
elsif c.row > @row + @height -1
$log.warn "c.row in CONTAINER exceeds container. #{c.row} "
c.row -= @height - @row_offset
else
# this is where it should come
c.row += @row + @row_offset
@last_row = c.row + 1
end
if (c.col || 0) <= 0
c.col = @col + inset + @col_offset
elsif c.col > @col + @width -1
c.col -= @width
elsif c.col == @col
c.col += @col_offset + inset
else #f c.col < @col
c.col += @col+@col_offset
end
$log.debug "XXX: CORRECT #{c.name} r:#{c.row} c:#{c.col} "
end
@first_time = false
end | [
"def",
"correct_component",
"c",
"raise",
"\"Form is still not set in Container\"",
"unless",
"@form",
"attach_form",
"(",
"c",
")",
"unless",
"c",
".",
"form",
"@last_row",
"||=",
"@row",
"+",
"1",
"inset",
"=",
"2",
"# 2011-10-20 current default behaviour is to stack",
"if",
"@positioning",
"==",
":stack",
"c",
".",
"row",
"=",
"@last_row",
"c",
".",
"col",
"=",
"@col",
"+",
"inset",
"# do not advance row, save col for next row",
"@last_row",
"+=",
"1",
"elsif",
"@positioning",
"==",
":relative",
"# UNTESTED NOTE",
"if",
"(",
"c",
".",
"row",
"||",
"0",
")",
"<=",
"0",
"$log",
".",
"warn",
"\"c.row in CONTAINER is #{c.row} \"",
"c",
".",
"row",
"=",
"@last_row",
"@last_row",
"+=",
"1",
"elsif",
"c",
".",
"row",
">",
"@row",
"+",
"@height",
"-",
"1",
"$log",
".",
"warn",
"\"c.row in CONTAINER exceeds container. #{c.row} \"",
"c",
".",
"row",
"-=",
"@height",
"-",
"@row_offset",
"else",
"# this is where it should come",
"c",
".",
"row",
"+=",
"@row",
"+",
"@row_offset",
"@last_row",
"=",
"c",
".",
"row",
"+",
"1",
"end",
"if",
"(",
"c",
".",
"col",
"||",
"0",
")",
"<=",
"0",
"c",
".",
"col",
"=",
"@col",
"+",
"inset",
"+",
"@col_offset",
"elsif",
"c",
".",
"col",
">",
"@col",
"+",
"@width",
"-",
"1",
"c",
".",
"col",
"-=",
"@width",
"elsif",
"c",
".",
"col",
"==",
"@col",
"c",
".",
"col",
"+=",
"@col_offset",
"+",
"inset",
"else",
"#f c.col < @col",
"c",
".",
"col",
"+=",
"@col",
"+",
"@col_offset",
"end",
"$log",
".",
"debug",
"\"XXX: CORRECT #{c.name} r:#{c.row} c:#{c.col} \"",
"end",
"@first_time",
"=",
"false",
"end"
] | what of by_name
correct coordinates of comp esp if App has stacked them after this
container
It is best to use the simple stack feature. The rest could change at any time
and is quite arbitrary. Some folks may set absolute locations if container
is directly on a form, others may set relative locations if it is inside a
tabbed pane or other container. Thus, stacks are best | [
"what",
"of",
"by_name",
"correct",
"coordinates",
"of",
"comp",
"esp",
"if",
"App",
"has",
"stacked",
"them",
"after",
"this",
"container",
"It",
"is",
"best",
"to",
"use",
"the",
"simple",
"stack",
"feature",
".",
"The",
"rest",
"could",
"change",
"at",
"any",
"time",
"and",
"is",
"quite",
"arbitrary",
".",
"Some",
"folks",
"may",
"set",
"absolute",
"locations",
"if",
"container",
"is",
"directly",
"on",
"a",
"form",
"others",
"may",
"set",
"relative",
"locations",
"if",
"it",
"is",
"inside",
"a",
"tabbed",
"pane",
"or",
"other",
"container",
".",
"Thus",
"stacks",
"are",
"best"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rcontainer.rb#L125-L162 |
23,817 | awilliams/RTanque | lib/rtanque/runner.rb | RTanque.Runner.start | def start(gui = true)
if gui
require 'rtanque/gui'
window = RTanque::Gui::Window.new(self.match)
trap(:INT) { window.close }
window.show
else
trap(:INT) { self.match.stop }
self.match.start
end
end | ruby | def start(gui = true)
if gui
require 'rtanque/gui'
window = RTanque::Gui::Window.new(self.match)
trap(:INT) { window.close }
window.show
else
trap(:INT) { self.match.stop }
self.match.start
end
end | [
"def",
"start",
"(",
"gui",
"=",
"true",
")",
"if",
"gui",
"require",
"'rtanque/gui'",
"window",
"=",
"RTanque",
"::",
"Gui",
"::",
"Window",
".",
"new",
"(",
"self",
".",
"match",
")",
"trap",
"(",
":INT",
")",
"{",
"window",
".",
"close",
"}",
"window",
".",
"show",
"else",
"trap",
"(",
":INT",
")",
"{",
"self",
".",
"match",
".",
"stop",
"}",
"self",
".",
"match",
".",
"start",
"end",
"end"
] | Starts the match
@param [Boolean] gui if false, runs headless match | [
"Starts",
"the",
"match"
] | a184cfbbbc259a88b40c900f3f90d8dcbcfe348e | https://github.com/awilliams/RTanque/blob/a184cfbbbc259a88b40c900f3f90d8dcbcfe348e/lib/rtanque/runner.rb#L30-L40 |
23,818 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App.loop | def loop &block
@form.repaint
@window.wrefresh
Ncurses::Panel.update_panels
@break_key = ?\C-q.getbyte(0)
# added this extra loop since from some places we exit using throw :close
# amd that was in a much higher place, and was getting us right out, with
# no chance of user canceling quit. This extra loop allows us to remain
# added on 2011-11-24
while true
catch :close do
while((ch = @window.getchar()) != 999 )
if ch == @break_key || ch == @quit_key
break
end
# 2014-08-19 - 22:51 commented next line, too much choice. keep it simple. delete in a month FIXME
#yield ch if block # <<<----
# this is what the user should have control ove. earlier we would put this in
# a try catch block so user could do what he wanted with the error. Now we
# need to get it to him somehow, perhaps through a block or on_error event
begin
# execute a code block so caller program can handle keys from a hash or whatever.
# NOTE: these keys will not appear in help
# FIXME : ideally if its just a hash, we should allow user to give it to form
# or widget which it will use, or merge, and be able to print help from
if @keyblock
str = keycode_tos ch
# why did we ever want to convert to a symbol. why not just pass it as is.
#@keyblock.call(str.gsub(/-/, "_").to_sym) # not used ever
ret = @keyblock.call(str)
if ret
@form.repaint
next
end
end
@form.handle_key ch
rescue => err
$log.debug( "app.rb handle_key rescue reached ")
$log.debug( err.to_s)
$log.debug(err.backtrace.join("\n"))
textdialog [err.to_s, *err.backtrace], :title => "Exception"
end
@window.wrefresh
end
end # catch
stopping = @window.fire_close_handler
@window.wrefresh
break if stopping.nil? || stopping
end # while
end | ruby | def loop &block
@form.repaint
@window.wrefresh
Ncurses::Panel.update_panels
@break_key = ?\C-q.getbyte(0)
# added this extra loop since from some places we exit using throw :close
# amd that was in a much higher place, and was getting us right out, with
# no chance of user canceling quit. This extra loop allows us to remain
# added on 2011-11-24
while true
catch :close do
while((ch = @window.getchar()) != 999 )
if ch == @break_key || ch == @quit_key
break
end
# 2014-08-19 - 22:51 commented next line, too much choice. keep it simple. delete in a month FIXME
#yield ch if block # <<<----
# this is what the user should have control ove. earlier we would put this in
# a try catch block so user could do what he wanted with the error. Now we
# need to get it to him somehow, perhaps through a block or on_error event
begin
# execute a code block so caller program can handle keys from a hash or whatever.
# NOTE: these keys will not appear in help
# FIXME : ideally if its just a hash, we should allow user to give it to form
# or widget which it will use, or merge, and be able to print help from
if @keyblock
str = keycode_tos ch
# why did we ever want to convert to a symbol. why not just pass it as is.
#@keyblock.call(str.gsub(/-/, "_").to_sym) # not used ever
ret = @keyblock.call(str)
if ret
@form.repaint
next
end
end
@form.handle_key ch
rescue => err
$log.debug( "app.rb handle_key rescue reached ")
$log.debug( err.to_s)
$log.debug(err.backtrace.join("\n"))
textdialog [err.to_s, *err.backtrace], :title => "Exception"
end
@window.wrefresh
end
end # catch
stopping = @window.fire_close_handler
@window.wrefresh
break if stopping.nil? || stopping
end # while
end | [
"def",
"loop",
"&",
"block",
"@form",
".",
"repaint",
"@window",
".",
"wrefresh",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"@break_key",
"=",
"?\\C-q",
".",
"getbyte",
"(",
"0",
")",
"# added this extra loop since from some places we exit using throw :close",
"# amd that was in a much higher place, and was getting us right out, with",
"# no chance of user canceling quit. This extra loop allows us to remain",
"# added on 2011-11-24 ",
"while",
"true",
"catch",
":close",
"do",
"while",
"(",
"(",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
")",
"!=",
"999",
")",
"if",
"ch",
"==",
"@break_key",
"||",
"ch",
"==",
"@quit_key",
"break",
"end",
"# 2014-08-19 - 22:51 commented next line, too much choice. keep it simple. delete in a month FIXME",
"#yield ch if block # <<<----",
"# this is what the user should have control ove. earlier we would put this in",
"# a try catch block so user could do what he wanted with the error. Now we",
"# need to get it to him somehow, perhaps through a block or on_error event",
"begin",
"# execute a code block so caller program can handle keys from a hash or whatever.",
"# NOTE: these keys will not appear in help",
"# FIXME : ideally if its just a hash, we should allow user to give it to form",
"# or widget which it will use, or merge, and be able to print help from",
"if",
"@keyblock",
"str",
"=",
"keycode_tos",
"ch",
"# why did we ever want to convert to a symbol. why not just pass it as is.",
"#@keyblock.call(str.gsub(/-/, \"_\").to_sym) # not used ever",
"ret",
"=",
"@keyblock",
".",
"call",
"(",
"str",
")",
"if",
"ret",
"@form",
".",
"repaint",
"next",
"end",
"end",
"@form",
".",
"handle_key",
"ch",
"rescue",
"=>",
"err",
"$log",
".",
"debug",
"(",
"\"app.rb handle_key rescue reached \"",
")",
"$log",
".",
"debug",
"(",
"err",
".",
"to_s",
")",
"$log",
".",
"debug",
"(",
"err",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"textdialog",
"[",
"err",
".",
"to_s",
",",
"err",
".",
"backtrace",
"]",
",",
":title",
"=>",
"\"Exception\"",
"end",
"@window",
".",
"wrefresh",
"end",
"end",
"# catch",
"stopping",
"=",
"@window",
".",
"fire_close_handler",
"@window",
".",
"wrefresh",
"break",
"if",
"stopping",
".",
"nil?",
"||",
"stopping",
"end",
"# while",
"end"
] | This method is called by run, and thus in most cases this is what is used.
+run+ calls this without a block
not sure, but user shuld be able to trap keystrokes if he wants
but do i still call handle_key if he does, or give him total control.
But loop is already called by framework | [
"This",
"method",
"is",
"called",
"by",
"run",
"and",
"thus",
"in",
"most",
"cases",
"this",
"is",
"what",
"is",
"used",
".",
"+",
"run",
"+",
"calls",
"this",
"without",
"a",
"block",
"not",
"sure",
"but",
"user",
"shuld",
"be",
"able",
"to",
"trap",
"keystrokes",
"if",
"he",
"wants",
"but",
"do",
"i",
"still",
"call",
"handle_key",
"if",
"he",
"does",
"or",
"give",
"him",
"total",
"control",
".",
"But",
"loop",
"is",
"already",
"called",
"by",
"framework"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L129-L181 |
23,819 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App.safe_loop | def safe_loop &block
begin
loop &block
rescue => ex
$log.debug( "APP.rb rescue reached ")
$log.debug( ex) if ex
$log.debug(ex.backtrace.join("\n")) if ex
ensure
close
# putting it here allows it to be printed on screen, otherwise it was not showing at all.
if ex
puts "========== EXCEPTION =========="
p ex
puts "==============================="
puts(ex.backtrace.join("\n"))
end
end
end | ruby | def safe_loop &block
begin
loop &block
rescue => ex
$log.debug( "APP.rb rescue reached ")
$log.debug( ex) if ex
$log.debug(ex.backtrace.join("\n")) if ex
ensure
close
# putting it here allows it to be printed on screen, otherwise it was not showing at all.
if ex
puts "========== EXCEPTION =========="
p ex
puts "==============================="
puts(ex.backtrace.join("\n"))
end
end
end | [
"def",
"safe_loop",
"&",
"block",
"begin",
"loop",
"block",
"rescue",
"=>",
"ex",
"$log",
".",
"debug",
"(",
"\"APP.rb rescue reached \"",
")",
"$log",
".",
"debug",
"(",
"ex",
")",
"if",
"ex",
"$log",
".",
"debug",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"if",
"ex",
"ensure",
"close",
"# putting it here allows it to be printed on screen, otherwise it was not showing at all.",
"if",
"ex",
"puts",
"\"========== EXCEPTION ==========\"",
"p",
"ex",
"puts",
"\"===============================\"",
"puts",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end",
"end"
] | if calling loop separately better to call this, since it will shut off ncurses
and print error on screen.
UNUSED | [
"if",
"calling",
"loop",
"separately",
"better",
"to",
"call",
"this",
"since",
"it",
"will",
"shut",
"off",
"ncurses",
"and",
"print",
"error",
"on",
"screen",
".",
"UNUSED"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L185-L202 |
23,820 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App.field_help_text | def field_help_text
f = @form.get_current_field
if f.respond_to?('help_text')
h = f.help_text
h = "No help text defined for this field.\nTry F1, or press '?' for key-bindings." unless h
textdialog "#{h}", :title => "Widget Help Text"
else
alert "Could not get field #{f} or does not respond to helptext. Try F1 or '?'"
end
end | ruby | def field_help_text
f = @form.get_current_field
if f.respond_to?('help_text')
h = f.help_text
h = "No help text defined for this field.\nTry F1, or press '?' for key-bindings." unless h
textdialog "#{h}", :title => "Widget Help Text"
else
alert "Could not get field #{f} or does not respond to helptext. Try F1 or '?'"
end
end | [
"def",
"field_help_text",
"f",
"=",
"@form",
".",
"get_current_field",
"if",
"f",
".",
"respond_to?",
"(",
"'help_text'",
")",
"h",
"=",
"f",
".",
"help_text",
"h",
"=",
"\"No help text defined for this field.\\nTry F1, or press '?' for key-bindings.\"",
"unless",
"h",
"textdialog",
"\"#{h}\"",
",",
":title",
"=>",
"\"Widget Help Text\"",
"else",
"alert",
"\"Could not get field #{f} or does not respond to helptext. Try F1 or '?'\"",
"end",
"end"
] | displays help_text associated with field. 2011-10-15 | [
"displays",
"help_text",
"associated",
"with",
"field",
".",
"2011",
"-",
"10",
"-",
"15"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L301-L310 |
23,821 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App.longest_in_list | def longest_in_list list #:nodoc:
longest = list.inject(0) do |memo,word|
memo >= word.length ? memo : word.length
end
longest
end | ruby | def longest_in_list list #:nodoc:
longest = list.inject(0) do |memo,word|
memo >= word.length ? memo : word.length
end
longest
end | [
"def",
"longest_in_list",
"list",
"#:nodoc:",
"longest",
"=",
"list",
".",
"inject",
"(",
"0",
")",
"do",
"|",
"memo",
",",
"word",
"|",
"memo",
">=",
"word",
".",
"length",
"?",
"memo",
":",
"word",
".",
"length",
"end",
"longest",
"end"
] | returns length of longest | [
"returns",
"length",
"of",
"longest"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L423-L428 |
23,822 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App._resolve_command | def _resolve_command opts, cmd
return cmd if opts.include? cmd
matches = opts.grep Regexp.new("^#{cmd}")
end | ruby | def _resolve_command opts, cmd
return cmd if opts.include? cmd
matches = opts.grep Regexp.new("^#{cmd}")
end | [
"def",
"_resolve_command",
"opts",
",",
"cmd",
"return",
"cmd",
"if",
"opts",
".",
"include?",
"cmd",
"matches",
"=",
"opts",
".",
"grep",
"Regexp",
".",
"new",
"(",
"\"^#{cmd}\"",
")",
"end"
] | if partial command entered then returns matches | [
"if",
"partial",
"command",
"entered",
"then",
"returns",
"matches"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L440-L443 |
23,823 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App.run | def run &block
begin
# check if user has passed window coord in config, else root window
@window = Canis::Window.root_window
awin = @window
catch(:close) do
@form = Form.new @window
#@form.bind_key(KEY_F1, 'help'){ display_app_help } # NOT REQUIRED NOW 2012-01-7 since form does it
@form.bind_key([?q,?q], 'quit' ){ throw :close } if $log.debug?
#@message = Variable.new
#@message.value = ""
$status_message ||= Variable.new # remember there are multiple levels of apps
$status_message.value = ""
#$error_message.update_command { @message.set_value($error_message.value) }
if block
begin
yield_or_eval &block if block_given?
# how the hell does a user trap exception if the loop is hidden from him ? FIXME
loop
rescue => ex
$log.debug( "APP.rb rescue reached ")
$log.debug( ex) if ex
$log.debug(ex.backtrace.join("\n")) if ex
ensure
close
# putting it here allows it to be printed on screen, otherwise it was not showing at all.
if ex
puts "========== EXCEPTION =========="
p ex
puts "==============================="
puts(ex.backtrace.join("\n"))
end
end
nil
else
#@close_on_terminate = true
self
end #if block
end # :close
end
end | ruby | def run &block
begin
# check if user has passed window coord in config, else root window
@window = Canis::Window.root_window
awin = @window
catch(:close) do
@form = Form.new @window
#@form.bind_key(KEY_F1, 'help'){ display_app_help } # NOT REQUIRED NOW 2012-01-7 since form does it
@form.bind_key([?q,?q], 'quit' ){ throw :close } if $log.debug?
#@message = Variable.new
#@message.value = ""
$status_message ||= Variable.new # remember there are multiple levels of apps
$status_message.value = ""
#$error_message.update_command { @message.set_value($error_message.value) }
if block
begin
yield_or_eval &block if block_given?
# how the hell does a user trap exception if the loop is hidden from him ? FIXME
loop
rescue => ex
$log.debug( "APP.rb rescue reached ")
$log.debug( ex) if ex
$log.debug(ex.backtrace.join("\n")) if ex
ensure
close
# putting it here allows it to be printed on screen, otherwise it was not showing at all.
if ex
puts "========== EXCEPTION =========="
p ex
puts "==============================="
puts(ex.backtrace.join("\n"))
end
end
nil
else
#@close_on_terminate = true
self
end #if block
end # :close
end
end | [
"def",
"run",
"&",
"block",
"begin",
"# check if user has passed window coord in config, else root window",
"@window",
"=",
"Canis",
"::",
"Window",
".",
"root_window",
"awin",
"=",
"@window",
"catch",
"(",
":close",
")",
"do",
"@form",
"=",
"Form",
".",
"new",
"@window",
"#@form.bind_key(KEY_F1, 'help'){ display_app_help } # NOT REQUIRED NOW 2012-01-7 since form does it",
"@form",
".",
"bind_key",
"(",
"[",
"?q",
",",
"?q",
"]",
",",
"'quit'",
")",
"{",
"throw",
":close",
"}",
"if",
"$log",
".",
"debug?",
"#@message = Variable.new",
"#@message.value = \"\"",
"$status_message",
"||=",
"Variable",
".",
"new",
"# remember there are multiple levels of apps",
"$status_message",
".",
"value",
"=",
"\"\"",
"#$error_message.update_command { @message.set_value($error_message.value) }",
"if",
"block",
"begin",
"yield_or_eval",
"block",
"if",
"block_given?",
"# how the hell does a user trap exception if the loop is hidden from him ? FIXME",
"loop",
"rescue",
"=>",
"ex",
"$log",
".",
"debug",
"(",
"\"APP.rb rescue reached \"",
")",
"$log",
".",
"debug",
"(",
"ex",
")",
"if",
"ex",
"$log",
".",
"debug",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"if",
"ex",
"ensure",
"close",
"# putting it here allows it to be printed on screen, otherwise it was not showing at all.",
"if",
"ex",
"puts",
"\"========== EXCEPTION ==========\"",
"p",
"ex",
"puts",
"\"===============================\"",
"puts",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end",
"nil",
"else",
"#@close_on_terminate = true",
"self",
"end",
"#if block",
"end",
"# :close",
"end",
"end"
] | This is the method that is called by all apps usually that define an App block | [
"This",
"is",
"the",
"method",
"that",
"is",
"called",
"by",
"all",
"apps",
"usually",
"that",
"define",
"an",
"App",
"block"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L446-L488 |
23,824 | mare-imbrium/canis | lib/canis/core/util/app.rb | Canis.App._process_args | def _process_args args, config, block_event, events #:nodoc:
raise "FIXME seems uncalled _process_args, remove it this does not come up within a month 2014-08-19 "
args.each do |arg|
case arg
when Array
# please don't use this, keep it simple and use hash NOTE
# we can use r,c, w, h
row, col, width, height = arg
config[:row] = row
config[:col] = col
config[:width] = width if width
# width for most XXX ?
config[:height] = height if height
when Hash
config.merge!(arg)
if block_event
block_event = config.delete(:block_event){ block_event }
raise "Invalid event. Use #{events}" unless events.include? block_event
end
when String
config[:name] = arg
config[:title] = arg # some may not have title
#config[:text] = arg # some may not have title
end
end
end | ruby | def _process_args args, config, block_event, events #:nodoc:
raise "FIXME seems uncalled _process_args, remove it this does not come up within a month 2014-08-19 "
args.each do |arg|
case arg
when Array
# please don't use this, keep it simple and use hash NOTE
# we can use r,c, w, h
row, col, width, height = arg
config[:row] = row
config[:col] = col
config[:width] = width if width
# width for most XXX ?
config[:height] = height if height
when Hash
config.merge!(arg)
if block_event
block_event = config.delete(:block_event){ block_event }
raise "Invalid event. Use #{events}" unless events.include? block_event
end
when String
config[:name] = arg
config[:title] = arg # some may not have title
#config[:text] = arg # some may not have title
end
end
end | [
"def",
"_process_args",
"args",
",",
"config",
",",
"block_event",
",",
"events",
"#:nodoc:",
"raise",
"\"FIXME seems uncalled _process_args, remove it this does not come up within a month 2014-08-19 \"",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"Array",
"# please don't use this, keep it simple and use hash NOTE",
"# we can use r,c, w, h",
"row",
",",
"col",
",",
"width",
",",
"height",
"=",
"arg",
"config",
"[",
":row",
"]",
"=",
"row",
"config",
"[",
":col",
"]",
"=",
"col",
"config",
"[",
":width",
"]",
"=",
"width",
"if",
"width",
"# width for most XXX ?",
"config",
"[",
":height",
"]",
"=",
"height",
"if",
"height",
"when",
"Hash",
"config",
".",
"merge!",
"(",
"arg",
")",
"if",
"block_event",
"block_event",
"=",
"config",
".",
"delete",
"(",
":block_event",
")",
"{",
"block_event",
"}",
"raise",
"\"Invalid event. Use #{events}\"",
"unless",
"events",
".",
"include?",
"block_event",
"end",
"when",
"String",
"config",
"[",
":name",
"]",
"=",
"arg",
"config",
"[",
":title",
"]",
"=",
"arg",
"# some may not have title",
"#config[:text] = arg # some may not have title",
"end",
"end",
"end"
] | process args, all widgets should call this | [
"process",
"args",
"all",
"widgets",
"should",
"call",
"this"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/app.rb#L553-L578 |
23,825 | mare-imbrium/canis | lib/canis/core/widgets/listfooter.rb | Canis.ListFooter.print | def print comp
config = @config
row = comp.row + comp.height - 1
col = comp.col + 2
len = comp.width - col
g = comp.form.window
# we check just in case user nullifies it deliberately, since he may have changed config values
@color_pair ||= get_color($datacolor, config[:color], config[:bgcolor])
@attrib ||= config[:attrib] || Ncurses::A_REVERSE
# first print dashes through
#g.printstring row, col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE
# now call the block to get current values for footer text on left
ftext = nil
if @command_text
ftext = text(comp)
else
if !@right_text
# user has not specified right or left, so we use a default on left
ftext = "#{comp.current_index} of #{comp.size} "
end
end
g.printstring(row, col, ftext, @color_pair, @attrib) if ftext
# user has specified text for right, print it
if @right_text
len = comp.width
ftext = right_text(comp)
c = len - ftext.length - 2
g.printstring row, c, ftext, @color_pair, @attrib
end
end | ruby | def print comp
config = @config
row = comp.row + comp.height - 1
col = comp.col + 2
len = comp.width - col
g = comp.form.window
# we check just in case user nullifies it deliberately, since he may have changed config values
@color_pair ||= get_color($datacolor, config[:color], config[:bgcolor])
@attrib ||= config[:attrib] || Ncurses::A_REVERSE
# first print dashes through
#g.printstring row, col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE
# now call the block to get current values for footer text on left
ftext = nil
if @command_text
ftext = text(comp)
else
if !@right_text
# user has not specified right or left, so we use a default on left
ftext = "#{comp.current_index} of #{comp.size} "
end
end
g.printstring(row, col, ftext, @color_pair, @attrib) if ftext
# user has specified text for right, print it
if @right_text
len = comp.width
ftext = right_text(comp)
c = len - ftext.length - 2
g.printstring row, c, ftext, @color_pair, @attrib
end
end | [
"def",
"print",
"comp",
"config",
"=",
"@config",
"row",
"=",
"comp",
".",
"row",
"+",
"comp",
".",
"height",
"-",
"1",
"col",
"=",
"comp",
".",
"col",
"+",
"2",
"len",
"=",
"comp",
".",
"width",
"-",
"col",
"g",
"=",
"comp",
".",
"form",
".",
"window",
"# we check just in case user nullifies it deliberately, since he may have changed config values",
"@color_pair",
"||=",
"get_color",
"(",
"$datacolor",
",",
"config",
"[",
":color",
"]",
",",
"config",
"[",
":bgcolor",
"]",
")",
"@attrib",
"||=",
"config",
"[",
":attrib",
"]",
"||",
"Ncurses",
"::",
"A_REVERSE",
"# first print dashes through",
"#g.printstring row, col, \"%s\" % \"-\" * len, @color_pair, Ncurses::A_REVERSE",
"# now call the block to get current values for footer text on left",
"ftext",
"=",
"nil",
"if",
"@command_text",
"ftext",
"=",
"text",
"(",
"comp",
")",
"else",
"if",
"!",
"@right_text",
"# user has not specified right or left, so we use a default on left",
"ftext",
"=",
"\"#{comp.current_index} of #{comp.size} \"",
"end",
"end",
"g",
".",
"printstring",
"(",
"row",
",",
"col",
",",
"ftext",
",",
"@color_pair",
",",
"@attrib",
")",
"if",
"ftext",
"# user has specified text for right, print it",
"if",
"@right_text",
"len",
"=",
"comp",
".",
"width",
"ftext",
"=",
"right_text",
"(",
"comp",
")",
"c",
"=",
"len",
"-",
"ftext",
".",
"length",
"-",
"2",
"g",
".",
"printstring",
"row",
",",
"c",
",",
"ftext",
",",
"@color_pair",
",",
"@attrib",
"end",
"end"
] | supply a default print function. The user program need not call this. It may be overridden
The idea of passing a component at this stage is that one footer can be created for several
tables or text components, each will pass +self+ when calling print.
@param comp : the calling textpad component (usually passed as +self+) | [
"supply",
"a",
"default",
"print",
"function",
".",
"The",
"user",
"program",
"need",
"not",
"call",
"this",
".",
"It",
"may",
"be",
"overridden",
"The",
"idea",
"of",
"passing",
"a",
"component",
"at",
"this",
"stage",
"is",
"that",
"one",
"footer",
"can",
"be",
"created",
"for",
"several",
"tables",
"or",
"text",
"components",
"each",
"will",
"pass",
"+",
"self",
"+",
"when",
"calling",
"print",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/listfooter.rb#L49-L82 |
23,826 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.set_layout | def set_layout(layout)
case layout
when Array
$log.error "NIL in window constructor" if layout.include? nil
raise ArgumentError, "Nil in window constructor" if layout.include? nil
# NOTE this is just setting, and not replacing zero with max values
@height, @width, @top, @left = *layout
raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil?
@layout = { :height => @height, :width => @width, :top => @top, :left => @left }
when Hash
@layout = layout
[:height, :width, :top, :left].each do |name|
instance_variable_set("@#{name}", @layout[name])
end
end
end | ruby | def set_layout(layout)
case layout
when Array
$log.error "NIL in window constructor" if layout.include? nil
raise ArgumentError, "Nil in window constructor" if layout.include? nil
# NOTE this is just setting, and not replacing zero with max values
@height, @width, @top, @left = *layout
raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil?
@layout = { :height => @height, :width => @width, :top => @top, :left => @left }
when Hash
@layout = layout
[:height, :width, :top, :left].each do |name|
instance_variable_set("@#{name}", @layout[name])
end
end
end | [
"def",
"set_layout",
"(",
"layout",
")",
"case",
"layout",
"when",
"Array",
"$log",
".",
"error",
"\"NIL in window constructor\"",
"if",
"layout",
".",
"include?",
"nil",
"raise",
"ArgumentError",
",",
"\"Nil in window constructor\"",
"if",
"layout",
".",
"include?",
"nil",
"# NOTE this is just setting, and not replacing zero with max values",
"@height",
",",
"@width",
",",
"@top",
",",
"@left",
"=",
"layout",
"raise",
"ArgumentError",
",",
"\"Nil in window constructor\"",
"if",
"@top",
".",
"nil?",
"||",
"@left",
".",
"nil?",
"@layout",
"=",
"{",
":height",
"=>",
"@height",
",",
":width",
"=>",
"@width",
",",
":top",
"=>",
"@top",
",",
":left",
"=>",
"@left",
"}",
"when",
"Hash",
"@layout",
"=",
"layout",
"[",
":height",
",",
":width",
",",
":top",
",",
":left",
"]",
".",
"each",
"do",
"|",
"name",
"|",
"instance_variable_set",
"(",
"\"@#{name}\"",
",",
"@layout",
"[",
"name",
"]",
")",
"end",
"end",
"end"
] | Creating variables case of array, we still create the hash
@param array or hash containing h w t and l | [
"Creating",
"variables",
"case",
"of",
"array",
"we",
"still",
"create",
"the",
"hash"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L229-L246 |
23,827 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.destroy | def destroy
# typically the ensure block should have this
#$log.debug "win destroy start"
$global_windows.delete self
Ncurses::Panel.del_panel(@panel.pointer) if @panel
delwin() if @window
Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
# destroy any pads that were created by widgets using get_pad
@pads.each { |pad|
FFI::NCurses.delwin(pad) if pad
pad = nil
} if @pads
# added here to hopefully take care of this issue once and for all.
# Whenever any window is destroyed, the root window is repainted.
#
# 2014-08-18 - 20:35 trying out without refresh all since lower dialog gets erased
Window.refresh_all
#$log.debug "win destroy end"
end | ruby | def destroy
# typically the ensure block should have this
#$log.debug "win destroy start"
$global_windows.delete self
Ncurses::Panel.del_panel(@panel.pointer) if @panel
delwin() if @window
Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
# destroy any pads that were created by widgets using get_pad
@pads.each { |pad|
FFI::NCurses.delwin(pad) if pad
pad = nil
} if @pads
# added here to hopefully take care of this issue once and for all.
# Whenever any window is destroyed, the root window is repainted.
#
# 2014-08-18 - 20:35 trying out without refresh all since lower dialog gets erased
Window.refresh_all
#$log.debug "win destroy end"
end | [
"def",
"destroy",
"# typically the ensure block should have this",
"#$log.debug \"win destroy start\"",
"$global_windows",
".",
"delete",
"self",
"Ncurses",
"::",
"Panel",
".",
"del_panel",
"(",
"@panel",
".",
"pointer",
")",
"if",
"@panel",
"delwin",
"(",
")",
"if",
"@window",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"# added so below window does not need to do this 2011-10-1 ",
"# destroy any pads that were created by widgets using get_pad",
"@pads",
".",
"each",
"{",
"|",
"pad",
"|",
"FFI",
"::",
"NCurses",
".",
"delwin",
"(",
"pad",
")",
"if",
"pad",
"pad",
"=",
"nil",
"}",
"if",
"@pads",
"# added here to hopefully take care of this issue once and for all. ",
"# Whenever any window is destroyed, the root window is repainted.",
"#",
"# 2014-08-18 - 20:35 trying out without refresh all since lower dialog gets erased",
"Window",
".",
"refresh_all",
"#$log.debug \"win destroy end\"",
"end"
] | destroy window, panel and any pads that were requested | [
"destroy",
"window",
"panel",
"and",
"any",
"pads",
"that",
"were",
"requested"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L429-L450 |
23,828 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.get_pad | def get_pad content_rows, content_cols
pad = FFI::NCurses.newpad(content_rows, content_cols)
@pads ||= []
@pads << pad
## added 2013-03-05 - 19:21 without next line how was pad being returned
return pad
end | ruby | def get_pad content_rows, content_cols
pad = FFI::NCurses.newpad(content_rows, content_cols)
@pads ||= []
@pads << pad
## added 2013-03-05 - 19:21 without next line how was pad being returned
return pad
end | [
"def",
"get_pad",
"content_rows",
",",
"content_cols",
"pad",
"=",
"FFI",
"::",
"NCurses",
".",
"newpad",
"(",
"content_rows",
",",
"content_cols",
")",
"@pads",
"||=",
"[",
"]",
"@pads",
"<<",
"pad",
"## added 2013-03-05 - 19:21 without next line how was pad being returned",
"return",
"pad",
"end"
] | Widgets can get window to create a pad for them. This way when the window
is destroyed, it will delete all the pads. A widget wold not be able to do this.
The destroy method of the widget will be called. | [
"Widgets",
"can",
"get",
"window",
"to",
"create",
"a",
"pad",
"for",
"them",
".",
"This",
"way",
"when",
"the",
"window",
"is",
"destroyed",
"it",
"will",
"delete",
"all",
"the",
"pads",
".",
"A",
"widget",
"wold",
"not",
"be",
"able",
"to",
"do",
"this",
".",
"The",
"destroy",
"method",
"of",
"the",
"widget",
"will",
"be",
"called",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L456-L462 |
23,829 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.print_border_mb | def print_border_mb row, col, height, width, color, attr
# the next is for xterm-256
att = get_attrib attr
len = width
len = Ncurses.COLS-0 if len == 0
# print a bar across the screen
#attron(Ncurses.COLOR_PAIR(color) | att)
# this works for newmessagebox but not for old one.
# Even now in some cases some black shows through, if the widget is printing spaces
# such as field or textview on a messagebox.
# 2016-01-14 - replacing 1 with space since junk is showing up in some cases.
space_char = " ".codepoints.first
(row-1).upto(row+height-1) do |r|
# this loop clears the screen, printing spaces does not work since ncurses does not do anything
mvwhline(r, col, space_char, len)
end
#attroff(Ncurses.COLOR_PAIR(color) | att)
mvwaddch row, col, Ncurses::ACS_ULCORNER
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6)
mvwaddch row, col+width-5, Ncurses::ACS_URCORNER
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-4)
mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER
mvwhline(row+height-3, col+1, Ncurses::ACS_HLINE, width-6)
mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER
mvwvline( row+1, col+width-5, Ncurses::ACS_VLINE, height-4)
end | ruby | def print_border_mb row, col, height, width, color, attr
# the next is for xterm-256
att = get_attrib attr
len = width
len = Ncurses.COLS-0 if len == 0
# print a bar across the screen
#attron(Ncurses.COLOR_PAIR(color) | att)
# this works for newmessagebox but not for old one.
# Even now in some cases some black shows through, if the widget is printing spaces
# such as field or textview on a messagebox.
# 2016-01-14 - replacing 1 with space since junk is showing up in some cases.
space_char = " ".codepoints.first
(row-1).upto(row+height-1) do |r|
# this loop clears the screen, printing spaces does not work since ncurses does not do anything
mvwhline(r, col, space_char, len)
end
#attroff(Ncurses.COLOR_PAIR(color) | att)
mvwaddch row, col, Ncurses::ACS_ULCORNER
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6)
mvwaddch row, col+width-5, Ncurses::ACS_URCORNER
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-4)
mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER
mvwhline(row+height-3, col+1, Ncurses::ACS_HLINE, width-6)
mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER
mvwvline( row+1, col+width-5, Ncurses::ACS_VLINE, height-4)
end | [
"def",
"print_border_mb",
"row",
",",
"col",
",",
"height",
",",
"width",
",",
"color",
",",
"attr",
"# the next is for xterm-256 ",
"att",
"=",
"get_attrib",
"attr",
"len",
"=",
"width",
"len",
"=",
"Ncurses",
".",
"COLS",
"-",
"0",
"if",
"len",
"==",
"0",
"# print a bar across the screen ",
"#attron(Ncurses.COLOR_PAIR(color) | att)",
"# this works for newmessagebox but not for old one.",
"# Even now in some cases some black shows through, if the widget is printing spaces",
"# such as field or textview on a messagebox.",
"# 2016-01-14 - replacing 1 with space since junk is showing up in some cases.",
"space_char",
"=",
"\" \"",
".",
"codepoints",
".",
"first",
"(",
"row",
"-",
"1",
")",
".",
"upto",
"(",
"row",
"+",
"height",
"-",
"1",
")",
"do",
"|",
"r",
"|",
"# this loop clears the screen, printing spaces does not work since ncurses does not do anything",
"mvwhline",
"(",
"r",
",",
"col",
",",
"space_char",
",",
"len",
")",
"end",
"#attroff(Ncurses.COLOR_PAIR(color) | att)",
"mvwaddch",
"row",
",",
"col",
",",
"Ncurses",
"::",
"ACS_ULCORNER",
"mvwhline",
"(",
"row",
",",
"col",
"+",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"width",
"-",
"6",
")",
"mvwaddch",
"row",
",",
"col",
"+",
"width",
"-",
"5",
",",
"Ncurses",
"::",
"ACS_URCORNER",
"mvwvline",
"(",
"row",
"+",
"1",
",",
"col",
",",
"Ncurses",
"::",
"ACS_VLINE",
",",
"height",
"-",
"4",
")",
"mvwaddch",
"row",
"+",
"height",
"-",
"3",
",",
"col",
",",
"Ncurses",
"::",
"ACS_LLCORNER",
"mvwhline",
"(",
"row",
"+",
"height",
"-",
"3",
",",
"col",
"+",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"width",
"-",
"6",
")",
"mvwaddch",
"row",
"+",
"height",
"-",
"3",
",",
"col",
"+",
"width",
"-",
"5",
",",
"Ncurses",
"::",
"ACS_LRCORNER",
"mvwvline",
"(",
"row",
"+",
"1",
",",
"col",
"+",
"width",
"-",
"5",
",",
"Ncurses",
"::",
"ACS_VLINE",
",",
"height",
"-",
"4",
")",
"end"
] | prints the border for message boxes
NOTE : FOR MESSAGEBOXES ONLY !!!! Then why not move to messagebox FIXME | [
"prints",
"the",
"border",
"for",
"message",
"boxes"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L583-L610 |
23,830 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.print_border | def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
raise "height needs to be supplied." if height.nil?
raise "width needs to be supplied." if width.nil?
att ||= Ncurses::A_NORMAL
#$log.debug " inside window print_border r #{row} c #{col} h #{height} w #{width} "
# 2009-11-02 00:45 made att nil for blanking out
# FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view
# when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53
ww=width-2
clr = " "*ww
(row+1).upto(row+height-1) do |r|
printstring( r, col+1, clr, color, att)
end
print_border_only row, col, height, width, color, att
end | ruby | def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
raise "height needs to be supplied." if height.nil?
raise "width needs to be supplied." if width.nil?
att ||= Ncurses::A_NORMAL
#$log.debug " inside window print_border r #{row} c #{col} h #{height} w #{width} "
# 2009-11-02 00:45 made att nil for blanking out
# FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view
# when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53
ww=width-2
clr = " "*ww
(row+1).upto(row+height-1) do |r|
printstring( r, col+1, clr, color, att)
end
print_border_only row, col, height, width, color, att
end | [
"def",
"print_border",
"row",
",",
"col",
",",
"height",
",",
"width",
",",
"color",
",",
"att",
"=",
"Ncurses",
"::",
"A_NORMAL",
"raise",
"\"height needs to be supplied.\"",
"if",
"height",
".",
"nil?",
"raise",
"\"width needs to be supplied.\"",
"if",
"width",
".",
"nil?",
"att",
"||=",
"Ncurses",
"::",
"A_NORMAL",
"#$log.debug \" inside window print_border r #{row} c #{col} h #{height} w #{width} \"",
"# 2009-11-02 00:45 made att nil for blanking out",
"# FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view",
"# when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53 ",
"ww",
"=",
"width",
"-",
"2",
"clr",
"=",
"\" \"",
"*",
"ww",
"(",
"row",
"+",
"1",
")",
".",
"upto",
"(",
"row",
"+",
"height",
"-",
"1",
")",
"do",
"|",
"r",
"|",
"printstring",
"(",
"r",
",",
"col",
"+",
"1",
",",
"clr",
",",
"color",
",",
"att",
")",
"end",
"print_border_only",
"row",
",",
"col",
",",
"height",
",",
"width",
",",
"color",
",",
"att",
"end"
] | prints a border around a widget, CLEARING the area.
If calling with a pad, you would typically use 0,0, h-1, w-1.
FIXME can this be moved to module Bordertitle ? | [
"prints",
"a",
"border",
"around",
"a",
"widget",
"CLEARING",
"the",
"area",
".",
"If",
"calling",
"with",
"a",
"pad",
"you",
"would",
"typically",
"use",
"0",
"0",
"h",
"-",
"1",
"w",
"-",
"1",
".",
"FIXME",
"can",
"this",
"be",
"moved",
"to",
"module",
"Bordertitle",
"?"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L616-L632 |
23,831 | mare-imbrium/canis | lib/canis/core/system/window.rb | Canis.Window.print_border_only | def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
if att.nil?
att = Ncurses::A_NORMAL
else
att = get_attrib att
end
wattron(Ncurses.COLOR_PAIR(color) | att)
mvwaddch row, col, Ncurses::ACS_ULCORNER
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-2)
mvwaddch row, col+width-1, Ncurses::ACS_URCORNER
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-1)
mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER
mvwhline(row+height-0, col+1, Ncurses::ACS_HLINE, width-2)
mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER
mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1)
wattroff(Ncurses.COLOR_PAIR(color) | att)
end | ruby | def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
if att.nil?
att = Ncurses::A_NORMAL
else
att = get_attrib att
end
wattron(Ncurses.COLOR_PAIR(color) | att)
mvwaddch row, col, Ncurses::ACS_ULCORNER
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-2)
mvwaddch row, col+width-1, Ncurses::ACS_URCORNER
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-1)
mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER
mvwhline(row+height-0, col+1, Ncurses::ACS_HLINE, width-2)
mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER
mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1)
wattroff(Ncurses.COLOR_PAIR(color) | att)
end | [
"def",
"print_border_only",
"row",
",",
"col",
",",
"height",
",",
"width",
",",
"color",
",",
"att",
"=",
"Ncurses",
"::",
"A_NORMAL",
"if",
"att",
".",
"nil?",
"att",
"=",
"Ncurses",
"::",
"A_NORMAL",
"else",
"att",
"=",
"get_attrib",
"att",
"end",
"wattron",
"(",
"Ncurses",
".",
"COLOR_PAIR",
"(",
"color",
")",
"|",
"att",
")",
"mvwaddch",
"row",
",",
"col",
",",
"Ncurses",
"::",
"ACS_ULCORNER",
"mvwhline",
"(",
"row",
",",
"col",
"+",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"width",
"-",
"2",
")",
"mvwaddch",
"row",
",",
"col",
"+",
"width",
"-",
"1",
",",
"Ncurses",
"::",
"ACS_URCORNER",
"mvwvline",
"(",
"row",
"+",
"1",
",",
"col",
",",
"Ncurses",
"::",
"ACS_VLINE",
",",
"height",
"-",
"1",
")",
"mvwaddch",
"row",
"+",
"height",
"-",
"0",
",",
"col",
",",
"Ncurses",
"::",
"ACS_LLCORNER",
"mvwhline",
"(",
"row",
"+",
"height",
"-",
"0",
",",
"col",
"+",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"width",
"-",
"2",
")",
"mvwaddch",
"row",
"+",
"height",
"-",
"0",
",",
"col",
"+",
"width",
"-",
"1",
",",
"Ncurses",
"::",
"ACS_LRCORNER",
"mvwvline",
"(",
"row",
"+",
"1",
",",
"col",
"+",
"width",
"-",
"1",
",",
"Ncurses",
"::",
"ACS_VLINE",
",",
"height",
"-",
"1",
")",
"wattroff",
"(",
"Ncurses",
".",
"COLOR_PAIR",
"(",
"color",
")",
"|",
"att",
")",
"end"
] | print just the border, no cleanup
+ Earlier, we would clean up. Now in some cases, i'd like
+ to print border over what's been done.
XXX this reduces 1 from width but not height !!! FIXME
FIXME can this be moved to module Bordertitle ? | [
"print",
"just",
"the",
"border",
"no",
"cleanup",
"+",
"Earlier",
"we",
"would",
"clean",
"up",
".",
"Now",
"in",
"some",
"cases",
"i",
"d",
"like",
"+",
"to",
"print",
"border",
"over",
"what",
"s",
"been",
"done",
".",
"XXX",
"this",
"reduces",
"1",
"from",
"width",
"but",
"not",
"height",
"!!!",
"FIXME",
"FIXME",
"can",
"this",
"be",
"moved",
"to",
"module",
"Bordertitle",
"?"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/system/window.rb#L640-L657 |
23,832 | mare-imbrium/canis | lib/canis/core/widgets/rtabbedpane.rb | Canis.TabbedPane.goto_last_item | def goto_last_item
bc = @buttons.count
f = nil
@components[bc..-1].each { |c|
if c.focusable
f = c
end
}
if f
leave_current_component
@current_component = f
set_form_row
end
end | ruby | def goto_last_item
bc = @buttons.count
f = nil
@components[bc..-1].each { |c|
if c.focusable
f = c
end
}
if f
leave_current_component
@current_component = f
set_form_row
end
end | [
"def",
"goto_last_item",
"bc",
"=",
"@buttons",
".",
"count",
"f",
"=",
"nil",
"@components",
"[",
"bc",
"..",
"-",
"1",
"]",
".",
"each",
"{",
"|",
"c",
"|",
"if",
"c",
".",
"focusable",
"f",
"=",
"c",
"end",
"}",
"if",
"f",
"leave_current_component",
"@current_component",
"=",
"f",
"set_form_row",
"end",
"end"
] | takes focus to last item | [
"takes",
"focus",
"to",
"last",
"item"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rtabbedpane.rb#L219-L232 |
23,833 | mare-imbrium/canis | lib/canis/core/widgets/rtabbedpane.rb | Canis.TabbedPane.goto_next_component | def goto_next_component
if @current_component != nil
leave_current_component
if on_last_component?
@_entered = false
return :UNHANDLED
end
@current_index = @components.index(@current_component)
index = @current_index + 1
index.upto(@components.length-1) do |i|
f = @components[i]
if f.focusable
@current_index = i
@current_component = f
return set_form_row
end
end
end
@_entered = false
return :UNHANDLED
end | ruby | def goto_next_component
if @current_component != nil
leave_current_component
if on_last_component?
@_entered = false
return :UNHANDLED
end
@current_index = @components.index(@current_component)
index = @current_index + 1
index.upto(@components.length-1) do |i|
f = @components[i]
if f.focusable
@current_index = i
@current_component = f
return set_form_row
end
end
end
@_entered = false
return :UNHANDLED
end | [
"def",
"goto_next_component",
"if",
"@current_component",
"!=",
"nil",
"leave_current_component",
"if",
"on_last_component?",
"@_entered",
"=",
"false",
"return",
":UNHANDLED",
"end",
"@current_index",
"=",
"@components",
".",
"index",
"(",
"@current_component",
")",
"index",
"=",
"@current_index",
"+",
"1",
"index",
".",
"upto",
"(",
"@components",
".",
"length",
"-",
"1",
")",
"do",
"|",
"i",
"|",
"f",
"=",
"@components",
"[",
"i",
"]",
"if",
"f",
".",
"focusable",
"@current_index",
"=",
"i",
"@current_component",
"=",
"f",
"return",
"set_form_row",
"end",
"end",
"end",
"@_entered",
"=",
"false",
"return",
":UNHANDLED",
"end"
] | take focus to the next component or item
Called from DOWN, RIGHT or Tab | [
"take",
"focus",
"to",
"the",
"next",
"component",
"or",
"item",
"Called",
"from",
"DOWN",
"RIGHT",
"or",
"Tab"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rtabbedpane.rb#L235-L255 |
23,834 | mare-imbrium/canis | lib/canis/core/widgets/rtabbedpane.rb | Canis.TabbedPane.goto_prev_component | def goto_prev_component
if @current_component != nil
leave_current_component
if on_first_component?
@_entered = false
return :UNHANDLED
end
@current_index = @components.index(@current_component)
index = @current_index -= 1
index.downto(0) do |i|
f = @components[i]
if f.focusable
@current_index = i
@current_component = f
return set_form_row
end
end
end
return :UNHANDLED
end | ruby | def goto_prev_component
if @current_component != nil
leave_current_component
if on_first_component?
@_entered = false
return :UNHANDLED
end
@current_index = @components.index(@current_component)
index = @current_index -= 1
index.downto(0) do |i|
f = @components[i]
if f.focusable
@current_index = i
@current_component = f
return set_form_row
end
end
end
return :UNHANDLED
end | [
"def",
"goto_prev_component",
"if",
"@current_component",
"!=",
"nil",
"leave_current_component",
"if",
"on_first_component?",
"@_entered",
"=",
"false",
"return",
":UNHANDLED",
"end",
"@current_index",
"=",
"@components",
".",
"index",
"(",
"@current_component",
")",
"index",
"=",
"@current_index",
"-=",
"1",
"index",
".",
"downto",
"(",
"0",
")",
"do",
"|",
"i",
"|",
"f",
"=",
"@components",
"[",
"i",
"]",
"if",
"f",
".",
"focusable",
"@current_index",
"=",
"i",
"@current_component",
"=",
"f",
"return",
"set_form_row",
"end",
"end",
"end",
"return",
":UNHANDLED",
"end"
] | take focus to prev component or item
Called from LEFT, UP or Back Tab | [
"take",
"focus",
"to",
"prev",
"component",
"or",
"item",
"Called",
"from",
"LEFT",
"UP",
"or",
"Back",
"Tab"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rtabbedpane.rb#L258-L277 |
23,835 | mare-imbrium/canis | lib/canis/core/widgets/rtabbedpane.rb | Canis.TabbedPane.make_buttons | def make_buttons names
@action_buttons = []
$log.debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} "
total = names.inject(0) {|total, item| total + item.length + 4}
bcol = center_column total
# this craps out when height is zero
brow = @row + @height-2
brow = FFI::NCurses.LINES-2 if brow < 0
$log.debug "XXX: putting buttons :on #{brow} : #{@row} , #{@height} "
button_ct=0
tpp = self
names.each_with_index do |bname, ix|
text = bname
#underline = @underlines[ix] if [email protected]?
button = Button.new nil do
text text
name bname
row brow
col bcol
#underline underline
highlight_bgcolor $reversecolor
color $datacolor
bgcolor $datacolor
end
@action_buttons << button
button.form = @form
button.override_graphic @graphic
index = button_ct
tpp = self
button.command { |form| @selected_index = index; @stop = true;
# ActionEvent has source event and action_command
fire_handler :PRESS, ActionEvent.new(tpp, index, button.text)
#throw(:close, @selected_index)
}
button_ct += 1
bcol += text.length+6
end
end | ruby | def make_buttons names
@action_buttons = []
$log.debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} "
total = names.inject(0) {|total, item| total + item.length + 4}
bcol = center_column total
# this craps out when height is zero
brow = @row + @height-2
brow = FFI::NCurses.LINES-2 if brow < 0
$log.debug "XXX: putting buttons :on #{brow} : #{@row} , #{@height} "
button_ct=0
tpp = self
names.each_with_index do |bname, ix|
text = bname
#underline = @underlines[ix] if [email protected]?
button = Button.new nil do
text text
name bname
row brow
col bcol
#underline underline
highlight_bgcolor $reversecolor
color $datacolor
bgcolor $datacolor
end
@action_buttons << button
button.form = @form
button.override_graphic @graphic
index = button_ct
tpp = self
button.command { |form| @selected_index = index; @stop = true;
# ActionEvent has source event and action_command
fire_handler :PRESS, ActionEvent.new(tpp, index, button.text)
#throw(:close, @selected_index)
}
button_ct += 1
bcol += text.length+6
end
end | [
"def",
"make_buttons",
"names",
"@action_buttons",
"=",
"[",
"]",
"$log",
".",
"debug",
"\"XXX: came to NTP make buttons FORM= #{@form.name} names #{names} \"",
"total",
"=",
"names",
".",
"inject",
"(",
"0",
")",
"{",
"|",
"total",
",",
"item",
"|",
"total",
"+",
"item",
".",
"length",
"+",
"4",
"}",
"bcol",
"=",
"center_column",
"total",
"# this craps out when height is zero",
"brow",
"=",
"@row",
"+",
"@height",
"-",
"2",
"brow",
"=",
"FFI",
"::",
"NCurses",
".",
"LINES",
"-",
"2",
"if",
"brow",
"<",
"0",
"$log",
".",
"debug",
"\"XXX: putting buttons :on #{brow} : #{@row} , #{@height} \"",
"button_ct",
"=",
"0",
"tpp",
"=",
"self",
"names",
".",
"each_with_index",
"do",
"|",
"bname",
",",
"ix",
"|",
"text",
"=",
"bname",
"#underline = @underlines[ix] if [email protected]?",
"button",
"=",
"Button",
".",
"new",
"nil",
"do",
"text",
"text",
"name",
"bname",
"row",
"brow",
"col",
"bcol",
"#underline underline",
"highlight_bgcolor",
"$reversecolor",
"color",
"$datacolor",
"bgcolor",
"$datacolor",
"end",
"@action_buttons",
"<<",
"button",
"button",
".",
"form",
"=",
"@form",
"button",
".",
"override_graphic",
"@graphic",
"index",
"=",
"button_ct",
"tpp",
"=",
"self",
"button",
".",
"command",
"{",
"|",
"form",
"|",
"@selected_index",
"=",
"index",
";",
"@stop",
"=",
"true",
";",
"# ActionEvent has source event and action_command",
"fire_handler",
":PRESS",
",",
"ActionEvent",
".",
"new",
"(",
"tpp",
",",
"index",
",",
"button",
".",
"text",
")",
"#throw(:close, @selected_index)",
"}",
"button_ct",
"+=",
"1",
"bcol",
"+=",
"text",
".",
"length",
"+",
"6",
"end",
"end"
] | actually creates the action buttons | [
"actually",
"creates",
"the",
"action",
"buttons"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rtabbedpane.rb#L492-L531 |
23,836 | mare-imbrium/canis | lib/canis/core/widgets/rcombo.rb | Canis.ComboBox.handle_key | def handle_key(ch)
@current_index ||= 0
# added 2009-01-18 22:44 no point moving horiz or passing up to Field if not edit
if !@editable
if ch == KEY_LEFT or ch == KEY_RIGHT
return :UNHANDLED
end
end
case @arrow_key_policy
when :ignore
if ch == KEY_DOWN or ch == KEY_UP
return :UNHANDLED
end
when :popup
if ch == KEY_DOWN or ch == KEY_UP
popup
end
end
case ch
#when KEY_UP # show previous value
# previous_row
#when KEY_DOWN # show previous value
# next_row
# adding spacebar to popup combo, as in microemacs 2010-10-01 13:21
when 32, KEY_DOWN+ META_KEY # alt down
popup # pop up the popup
else
super
end
end | ruby | def handle_key(ch)
@current_index ||= 0
# added 2009-01-18 22:44 no point moving horiz or passing up to Field if not edit
if !@editable
if ch == KEY_LEFT or ch == KEY_RIGHT
return :UNHANDLED
end
end
case @arrow_key_policy
when :ignore
if ch == KEY_DOWN or ch == KEY_UP
return :UNHANDLED
end
when :popup
if ch == KEY_DOWN or ch == KEY_UP
popup
end
end
case ch
#when KEY_UP # show previous value
# previous_row
#when KEY_DOWN # show previous value
# next_row
# adding spacebar to popup combo, as in microemacs 2010-10-01 13:21
when 32, KEY_DOWN+ META_KEY # alt down
popup # pop up the popup
else
super
end
end | [
"def",
"handle_key",
"(",
"ch",
")",
"@current_index",
"||=",
"0",
"# added 2009-01-18 22:44 no point moving horiz or passing up to Field if not edit",
"if",
"!",
"@editable",
"if",
"ch",
"==",
"KEY_LEFT",
"or",
"ch",
"==",
"KEY_RIGHT",
"return",
":UNHANDLED",
"end",
"end",
"case",
"@arrow_key_policy",
"when",
":ignore",
"if",
"ch",
"==",
"KEY_DOWN",
"or",
"ch",
"==",
"KEY_UP",
"return",
":UNHANDLED",
"end",
"when",
":popup",
"if",
"ch",
"==",
"KEY_DOWN",
"or",
"ch",
"==",
"KEY_UP",
"popup",
"end",
"end",
"case",
"ch",
"#when KEY_UP # show previous value",
"# previous_row",
"#when KEY_DOWN # show previous value",
"# next_row",
"# adding spacebar to popup combo, as in microemacs 2010-10-01 13:21 ",
"when",
"32",
",",
"KEY_DOWN",
"+",
"META_KEY",
"# alt down",
"popup",
"# pop up the popup",
"else",
"super",
"end",
"end"
] | combo edit box key handling
removed UP and DOWN and bound it, so it can be unbound | [
"combo",
"edit",
"box",
"key",
"handling",
"removed",
"UP",
"and",
"DOWN",
"and",
"bound",
"it",
"so",
"it",
"can",
"be",
"unbound"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rcombo.rb#L80-L109 |
23,837 | mare-imbrium/canis | lib/canis/core/widgets/rcombo.rb | Canis.ComboBox.putc | def putc c
if c >= 0 and c <= 127
ret = putch c.chr
if ret == 0
addcol 1 if @editable
set_modified
end
end
return -1 # always ??? XXX
end | ruby | def putc c
if c >= 0 and c <= 127
ret = putch c.chr
if ret == 0
addcol 1 if @editable
set_modified
end
end
return -1 # always ??? XXX
end | [
"def",
"putc",
"c",
"if",
"c",
">=",
"0",
"and",
"c",
"<=",
"127",
"ret",
"=",
"putch",
"c",
".",
"chr",
"if",
"ret",
"==",
"0",
"addcol",
"1",
"if",
"@editable",
"set_modified",
"end",
"end",
"return",
"-",
"1",
"# always ??? XXX ",
"end"
] | Field putc advances cursor when it gives a char so we override this | [
"Field",
"putc",
"advances",
"cursor",
"when",
"it",
"gives",
"a",
"char",
"so",
"we",
"override",
"this"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rcombo.rb#L140-L149 |
23,838 | mare-imbrium/canis | lib/canis/core/widgets/rcombo.rb | Canis.ComboBox.putch | def putch char
@current_index ||= 0
if @editable
raise "how is it editable here in combo"
super
return 0
else
match = next_match(char)
text match unless match.nil?
fire_handler :ENTER_ROW, self
end
@modified = true
fire_handler :CHANGE, self # 2008-12-09 14:51 ???
0
end | ruby | def putch char
@current_index ||= 0
if @editable
raise "how is it editable here in combo"
super
return 0
else
match = next_match(char)
text match unless match.nil?
fire_handler :ENTER_ROW, self
end
@modified = true
fire_handler :CHANGE, self # 2008-12-09 14:51 ???
0
end | [
"def",
"putch",
"char",
"@current_index",
"||=",
"0",
"if",
"@editable",
"raise",
"\"how is it editable here in combo\"",
"super",
"return",
"0",
"else",
"match",
"=",
"next_match",
"(",
"char",
")",
"text",
"match",
"unless",
"match",
".",
"nil?",
"fire_handler",
":ENTER_ROW",
",",
"self",
"end",
"@modified",
"=",
"true",
"fire_handler",
":CHANGE",
",",
"self",
"# 2008-12-09 14:51 ???",
"0",
"end"
] | field does not give char to non-editable fields so we override | [
"field",
"does",
"not",
"give",
"char",
"to",
"non",
"-",
"editable",
"fields",
"so",
"we",
"override"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rcombo.rb#L152-L166 |
23,839 | mare-imbrium/canis | lib/canis/core/widgets/rcombo.rb | Canis.ComboBox.next_match | def next_match char
start = @current_index
start.upto(@list.length-1) do |ix|
if @list[ix][0,1].casecmp(char) == 0
return @list[ix] unless @list[ix] == @buffer
end
@current_index += 1
end
## could not find, start from zero
@current_index = 0
start = [@list.length()-1, start].min
0.upto(start) do |ix|
if @list[ix][0,1].casecmp(char) == 0
return @list[ix] unless @list[ix] == @buffer
end
@current_index += 1
end
@current_index = [@list.length()-1, @current_index].min
return nil
end | ruby | def next_match char
start = @current_index
start.upto(@list.length-1) do |ix|
if @list[ix][0,1].casecmp(char) == 0
return @list[ix] unless @list[ix] == @buffer
end
@current_index += 1
end
## could not find, start from zero
@current_index = 0
start = [@list.length()-1, start].min
0.upto(start) do |ix|
if @list[ix][0,1].casecmp(char) == 0
return @list[ix] unless @list[ix] == @buffer
end
@current_index += 1
end
@current_index = [@list.length()-1, @current_index].min
return nil
end | [
"def",
"next_match",
"char",
"start",
"=",
"@current_index",
"start",
".",
"upto",
"(",
"@list",
".",
"length",
"-",
"1",
")",
"do",
"|",
"ix",
"|",
"if",
"@list",
"[",
"ix",
"]",
"[",
"0",
",",
"1",
"]",
".",
"casecmp",
"(",
"char",
")",
"==",
"0",
"return",
"@list",
"[",
"ix",
"]",
"unless",
"@list",
"[",
"ix",
"]",
"==",
"@buffer",
"end",
"@current_index",
"+=",
"1",
"end",
"## could not find, start from zero",
"@current_index",
"=",
"0",
"start",
"=",
"[",
"@list",
".",
"length",
"(",
")",
"-",
"1",
",",
"start",
"]",
".",
"min",
"0",
".",
"upto",
"(",
"start",
")",
"do",
"|",
"ix",
"|",
"if",
"@list",
"[",
"ix",
"]",
"[",
"0",
",",
"1",
"]",
".",
"casecmp",
"(",
"char",
")",
"==",
"0",
"return",
"@list",
"[",
"ix",
"]",
"unless",
"@list",
"[",
"ix",
"]",
"==",
"@buffer",
"end",
"@current_index",
"+=",
"1",
"end",
"@current_index",
"=",
"[",
"@list",
".",
"length",
"(",
")",
"-",
"1",
",",
"@current_index",
"]",
".",
"min",
"return",
"nil",
"end"
] | the sets the next match in the edit field | [
"the",
"sets",
"the",
"next",
"match",
"in",
"the",
"edit",
"field"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rcombo.rb#L169-L188 |
23,840 | mare-imbrium/canis | examples/common/devel.rb | Canis.Devel.choose_file_and_view | def choose_file_and_view glob=nil, startdir="."
glob ||= "**/*.rb"
str = choose_file glob, :title => "Select a file",
:directory => startdir,
:help_text => "Enter pattern, use UP DOWN to traverse, Backspace to delete, ENTER to select. Esc-Esc to quit"
if str and str != ""
code_browse str
end
end | ruby | def choose_file_and_view glob=nil, startdir="."
glob ||= "**/*.rb"
str = choose_file glob, :title => "Select a file",
:directory => startdir,
:help_text => "Enter pattern, use UP DOWN to traverse, Backspace to delete, ENTER to select. Esc-Esc to quit"
if str and str != ""
code_browse str
end
end | [
"def",
"choose_file_and_view",
"glob",
"=",
"nil",
",",
"startdir",
"=",
"\".\"",
"glob",
"||=",
"\"**/*.rb\"",
"str",
"=",
"choose_file",
"glob",
",",
":title",
"=>",
"\"Select a file\"",
",",
":directory",
"=>",
"startdir",
",",
":help_text",
"=>",
"\"Enter pattern, use UP DOWN to traverse, Backspace to delete, ENTER to select. Esc-Esc to quit\"",
"if",
"str",
"and",
"str",
"!=",
"\"\"",
"code_browse",
"str",
"end",
"end"
] | this should be available to view also. | [
"this",
"should",
"be",
"available",
"to",
"view",
"also",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/examples/common/devel.rb#L72-L80 |
23,841 | mare-imbrium/canis | examples/common/devel.rb | Canis.Devel.view_properties_as_tree | def view_properties_as_tree [email protected]_current_field
alert "Nil field" unless field
return unless field
text = []
tree = {}
#iv = field.instance_variables.map do |v| v.to_s; end
field.instance_variables.each do |v|
val = field.instance_variable_get(v)
klass = val.class
if val.is_a? Array
#tree[v.to_s] = val
text << { v.to_s => val }
val = val.size
elsif val.is_a? Hash
#tree[v.to_s] = val
text << { v.to_s => val }
if val.size <= 5
val = val.keys
else
val = val.keys.size.to_s + " [" + val.keys.first(5).join(", ") + " ...]"
end
end
case val
when String, Integer, TrueClass, FalseClass, NilClass, Array, Hash, Symbol
;
else
val = "Not shown"
end
text << "%-20s %10s %s" % [v, klass, val]
end
tree["Instance Variables"] = text
pm = field.public_methods(false).map do |v| v.to_s; end
tree["Public Methods"] = pm
pm = field.public_methods(true) - field.public_methods(false)
pm = pm.map do |v| v.to_s; end
tree["Inherited Methods"] = pm
#$log.debug " view_properties #{s.size} , #{s} "
treedialog tree, :title => "Properties"
end | ruby | def view_properties_as_tree [email protected]_current_field
alert "Nil field" unless field
return unless field
text = []
tree = {}
#iv = field.instance_variables.map do |v| v.to_s; end
field.instance_variables.each do |v|
val = field.instance_variable_get(v)
klass = val.class
if val.is_a? Array
#tree[v.to_s] = val
text << { v.to_s => val }
val = val.size
elsif val.is_a? Hash
#tree[v.to_s] = val
text << { v.to_s => val }
if val.size <= 5
val = val.keys
else
val = val.keys.size.to_s + " [" + val.keys.first(5).join(", ") + " ...]"
end
end
case val
when String, Integer, TrueClass, FalseClass, NilClass, Array, Hash, Symbol
;
else
val = "Not shown"
end
text << "%-20s %10s %s" % [v, klass, val]
end
tree["Instance Variables"] = text
pm = field.public_methods(false).map do |v| v.to_s; end
tree["Public Methods"] = pm
pm = field.public_methods(true) - field.public_methods(false)
pm = pm.map do |v| v.to_s; end
tree["Inherited Methods"] = pm
#$log.debug " view_properties #{s.size} , #{s} "
treedialog tree, :title => "Properties"
end | [
"def",
"view_properties_as_tree",
"field",
"=",
"@form",
".",
"get_current_field",
"alert",
"\"Nil field\"",
"unless",
"field",
"return",
"unless",
"field",
"text",
"=",
"[",
"]",
"tree",
"=",
"{",
"}",
"#iv = field.instance_variables.map do |v| v.to_s; end",
"field",
".",
"instance_variables",
".",
"each",
"do",
"|",
"v",
"|",
"val",
"=",
"field",
".",
"instance_variable_get",
"(",
"v",
")",
"klass",
"=",
"val",
".",
"class",
"if",
"val",
".",
"is_a?",
"Array",
"#tree[v.to_s] = val",
"text",
"<<",
"{",
"v",
".",
"to_s",
"=>",
"val",
"}",
"val",
"=",
"val",
".",
"size",
"elsif",
"val",
".",
"is_a?",
"Hash",
"#tree[v.to_s] = val",
"text",
"<<",
"{",
"v",
".",
"to_s",
"=>",
"val",
"}",
"if",
"val",
".",
"size",
"<=",
"5",
"val",
"=",
"val",
".",
"keys",
"else",
"val",
"=",
"val",
".",
"keys",
".",
"size",
".",
"to_s",
"+",
"\" [\"",
"+",
"val",
".",
"keys",
".",
"first",
"(",
"5",
")",
".",
"join",
"(",
"\", \"",
")",
"+",
"\" ...]\"",
"end",
"end",
"case",
"val",
"when",
"String",
",",
"Integer",
",",
"TrueClass",
",",
"FalseClass",
",",
"NilClass",
",",
"Array",
",",
"Hash",
",",
"Symbol",
";",
"else",
"val",
"=",
"\"Not shown\"",
"end",
"text",
"<<",
"\"%-20s %10s %s\"",
"%",
"[",
"v",
",",
"klass",
",",
"val",
"]",
"end",
"tree",
"[",
"\"Instance Variables\"",
"]",
"=",
"text",
"pm",
"=",
"field",
".",
"public_methods",
"(",
"false",
")",
".",
"map",
"do",
"|",
"v",
"|",
"v",
".",
"to_s",
";",
"end",
"tree",
"[",
"\"Public Methods\"",
"]",
"=",
"pm",
"pm",
"=",
"field",
".",
"public_methods",
"(",
"true",
")",
"-",
"field",
".",
"public_methods",
"(",
"false",
")",
"pm",
"=",
"pm",
".",
"map",
"do",
"|",
"v",
"|",
"v",
".",
"to_s",
";",
"end",
"tree",
"[",
"\"Inherited Methods\"",
"]",
"=",
"pm",
"#$log.debug \" view_properties #{s.size} , #{s} \"",
"treedialog",
"tree",
",",
":title",
"=>",
"\"Properties\"",
"end"
] | place instance_vars of current or given object into a hash
and view in a treedialog. | [
"place",
"instance_vars",
"of",
"current",
"or",
"given",
"object",
"into",
"a",
"hash",
"and",
"view",
"in",
"a",
"treedialog",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/examples/common/devel.rb#L124-L163 |
23,842 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.MenuSeparator.repaint | def repaint
acolor = get_color($reversecolor, @color, @bgcolor)
#@parent.window.printstring( @row, 0, "|%s|" % ("-"*@width), acolor)
@parent.window.mvwhline( @row, 1, Ncurses::ACS_HLINE, @width)
# these 2 are probably overwritten by the borders
@parent.window.mvaddch( @row, 0, Ncurses::ACS_LTEE)
@parent.window.mvaddch( @row, @width+1, Ncurses::ACS_RTEE)
end | ruby | def repaint
acolor = get_color($reversecolor, @color, @bgcolor)
#@parent.window.printstring( @row, 0, "|%s|" % ("-"*@width), acolor)
@parent.window.mvwhline( @row, 1, Ncurses::ACS_HLINE, @width)
# these 2 are probably overwritten by the borders
@parent.window.mvaddch( @row, 0, Ncurses::ACS_LTEE)
@parent.window.mvaddch( @row, @width+1, Ncurses::ACS_RTEE)
end | [
"def",
"repaint",
"acolor",
"=",
"get_color",
"(",
"$reversecolor",
",",
"@color",
",",
"@bgcolor",
")",
"#@parent.window.printstring( @row, 0, \"|%s|\" % (\"-\"*@width), acolor)",
"@parent",
".",
"window",
".",
"mvwhline",
"(",
"@row",
",",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"@width",
")",
"# these 2 are probably overwritten by the borders",
"@parent",
".",
"window",
".",
"mvaddch",
"(",
"@row",
",",
"0",
",",
"Ncurses",
"::",
"ACS_LTEE",
")",
"@parent",
".",
"window",
".",
"mvaddch",
"(",
"@row",
",",
"@width",
"+",
"1",
",",
"Ncurses",
"::",
"ACS_RTEE",
")",
"end"
] | 2011-09-25 V1.3.1 | [
"2011",
"-",
"09",
"-",
"25",
"V1",
".",
"3",
".",
"1"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L47-L54 |
23,843 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.Menu.select_item | def select_item ix0
return if @items.nil? or @items.empty?
#$log.debug "insdie select item : #{ix0} active: #{@active_index}"
if !@active_index.nil?
@items[@active_index].on_leave
end
previtem = @active_index
@active_index = ix0
if @items[ix0].enabled
@items[ix0].on_enter
else
#$log.debug "insdie sele nxt item ENABLED FALSE : #{ix0}"
if @active_index > previtem
select_next_item
else
select_prev_item
end
end
@window.refresh
end | ruby | def select_item ix0
return if @items.nil? or @items.empty?
#$log.debug "insdie select item : #{ix0} active: #{@active_index}"
if !@active_index.nil?
@items[@active_index].on_leave
end
previtem = @active_index
@active_index = ix0
if @items[ix0].enabled
@items[ix0].on_enter
else
#$log.debug "insdie sele nxt item ENABLED FALSE : #{ix0}"
if @active_index > previtem
select_next_item
else
select_prev_item
end
end
@window.refresh
end | [
"def",
"select_item",
"ix0",
"return",
"if",
"@items",
".",
"nil?",
"or",
"@items",
".",
"empty?",
"#$log.debug \"insdie select item : #{ix0} active: #{@active_index}\" ",
"if",
"!",
"@active_index",
".",
"nil?",
"@items",
"[",
"@active_index",
"]",
".",
"on_leave",
"end",
"previtem",
"=",
"@active_index",
"@active_index",
"=",
"ix0",
"if",
"@items",
"[",
"ix0",
"]",
".",
"enabled",
"@items",
"[",
"ix0",
"]",
".",
"on_enter",
"else",
"#$log.debug \"insdie sele nxt item ENABLED FALSE : #{ix0}\" ",
"if",
"@active_index",
">",
"previtem",
"select_next_item",
"else",
"select_prev_item",
"end",
"end",
"@window",
".",
"refresh",
"end"
] | recursive if given one not enabled goes to next enabled | [
"recursive",
"if",
"given",
"one",
"not",
"enabled",
"goes",
"to",
"next",
"enabled"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L336-L355 |
23,844 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.Menu.array_width | def array_width a
longest = a.max {|a,b| a.to_s.length <=> b.to_s.length }
#$log.debug "array width #{longest}"
longest.to_s.length
end | ruby | def array_width a
longest = a.max {|a,b| a.to_s.length <=> b.to_s.length }
#$log.debug "array width #{longest}"
longest.to_s.length
end | [
"def",
"array_width",
"a",
"longest",
"=",
"a",
".",
"max",
"{",
"|",
"a",
",",
"b",
"|",
"a",
".",
"to_s",
".",
"length",
"<=>",
"b",
".",
"to_s",
".",
"length",
"}",
"#$log.debug \"array width #{longest}\"",
"longest",
".",
"to_s",
".",
"length",
"end"
] | private
returns length of longest item in array | [
"private",
"returns",
"length",
"of",
"longest",
"item",
"in",
"array"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L542-L546 |
23,845 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.Menu.handle_key | def handle_key ch
if !@current_menu.empty?
cmenu = @current_menu.last
else
cmenu = self
end
if !@@menus.empty?
cmenu = @@menus.last
else
cmenu = self
end
case ch
when KEY_DOWN
cmenu.select_next_item
#return cmenu.fire # XXX 2010-10-16 21:39 trying out
if cmenu.is_a? Canis::Menu
#alert "is a menu" # this gets triggered even when we are on items
end
when KEY_UP
cmenu.select_prev_item
when KEY_ENTER, 10, 13, 32 # added 32 2008-11-27 23:50
return cmenu.fire
when KEY_LEFT
if cmenu.parent.is_a? Canis::Menu
#$log.debug "LEFT IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}"
#$log.debug "left IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}"
end
ret = cmenu.select_left_item # 2011-09-24 V1.3.1 attempt to goto left item if columns
if ret == :UNHANDLED
if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.parent.current_menu.empty?
#$log.debug " ABOU TO DESTROY DUE TO LEFT"
cmenu.current_menu.pop
@@menus.pop ## NEW
cmenu.destroy
return :UNHANDLED
end
# LEFT on a menu list allows me to close and return to higher level
if cmenu.parent.is_a? Canis::Menu #and !cmenu.parent.current_menu.empty?
#$log.debug " ABOU TO DESTROY DUE TO LEFT"
cmenu.current_menu.pop
@@menus.pop ## NEW
cmenu.destroy
#return :UNHANDLED
end
end
when KEY_RIGHT
$log.debug "RIGHTIN MENU : #{text} "
if cmenu.active_index
if cmenu.items[cmenu.active_index].is_a? Canis::Menu
#alert "could fire here cmenu: #{cmenu.text}, par: #{cmenu.parent.text} "
cmenu.fire
return
#$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}"
#$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}"
end
end
# This introduces a bug if no open items
ret = cmenu.select_right_item # 2011-09-24 V1.3.1 attempt to goto right item if columns
#alert "attempting to select right #{ret} "
if ret == :UNHANDLED
#if cmenu.parent.is_a? Canis::Menu and !cmenu.parent.current_menu.empty?
if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.current_menu.empty?
$log.debug " ABOU TO DESTROY DUE TO RIGHT"
cmenu.current_menu.pop
@@menus.pop
cmenu.destroy
return :UNHANDLED
end
end
else
ret = check_mnemonics cmenu, ch
return ret
end
end | ruby | def handle_key ch
if !@current_menu.empty?
cmenu = @current_menu.last
else
cmenu = self
end
if !@@menus.empty?
cmenu = @@menus.last
else
cmenu = self
end
case ch
when KEY_DOWN
cmenu.select_next_item
#return cmenu.fire # XXX 2010-10-16 21:39 trying out
if cmenu.is_a? Canis::Menu
#alert "is a menu" # this gets triggered even when we are on items
end
when KEY_UP
cmenu.select_prev_item
when KEY_ENTER, 10, 13, 32 # added 32 2008-11-27 23:50
return cmenu.fire
when KEY_LEFT
if cmenu.parent.is_a? Canis::Menu
#$log.debug "LEFT IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}"
#$log.debug "left IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}"
end
ret = cmenu.select_left_item # 2011-09-24 V1.3.1 attempt to goto left item if columns
if ret == :UNHANDLED
if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.parent.current_menu.empty?
#$log.debug " ABOU TO DESTROY DUE TO LEFT"
cmenu.current_menu.pop
@@menus.pop ## NEW
cmenu.destroy
return :UNHANDLED
end
# LEFT on a menu list allows me to close and return to higher level
if cmenu.parent.is_a? Canis::Menu #and !cmenu.parent.current_menu.empty?
#$log.debug " ABOU TO DESTROY DUE TO LEFT"
cmenu.current_menu.pop
@@menus.pop ## NEW
cmenu.destroy
#return :UNHANDLED
end
end
when KEY_RIGHT
$log.debug "RIGHTIN MENU : #{text} "
if cmenu.active_index
if cmenu.items[cmenu.active_index].is_a? Canis::Menu
#alert "could fire here cmenu: #{cmenu.text}, par: #{cmenu.parent.text} "
cmenu.fire
return
#$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}"
#$log.debug "right IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}"
end
end
# This introduces a bug if no open items
ret = cmenu.select_right_item # 2011-09-24 V1.3.1 attempt to goto right item if columns
#alert "attempting to select right #{ret} "
if ret == :UNHANDLED
#if cmenu.parent.is_a? Canis::Menu and !cmenu.parent.current_menu.empty?
if cmenu.parent.is_a? Canis::MenuBar #and !cmenu.current_menu.empty?
$log.debug " ABOU TO DESTROY DUE TO RIGHT"
cmenu.current_menu.pop
@@menus.pop
cmenu.destroy
return :UNHANDLED
end
end
else
ret = check_mnemonics cmenu, ch
return ret
end
end | [
"def",
"handle_key",
"ch",
"if",
"!",
"@current_menu",
".",
"empty?",
"cmenu",
"=",
"@current_menu",
".",
"last",
"else",
"cmenu",
"=",
"self",
"end",
"if",
"!",
"@@menus",
".",
"empty?",
"cmenu",
"=",
"@@menus",
".",
"last",
"else",
"cmenu",
"=",
"self",
"end",
"case",
"ch",
"when",
"KEY_DOWN",
"cmenu",
".",
"select_next_item",
"#return cmenu.fire # XXX 2010-10-16 21:39 trying out",
"if",
"cmenu",
".",
"is_a?",
"Canis",
"::",
"Menu",
"#alert \"is a menu\" # this gets triggered even when we are on items",
"end",
"when",
"KEY_UP",
"cmenu",
".",
"select_prev_item",
"when",
"KEY_ENTER",
",",
"10",
",",
"13",
",",
"32",
"# added 32 2008-11-27 23:50 ",
"return",
"cmenu",
".",
"fire",
"when",
"KEY_LEFT",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"Menu",
"#$log.debug \"LEFT IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}\"",
"#$log.debug \"left IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}\"",
"end",
"ret",
"=",
"cmenu",
".",
"select_left_item",
"# 2011-09-24 V1.3.1 attempt to goto left item if columns",
"if",
"ret",
"==",
":UNHANDLED",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"MenuBar",
"#and !cmenu.parent.current_menu.empty?",
"#$log.debug \" ABOU TO DESTROY DUE TO LEFT\"",
"cmenu",
".",
"current_menu",
".",
"pop",
"@@menus",
".",
"pop",
"## NEW",
"cmenu",
".",
"destroy",
"return",
":UNHANDLED",
"end",
"# LEFT on a menu list allows me to close and return to higher level",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"Menu",
"#and !cmenu.parent.current_menu.empty?",
"#$log.debug \" ABOU TO DESTROY DUE TO LEFT\"",
"cmenu",
".",
"current_menu",
".",
"pop",
"@@menus",
".",
"pop",
"## NEW",
"cmenu",
".",
"destroy",
"#return :UNHANDLED",
"end",
"end",
"when",
"KEY_RIGHT",
"$log",
".",
"debug",
"\"RIGHTIN MENU : #{text} \"",
"if",
"cmenu",
".",
"active_index",
"if",
"cmenu",
".",
"items",
"[",
"cmenu",
".",
"active_index",
"]",
".",
"is_a?",
"Canis",
"::",
"Menu",
"#alert \"could fire here cmenu: #{cmenu.text}, par: #{cmenu.parent.text} \"",
"cmenu",
".",
"fire",
"return",
"#$log.debug \"right IN MENU : #{cmenu.parent.class} len: #{cmenu.parent.current_menu.length}\"",
"#$log.debug \"right IN MENU : #{cmenu.parent.class} len: #{cmenu.current_menu.length}\"",
"end",
"end",
"# This introduces a bug if no open items",
"ret",
"=",
"cmenu",
".",
"select_right_item",
"# 2011-09-24 V1.3.1 attempt to goto right item if columns",
"#alert \"attempting to select right #{ret} \"",
"if",
"ret",
"==",
":UNHANDLED",
"#if cmenu.parent.is_a? Canis::Menu and !cmenu.parent.current_menu.empty?",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"MenuBar",
"#and !cmenu.current_menu.empty?",
"$log",
".",
"debug",
"\" ABOU TO DESTROY DUE TO RIGHT\"",
"cmenu",
".",
"current_menu",
".",
"pop",
"@@menus",
".",
"pop",
"cmenu",
".",
"destroy",
"return",
":UNHANDLED",
"end",
"end",
"else",
"ret",
"=",
"check_mnemonics",
"cmenu",
",",
"ch",
"return",
"ret",
"end",
"end"
] | menu LEFT, RIGHT, DOWN, UP, ENTER
item could be menuitem or another menu | [
"menu",
"LEFT",
"RIGHT",
"DOWN",
"UP",
"ENTER",
"item",
"could",
"be",
"menuitem",
"or",
"another",
"menu"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L565-L638 |
23,846 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.MenuBar.set_menu | def set_menu index
#$log.debug "set meu: #{@active_index} #{index}"
# first leave the existing window
menu = @items[@active_index]
menu.on_leave # hide its window, if open
# now move to given menu
@active_index = index
menu = @items[@active_index]
menu.on_enter #display window, if previous was displayed
# move cursor to selected menu option on top, not inside list
@window.wmove menu.row, menu.col
# menu.show
# menu.window.wrefresh # XXX we need this
end | ruby | def set_menu index
#$log.debug "set meu: #{@active_index} #{index}"
# first leave the existing window
menu = @items[@active_index]
menu.on_leave # hide its window, if open
# now move to given menu
@active_index = index
menu = @items[@active_index]
menu.on_enter #display window, if previous was displayed
# move cursor to selected menu option on top, not inside list
@window.wmove menu.row, menu.col
# menu.show
# menu.window.wrefresh # XXX we need this
end | [
"def",
"set_menu",
"index",
"#$log.debug \"set meu: #{@active_index} #{index}\" ",
"# first leave the existing window",
"menu",
"=",
"@items",
"[",
"@active_index",
"]",
"menu",
".",
"on_leave",
"# hide its window, if open",
"# now move to given menu",
"@active_index",
"=",
"index",
"menu",
"=",
"@items",
"[",
"@active_index",
"]",
"menu",
".",
"on_enter",
"#display window, if previous was displayed",
"# move cursor to selected menu option on top, not inside list",
"@window",
".",
"wmove",
"menu",
".",
"row",
",",
"menu",
".",
"col",
"# menu.show",
"# menu.window.wrefresh # XXX we need this",
"end"
] | set the given menu index as the current or active menu
after closing the active menu.
@param Integer index of menu to activate, starting 0 | [
"set",
"the",
"given",
"menu",
"index",
"as",
"the",
"current",
"or",
"active",
"menu",
"after",
"closing",
"the",
"active",
"menu",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L738-L751 |
23,847 | mare-imbrium/canis | lib/canis/core/widgets/rmenu.rb | Canis.MenuBar.handle_keys | def handle_keys
@selected = false
@repaint_required = true # added 2011-12-12 otherwise keeps repainting and you see a flicker
@toggle_key ||= 27 # default switch off with ESC, if nothing else defined
set_menu 0
begin
catch(:menubarclose) do
while((ch = @window.getchar()) != @toggle_key )
#$log.debug "menuubar inside handle_keys : #{ch}" if ch != -1
case ch
when -1
next
when KEY_DOWN
if !@selected
current_menu.fire
else
current_menu.handle_key ch
end
@selected = true
when KEY_ENTER, 10, 13, 32
@selected = true
ret = current_menu.handle_key ch
#break; ## 2008-12-29 18:00 This will close after firing anything
break if ret == :CLOSE
when KEY_UP
current_menu.handle_key ch
when KEY_LEFT
ret = current_menu.handle_key ch
prev_menu if ret == :UNHANDLED
when KEY_RIGHT
ret = current_menu.handle_key ch
next_menu if ret == :UNHANDLED
when ?\C-g.getbyte(0) # abort
throw :menubarclose
else
ret = current_menu.handle_key ch
if ret == :UNHANDLED
Ncurses.beep
else
break # we handled a menu action, close menubar (THIS WORKS FOR MNEMONICS ONLY and always)
end
end
Ncurses::Panel.update_panels();
Ncurses.doupdate();
@window.wrefresh
end
end # catch
ensure
#ensure is required becos one can throw a :close
$log.debug " DESTROY IN ENSURE"
current_menu.clear_menus
@repaint_required = false
destroy # Note that we destroy the menu bar upon exit
end
end | ruby | def handle_keys
@selected = false
@repaint_required = true # added 2011-12-12 otherwise keeps repainting and you see a flicker
@toggle_key ||= 27 # default switch off with ESC, if nothing else defined
set_menu 0
begin
catch(:menubarclose) do
while((ch = @window.getchar()) != @toggle_key )
#$log.debug "menuubar inside handle_keys : #{ch}" if ch != -1
case ch
when -1
next
when KEY_DOWN
if !@selected
current_menu.fire
else
current_menu.handle_key ch
end
@selected = true
when KEY_ENTER, 10, 13, 32
@selected = true
ret = current_menu.handle_key ch
#break; ## 2008-12-29 18:00 This will close after firing anything
break if ret == :CLOSE
when KEY_UP
current_menu.handle_key ch
when KEY_LEFT
ret = current_menu.handle_key ch
prev_menu if ret == :UNHANDLED
when KEY_RIGHT
ret = current_menu.handle_key ch
next_menu if ret == :UNHANDLED
when ?\C-g.getbyte(0) # abort
throw :menubarclose
else
ret = current_menu.handle_key ch
if ret == :UNHANDLED
Ncurses.beep
else
break # we handled a menu action, close menubar (THIS WORKS FOR MNEMONICS ONLY and always)
end
end
Ncurses::Panel.update_panels();
Ncurses.doupdate();
@window.wrefresh
end
end # catch
ensure
#ensure is required becos one can throw a :close
$log.debug " DESTROY IN ENSURE"
current_menu.clear_menus
@repaint_required = false
destroy # Note that we destroy the menu bar upon exit
end
end | [
"def",
"handle_keys",
"@selected",
"=",
"false",
"@repaint_required",
"=",
"true",
"# added 2011-12-12 otherwise keeps repainting and you see a flicker",
"@toggle_key",
"||=",
"27",
"# default switch off with ESC, if nothing else defined",
"set_menu",
"0",
"begin",
"catch",
"(",
":menubarclose",
")",
"do",
"while",
"(",
"(",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
")",
"!=",
"@toggle_key",
")",
"#$log.debug \"menuubar inside handle_keys : #{ch}\" if ch != -1",
"case",
"ch",
"when",
"-",
"1",
"next",
"when",
"KEY_DOWN",
"if",
"!",
"@selected",
"current_menu",
".",
"fire",
"else",
"current_menu",
".",
"handle_key",
"ch",
"end",
"@selected",
"=",
"true",
"when",
"KEY_ENTER",
",",
"10",
",",
"13",
",",
"32",
"@selected",
"=",
"true",
"ret",
"=",
"current_menu",
".",
"handle_key",
"ch",
"#break; ## 2008-12-29 18:00 This will close after firing anything",
"break",
"if",
"ret",
"==",
":CLOSE",
"when",
"KEY_UP",
"current_menu",
".",
"handle_key",
"ch",
"when",
"KEY_LEFT",
"ret",
"=",
"current_menu",
".",
"handle_key",
"ch",
"prev_menu",
"if",
"ret",
"==",
":UNHANDLED",
"when",
"KEY_RIGHT",
"ret",
"=",
"current_menu",
".",
"handle_key",
"ch",
"next_menu",
"if",
"ret",
"==",
":UNHANDLED",
"when",
"?\\C-g",
".",
"getbyte",
"(",
"0",
")",
"# abort",
"throw",
":menubarclose",
"else",
"ret",
"=",
"current_menu",
".",
"handle_key",
"ch",
"if",
"ret",
"==",
":UNHANDLED",
"Ncurses",
".",
"beep",
"else",
"break",
"# we handled a menu action, close menubar (THIS WORKS FOR MNEMONICS ONLY and always)",
"end",
"end",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"(",
")",
";",
"Ncurses",
".",
"doupdate",
"(",
")",
";",
"@window",
".",
"wrefresh",
"end",
"end",
"# catch",
"ensure",
"#ensure is required becos one can throw a :close",
"$log",
".",
"debug",
"\" DESTROY IN ENSURE\"",
"current_menu",
".",
"clear_menus",
"@repaint_required",
"=",
"false",
"destroy",
"# Note that we destroy the menu bar upon exit",
"end",
"end"
] | menubar LEFT, RIGHT, DOWN | [
"menubar",
"LEFT",
"RIGHT",
"DOWN"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/rmenu.rb#L764-L821 |
23,848 | mare-imbrium/canis | lib/canis/core/widgets/keylabelprinter.rb | Canis.KeyLabelPrinter.update_application_key_label | def update_application_key_label(display_code, new_display_code, text)
@repaint_required = true
labels = key_labels()
raise "labels are nil !!!" unless labels
labels.each_index do |ix|
lab = labels[ix]
next if lab.nil?
if lab[0] == display_code
labels[ix] = [new_display_code , text]
$log.debug("updated #{labels[ix]}")
return true
end
end
return false
end | ruby | def update_application_key_label(display_code, new_display_code, text)
@repaint_required = true
labels = key_labels()
raise "labels are nil !!!" unless labels
labels.each_index do |ix|
lab = labels[ix]
next if lab.nil?
if lab[0] == display_code
labels[ix] = [new_display_code , text]
$log.debug("updated #{labels[ix]}")
return true
end
end
return false
end | [
"def",
"update_application_key_label",
"(",
"display_code",
",",
"new_display_code",
",",
"text",
")",
"@repaint_required",
"=",
"true",
"labels",
"=",
"key_labels",
"(",
")",
"raise",
"\"labels are nil !!!\"",
"unless",
"labels",
"labels",
".",
"each_index",
"do",
"|",
"ix",
"|",
"lab",
"=",
"labels",
"[",
"ix",
"]",
"next",
"if",
"lab",
".",
"nil?",
"if",
"lab",
"[",
"0",
"]",
"==",
"display_code",
"labels",
"[",
"ix",
"]",
"=",
"[",
"new_display_code",
",",
"text",
"]",
"$log",
".",
"debug",
"(",
"\"updated #{labels[ix]}\"",
")",
"return",
"true",
"end",
"end",
"return",
"false",
"end"
] | updates existing label with a new one.
@return true if updated, else false
@example update "C-x", "C-x", "Disable" | [
"updates",
"existing",
"label",
"with",
"a",
"new",
"one",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/keylabelprinter.rb#L167-L181 |
23,849 | mare-imbrium/canis | lib/canis/core/widgets/extras/stackflow.rb | RubyCurses.StackFlow.handle_key | def handle_key ch
$log.debug " STACKFLOW handle_key #{ch} "
return if @components.empty?
_multiplier = ($multiplier == 0 ? 1 : $multiplier )
# should this go here 2011-10-19
unless @_entered
$log.warn "XXX WARN: calling ON_ENTER since in this situation it was not called"
on_enter
end
if ch == KEY_TAB
$log.debug "STACKFLOW GOTO NEXT TAB"
return goto_next_component
elsif ch == KEY_BTAB
return goto_prev_component
end
comp = @current_component
$log.debug " STACKFLOW handle_key #{ch}: #{comp}"
if comp
ret = comp.handle_key(ch)
$log.debug " STACKFLOW handle_key#{ch}: #{comp} returned #{ret} "
if ret != :UNHANDLED
comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL
# in repaint of this.
return ret
end
$log.debug "XXX STACKFLOW key unhandled by comp #{comp.name} "
else
$log.warn "XXX STACKFLOW key unhandled NULL comp"
end
case ch
when ?\C-c.getbyte(0)
$multiplier = 0
return 0
when ?0.getbyte(0)..?9.getbyte(0)
$log.debug " VIM coming here to set multiplier #{$multiplier} "
$multiplier *= 10 ; $multiplier += (ch-48)
return 0
end
ret = process_key ch, self
# allow user to map left and right if he wants
if ret == :UNHANDLED
case ch
when KEY_UP
# form will pick this up and do needful
return goto_prev_component #unless on_first_component?
when KEY_LEFT
# if i don't check for first component, key will go back to form,
# but not be processes. so focussed remain here, but be false.
# In case of returnign an unhandled TAB, on_leave will happen and cursor will move to
# previous component outside of this.
return goto_prev_component unless on_first_component?
when KEY_RIGHT
return goto_next_component #unless on_last_component?
when KEY_DOWN
return goto_next_component #unless on_last_component?
else
@_entered = false
return :UNHANDLED
end
end
$multiplier = 0
return 0
end | ruby | def handle_key ch
$log.debug " STACKFLOW handle_key #{ch} "
return if @components.empty?
_multiplier = ($multiplier == 0 ? 1 : $multiplier )
# should this go here 2011-10-19
unless @_entered
$log.warn "XXX WARN: calling ON_ENTER since in this situation it was not called"
on_enter
end
if ch == KEY_TAB
$log.debug "STACKFLOW GOTO NEXT TAB"
return goto_next_component
elsif ch == KEY_BTAB
return goto_prev_component
end
comp = @current_component
$log.debug " STACKFLOW handle_key #{ch}: #{comp}"
if comp
ret = comp.handle_key(ch)
$log.debug " STACKFLOW handle_key#{ch}: #{comp} returned #{ret} "
if ret != :UNHANDLED
comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL
# in repaint of this.
return ret
end
$log.debug "XXX STACKFLOW key unhandled by comp #{comp.name} "
else
$log.warn "XXX STACKFLOW key unhandled NULL comp"
end
case ch
when ?\C-c.getbyte(0)
$multiplier = 0
return 0
when ?0.getbyte(0)..?9.getbyte(0)
$log.debug " VIM coming here to set multiplier #{$multiplier} "
$multiplier *= 10 ; $multiplier += (ch-48)
return 0
end
ret = process_key ch, self
# allow user to map left and right if he wants
if ret == :UNHANDLED
case ch
when KEY_UP
# form will pick this up and do needful
return goto_prev_component #unless on_first_component?
when KEY_LEFT
# if i don't check for first component, key will go back to form,
# but not be processes. so focussed remain here, but be false.
# In case of returnign an unhandled TAB, on_leave will happen and cursor will move to
# previous component outside of this.
return goto_prev_component unless on_first_component?
when KEY_RIGHT
return goto_next_component #unless on_last_component?
when KEY_DOWN
return goto_next_component #unless on_last_component?
else
@_entered = false
return :UNHANDLED
end
end
$multiplier = 0
return 0
end | [
"def",
"handle_key",
"ch",
"$log",
".",
"debug",
"\" STACKFLOW handle_key #{ch} \"",
"return",
"if",
"@components",
".",
"empty?",
"_multiplier",
"=",
"(",
"$multiplier",
"==",
"0",
"?",
"1",
":",
"$multiplier",
")",
"# should this go here 2011-10-19 ",
"unless",
"@_entered",
"$log",
".",
"warn",
"\"XXX WARN: calling ON_ENTER since in this situation it was not called\"",
"on_enter",
"end",
"if",
"ch",
"==",
"KEY_TAB",
"$log",
".",
"debug",
"\"STACKFLOW GOTO NEXT TAB\"",
"return",
"goto_next_component",
"elsif",
"ch",
"==",
"KEY_BTAB",
"return",
"goto_prev_component",
"end",
"comp",
"=",
"@current_component",
"$log",
".",
"debug",
"\" STACKFLOW handle_key #{ch}: #{comp}\"",
"if",
"comp",
"ret",
"=",
"comp",
".",
"handle_key",
"(",
"ch",
")",
"$log",
".",
"debug",
"\" STACKFLOW handle_key#{ch}: #{comp} returned #{ret} \"",
"if",
"ret",
"!=",
":UNHANDLED",
"comp",
".",
"repaint",
"# NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL",
"# in repaint of this.",
"return",
"ret",
"end",
"$log",
".",
"debug",
"\"XXX STACKFLOW key unhandled by comp #{comp.name} \"",
"else",
"$log",
".",
"warn",
"\"XXX STACKFLOW key unhandled NULL comp\"",
"end",
"case",
"ch",
"when",
"?\\C-c",
".",
"getbyte",
"(",
"0",
")",
"$multiplier",
"=",
"0",
"return",
"0",
"when",
"?0",
".",
"getbyte",
"(",
"0",
")",
"..",
"?9",
".",
"getbyte",
"(",
"0",
")",
"$log",
".",
"debug",
"\" VIM coming here to set multiplier #{$multiplier} \"",
"$multiplier",
"*=",
"10",
";",
"$multiplier",
"+=",
"(",
"ch",
"-",
"48",
")",
"return",
"0",
"end",
"ret",
"=",
"process_key",
"ch",
",",
"self",
"# allow user to map left and right if he wants",
"if",
"ret",
"==",
":UNHANDLED",
"case",
"ch",
"when",
"KEY_UP",
"# form will pick this up and do needful",
"return",
"goto_prev_component",
"#unless on_first_component?",
"when",
"KEY_LEFT",
"# if i don't check for first component, key will go back to form,",
"# but not be processes. so focussed remain here, but be false.",
"# In case of returnign an unhandled TAB, on_leave will happen and cursor will move to ",
"# previous component outside of this.",
"return",
"goto_prev_component",
"unless",
"on_first_component?",
"when",
"KEY_RIGHT",
"return",
"goto_next_component",
"#unless on_last_component?",
"when",
"KEY_DOWN",
"return",
"goto_next_component",
"#unless on_last_component?",
"else",
"@_entered",
"=",
"false",
"return",
":UNHANDLED",
"end",
"end",
"$multiplier",
"=",
"0",
"return",
"0",
"end"
] | called by parent or form, otherwise its private | [
"called",
"by",
"parent",
"or",
"form",
"otherwise",
"its",
"private"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/stackflow.rb#L227-L291 |
23,850 | mare-imbrium/canis | lib/canis/core/widgets/extras/stackflow.rb | RubyCurses.StackFlow.leave_current_component | def leave_current_component
begin
@current_component.on_leave
rescue FieldValidationException => fve
alert fve.to_s
end
# NOTE this is required, since repaint will just not happen otherwise
# Some components are erroneously repainting all, after setting this to true so it is
# working there.
@current_component.repaint_required true
$log.debug " after on_leave STACKFLOW XXX #{@current_component.focussed} #{@current_component.name}"
@current_component.repaint
end | ruby | def leave_current_component
begin
@current_component.on_leave
rescue FieldValidationException => fve
alert fve.to_s
end
# NOTE this is required, since repaint will just not happen otherwise
# Some components are erroneously repainting all, after setting this to true so it is
# working there.
@current_component.repaint_required true
$log.debug " after on_leave STACKFLOW XXX #{@current_component.focussed} #{@current_component.name}"
@current_component.repaint
end | [
"def",
"leave_current_component",
"begin",
"@current_component",
".",
"on_leave",
"rescue",
"FieldValidationException",
"=>",
"fve",
"alert",
"fve",
".",
"to_s",
"end",
"# NOTE this is required, since repaint will just not happen otherwise",
"# Some components are erroneously repainting all, after setting this to true so it is ",
"# working there. ",
"@current_component",
".",
"repaint_required",
"true",
"$log",
".",
"debug",
"\" after on_leave STACKFLOW XXX #{@current_component.focussed} #{@current_component.name}\"",
"@current_component",
".",
"repaint",
"end"
] | leave the component we are on.
This should be followed by all containers, so that the on_leave action
of earlier comp can be displayed, such as dimming components selections | [
"leave",
"the",
"component",
"we",
"are",
"on",
".",
"This",
"should",
"be",
"followed",
"by",
"all",
"containers",
"so",
"that",
"the",
"on_leave",
"action",
"of",
"earlier",
"comp",
"can",
"be",
"displayed",
"such",
"as",
"dimming",
"components",
"selections"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/stackflow.rb#L379-L391 |
23,851 | mare-imbrium/canis | lib/canis/core/include/deprecated/listselectable.rb | Canis.NewListSelectable.add_to_selection | def add_to_selection crow=@current_index-@_header_adjustment
@last_clicked ||= crow
min = [@last_clicked, crow].min
max = [@last_clicked, crow].max
case @selection_mode
when :multiple
@widget_scrolled = true # FIXME we need a better name
if @selected_indices.include? crow
# delete from last_clicked until this one in any direction
min.upto(max){ |i| @selected_indices.delete i }
lse = ListSelectionEvent.new(min, max, self, :DELETE)
fire_handler :LIST_SELECTION_EVENT, lse
else
# add to selection from last_clicked until this one in any direction
min.upto(max){ |i| @selected_indices << i unless @selected_indices.include?(i) }
lse = ListSelectionEvent.new(min, max, self, :INSERT)
fire_handler :LIST_SELECTION_EVENT, lse
end
else
end
@repaint_required = true
self
end | ruby | def add_to_selection crow=@current_index-@_header_adjustment
@last_clicked ||= crow
min = [@last_clicked, crow].min
max = [@last_clicked, crow].max
case @selection_mode
when :multiple
@widget_scrolled = true # FIXME we need a better name
if @selected_indices.include? crow
# delete from last_clicked until this one in any direction
min.upto(max){ |i| @selected_indices.delete i }
lse = ListSelectionEvent.new(min, max, self, :DELETE)
fire_handler :LIST_SELECTION_EVENT, lse
else
# add to selection from last_clicked until this one in any direction
min.upto(max){ |i| @selected_indices << i unless @selected_indices.include?(i) }
lse = ListSelectionEvent.new(min, max, self, :INSERT)
fire_handler :LIST_SELECTION_EVENT, lse
end
else
end
@repaint_required = true
self
end | [
"def",
"add_to_selection",
"crow",
"=",
"@current_index",
"-",
"@_header_adjustment",
"@last_clicked",
"||=",
"crow",
"min",
"=",
"[",
"@last_clicked",
",",
"crow",
"]",
".",
"min",
"max",
"=",
"[",
"@last_clicked",
",",
"crow",
"]",
".",
"max",
"case",
"@selection_mode",
"when",
":multiple",
"@widget_scrolled",
"=",
"true",
"# FIXME we need a better name",
"if",
"@selected_indices",
".",
"include?",
"crow",
"# delete from last_clicked until this one in any direction",
"min",
".",
"upto",
"(",
"max",
")",
"{",
"|",
"i",
"|",
"@selected_indices",
".",
"delete",
"i",
"}",
"lse",
"=",
"ListSelectionEvent",
".",
"new",
"(",
"min",
",",
"max",
",",
"self",
",",
":DELETE",
")",
"fire_handler",
":LIST_SELECTION_EVENT",
",",
"lse",
"else",
"# add to selection from last_clicked until this one in any direction",
"min",
".",
"upto",
"(",
"max",
")",
"{",
"|",
"i",
"|",
"@selected_indices",
"<<",
"i",
"unless",
"@selected_indices",
".",
"include?",
"(",
"i",
")",
"}",
"lse",
"=",
"ListSelectionEvent",
".",
"new",
"(",
"min",
",",
"max",
",",
"self",
",",
":INSERT",
")",
"fire_handler",
":LIST_SELECTION_EVENT",
",",
"lse",
"end",
"else",
"end",
"@repaint_required",
"=",
"true",
"self",
"end"
] | Only for multiple mode.
add an item to selection, if selection mode is multiple
if item already selected, it is deselected, else selected
typically bound to Ctrl-Space
@example
bind_key(0) { add_to_selection } | [
"Only",
"for",
"multiple",
"mode",
".",
"add",
"an",
"item",
"to",
"selection",
"if",
"selection",
"mode",
"is",
"multiple",
"if",
"item",
"already",
"selected",
"it",
"is",
"deselected",
"else",
"selected",
"typically",
"bound",
"to",
"Ctrl",
"-",
"Space"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/deprecated/listselectable.rb#L57-L79 |
23,852 | mare-imbrium/canis | lib/canis/core/include/deprecated/listselectable.rb | Canis.NewListSelectable.list_bindings | def list_bindings
# what about users wanting 32 and ENTER to also go to next row automatically
# should make that optional, TODO
bind_key($row_selector || 32, 'toggle selection') { toggle_row_selection }
# 2013-03-24 - 14:46 added condition so single select does not get these
if @selection_mode == :multiple
bind_key(0, 'range select') { add_to_selection }
bind_key(?+, :ask_select) # --> calls select_values
bind_key(?-, :ask_unselect) # please implement FIXME TODO
bind_key(?a, :select_all)
bind_key(?*, :invert_selection)
bind_key(?u, :clear_selection)
end
@_header_adjustment ||= 0 # incase caller does not use
@_events << :LIST_SELECTION_EVENT unless @_events.include? :LIST_SELECTION_EVENT
end | ruby | def list_bindings
# what about users wanting 32 and ENTER to also go to next row automatically
# should make that optional, TODO
bind_key($row_selector || 32, 'toggle selection') { toggle_row_selection }
# 2013-03-24 - 14:46 added condition so single select does not get these
if @selection_mode == :multiple
bind_key(0, 'range select') { add_to_selection }
bind_key(?+, :ask_select) # --> calls select_values
bind_key(?-, :ask_unselect) # please implement FIXME TODO
bind_key(?a, :select_all)
bind_key(?*, :invert_selection)
bind_key(?u, :clear_selection)
end
@_header_adjustment ||= 0 # incase caller does not use
@_events << :LIST_SELECTION_EVENT unless @_events.include? :LIST_SELECTION_EVENT
end | [
"def",
"list_bindings",
"# what about users wanting 32 and ENTER to also go to next row automatically",
"# should make that optional, TODO",
"bind_key",
"(",
"$row_selector",
"||",
"32",
",",
"'toggle selection'",
")",
"{",
"toggle_row_selection",
"}",
"# 2013-03-24 - 14:46 added condition so single select does not get these",
"if",
"@selection_mode",
"==",
":multiple",
"bind_key",
"(",
"0",
",",
"'range select'",
")",
"{",
"add_to_selection",
"}",
"bind_key",
"(",
"?+",
",",
":ask_select",
")",
"# --> calls select_values",
"bind_key",
"(",
"?-",
",",
":ask_unselect",
")",
"# please implement FIXME TODO",
"bind_key",
"(",
"?a",
",",
":select_all",
")",
"bind_key",
"(",
"?*",
",",
":invert_selection",
")",
"bind_key",
"(",
"?u",
",",
":clear_selection",
")",
"end",
"@_header_adjustment",
"||=",
"0",
"# incase caller does not use",
"@_events",
"<<",
":LIST_SELECTION_EVENT",
"unless",
"@_events",
".",
"include?",
":LIST_SELECTION_EVENT",
"end"
] | mod
Applications may call this or just copy and modify
bindings related to selection | [
"mod",
"Applications",
"may",
"call",
"this",
"or",
"just",
"copy",
"and",
"modify"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/deprecated/listselectable.rb#L210-L225 |
23,853 | mare-imbrium/canis | lib/canis/core/widgets/tree/treemodel.rb | Canis.DefaultTreeModel.add | def add nodechild, allows_children=true, &block
# calling TreeNode.add
$log.debug " XXX def add of DTM #{nodechild} to root "
node = @root.add nodechild, allows_children, &block
if @handler # only if someone is listening, won't fire when being prepared
tme = TreeModelEvent.new(row, row,:ALL_COLUMNS, self, :INSERT)
fire_handler :TREE_MODEL_EVENT, tme
end
#return @root
return node
end | ruby | def add nodechild, allows_children=true, &block
# calling TreeNode.add
$log.debug " XXX def add of DTM #{nodechild} to root "
node = @root.add nodechild, allows_children, &block
if @handler # only if someone is listening, won't fire when being prepared
tme = TreeModelEvent.new(row, row,:ALL_COLUMNS, self, :INSERT)
fire_handler :TREE_MODEL_EVENT, tme
end
#return @root
return node
end | [
"def",
"add",
"nodechild",
",",
"allows_children",
"=",
"true",
",",
"&",
"block",
"# calling TreeNode.add",
"$log",
".",
"debug",
"\" XXX def add of DTM #{nodechild} to root \"",
"node",
"=",
"@root",
".",
"add",
"nodechild",
",",
"allows_children",
",",
"block",
"if",
"@handler",
"# only if someone is listening, won't fire when being prepared",
"tme",
"=",
"TreeModelEvent",
".",
"new",
"(",
"row",
",",
"row",
",",
":ALL_COLUMNS",
",",
"self",
",",
":INSERT",
")",
"fire_handler",
":TREE_MODEL_EVENT",
",",
"tme",
"end",
"#return @root",
"return",
"node",
"end"
] | add a node to root passing a block optionally
@param [String, TreeNode, Array, Hash] node/s to add
@param [Boolean] allow children to be added
@see TreeNode.add
@return [TreeNode] node just added to root (NOT self) | [
"add",
"a",
"node",
"to",
"root",
"passing",
"a",
"block",
"optionally"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tree/treemodel.rb#L50-L60 |
23,854 | mare-imbrium/canis | lib/canis/core/widgets/tree/treemodel.rb | Canis.DefaultTreeModel.undo | def undo where
raise "not yet used"
return unless @delete_buffer
case @delete_buffer[0]
when Array
@delete_buffer.each do |r|
insert where, r
end
else
insert where, @delete_buffer
end
end | ruby | def undo where
raise "not yet used"
return unless @delete_buffer
case @delete_buffer[0]
when Array
@delete_buffer.each do |r|
insert where, r
end
else
insert where, @delete_buffer
end
end | [
"def",
"undo",
"where",
"raise",
"\"not yet used\"",
"return",
"unless",
"@delete_buffer",
"case",
"@delete_buffer",
"[",
"0",
"]",
"when",
"Array",
"@delete_buffer",
".",
"each",
"do",
"|",
"r",
"|",
"insert",
"where",
",",
"r",
"end",
"else",
"insert",
"where",
",",
"@delete_buffer",
"end",
"end"
] | a quick method to undo deletes onto given row. More like paste | [
"a",
"quick",
"method",
"to",
"undo",
"deletes",
"onto",
"given",
"row",
".",
"More",
"like",
"paste"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tree/treemodel.rb#L136-L147 |
23,855 | mare-imbrium/canis | lib/canis/core/widgets/tree/treemodel.rb | Canis.DefaultTreeModel.data= | def data=(data)
raise "not yet used"
raise "Data nil or invalid" if data.nil? or data.size == 0
delete_all
@data = data
tme = TreeModelEvent.new(0, @data.length-1,:ALL_COLUMNS, self, :INSERT)
fire_handler :TREE_MODEL_EVENT, tme
end | ruby | def data=(data)
raise "not yet used"
raise "Data nil or invalid" if data.nil? or data.size == 0
delete_all
@data = data
tme = TreeModelEvent.new(0, @data.length-1,:ALL_COLUMNS, self, :INSERT)
fire_handler :TREE_MODEL_EVENT, tme
end | [
"def",
"data",
"=",
"(",
"data",
")",
"raise",
"\"not yet used\"",
"raise",
"\"Data nil or invalid\"",
"if",
"data",
".",
"nil?",
"or",
"data",
".",
"size",
"==",
"0",
"delete_all",
"@data",
"=",
"data",
"tme",
"=",
"TreeModelEvent",
".",
"new",
"(",
"0",
",",
"@data",
".",
"length",
"-",
"1",
",",
":ALL_COLUMNS",
",",
"self",
",",
":INSERT",
")",
"fire_handler",
":TREE_MODEL_EVENT",
",",
"tme",
"end"
] | for those quick cases when you wish to replace all the data
and not have an event per row being generated | [
"for",
"those",
"quick",
"cases",
"when",
"you",
"wish",
"to",
"replace",
"all",
"the",
"data",
"and",
"not",
"have",
"an",
"event",
"per",
"row",
"being",
"generated"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tree/treemodel.rb#L161-L168 |
23,856 | mare-imbrium/canis | lib/canis/core/widgets/tree/treemodel.rb | Canis.TreeNode.add | def add node, allows_children=true, &block
raise IllegalStateException, "Cannot add a child to this node" unless @allows_children
$log.debug " XXX def add of TreeNode #{node} parent #{self} "
case node
when Array
node.each do |e|
add e, allows_children, &block
end
when Hash
node.each_pair { |name, val|
n = _add name, allows_children, &block
n.add val, allows_children, &block
}
else
return _add node, allows_children, &block
end
self
end | ruby | def add node, allows_children=true, &block
raise IllegalStateException, "Cannot add a child to this node" unless @allows_children
$log.debug " XXX def add of TreeNode #{node} parent #{self} "
case node
when Array
node.each do |e|
add e, allows_children, &block
end
when Hash
node.each_pair { |name, val|
n = _add name, allows_children, &block
n.add val, allows_children, &block
}
else
return _add node, allows_children, &block
end
self
end | [
"def",
"add",
"node",
",",
"allows_children",
"=",
"true",
",",
"&",
"block",
"raise",
"IllegalStateException",
",",
"\"Cannot add a child to this node\"",
"unless",
"@allows_children",
"$log",
".",
"debug",
"\" XXX def add of TreeNode #{node} parent #{self} \"",
"case",
"node",
"when",
"Array",
"node",
".",
"each",
"do",
"|",
"e",
"|",
"add",
"e",
",",
"allows_children",
",",
"block",
"end",
"when",
"Hash",
"node",
".",
"each_pair",
"{",
"|",
"name",
",",
"val",
"|",
"n",
"=",
"_add",
"name",
",",
"allows_children",
",",
"block",
"n",
".",
"add",
"val",
",",
"allows_children",
",",
"block",
"}",
"else",
"return",
"_add",
"node",
",",
"allows_children",
",",
"block",
"end",
"self",
"end"
] | add a node to this node, optionally passing a block for further adding
add a node as child to existing node
If node is not a TreeNode it will be converted to one.
@param [TreeNode, Array, Hash] node/s to add
@param [boolean] should children be allowed
@return [TreeNode] node last added (*NOT* self) | [
"add",
"a",
"node",
"to",
"this",
"node",
"optionally",
"passing",
"a",
"block",
"for",
"further",
"adding",
"add",
"a",
"node",
"as",
"child",
"to",
"existing",
"node",
"If",
"node",
"is",
"not",
"a",
"TreeNode",
"it",
"will",
"be",
"converted",
"to",
"one",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tree/treemodel.rb#L280-L297 |
23,857 | mare-imbrium/canis | lib/canis/core/widgets/tree/treemodel.rb | Canis.TreeNode.user_object_path | def user_object_path
arr = []
arr << self.user_object.to_s
traverse_up do |e|
arr << e.user_object.to_s
end
arr.reverse!
end | ruby | def user_object_path
arr = []
arr << self.user_object.to_s
traverse_up do |e|
arr << e.user_object.to_s
end
arr.reverse!
end | [
"def",
"user_object_path",
"arr",
"=",
"[",
"]",
"arr",
"<<",
"self",
".",
"user_object",
".",
"to_s",
"traverse_up",
"do",
"|",
"e",
"|",
"arr",
"<<",
"e",
".",
"user_object",
".",
"to_s",
"end",
"arr",
".",
"reverse!",
"end"
] | returns an array of user_objects for the current node
starting from root, ending in the current one. The last node
represents this node.
@return [Array] Strings[] | [
"returns",
"an",
"array",
"of",
"user_objects",
"for",
"the",
"current",
"node",
"starting",
"from",
"root",
"ending",
"in",
"the",
"current",
"one",
".",
"The",
"last",
"node",
"represents",
"this",
"node",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/tree/treemodel.rb#L351-L358 |
23,858 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.say | def say statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible?
$log.debug "XXX: inside say win #{@window} !"
case statement
when Question
if config.has_key? :color_pair
$log.debug "INSIDE QUESTION 2 " if $log.debug?
else
$log.debug "XXXX SAY using colorpair: #{statement.color_pair} " if $log.debug?
config[:color_pair] = statement.color_pair
end
else
$log.debug "XXX INSDIE SAY #{statement.class} " if $log.debug?
end
statement = statement.to_str
template = ERB.new(statement, nil, "%")
statement = template.result(binding)
@prompt_length = statement.length # required by ask since it prints after
@statement = statement #
clear_line
print_str statement, config
end | ruby | def say statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible?
$log.debug "XXX: inside say win #{@window} !"
case statement
when Question
if config.has_key? :color_pair
$log.debug "INSIDE QUESTION 2 " if $log.debug?
else
$log.debug "XXXX SAY using colorpair: #{statement.color_pair} " if $log.debug?
config[:color_pair] = statement.color_pair
end
else
$log.debug "XXX INSDIE SAY #{statement.class} " if $log.debug?
end
statement = statement.to_str
template = ERB.new(statement, nil, "%")
statement = template.result(binding)
@prompt_length = statement.length # required by ask since it prints after
@statement = statement #
clear_line
print_str statement, config
end | [
"def",
"say",
"statement",
",",
"config",
"=",
"{",
"}",
"@window",
"||=",
"_create_footer_window",
"#@window.show #unless @window.visible?",
"$log",
".",
"debug",
"\"XXX: inside say win #{@window} !\"",
"case",
"statement",
"when",
"Question",
"if",
"config",
".",
"has_key?",
":color_pair",
"$log",
".",
"debug",
"\"INSIDE QUESTION 2 \"",
"if",
"$log",
".",
"debug?",
"else",
"$log",
".",
"debug",
"\"XXXX SAY using colorpair: #{statement.color_pair} \"",
"if",
"$log",
".",
"debug?",
"config",
"[",
":color_pair",
"]",
"=",
"statement",
".",
"color_pair",
"end",
"else",
"$log",
".",
"debug",
"\"XXX INSDIE SAY #{statement.class} \"",
"if",
"$log",
".",
"debug?",
"end",
"statement",
"=",
"statement",
".",
"to_str",
"template",
"=",
"ERB",
".",
"new",
"(",
"statement",
",",
"nil",
",",
"\"%\"",
")",
"statement",
"=",
"template",
".",
"result",
"(",
"binding",
")",
"@prompt_length",
"=",
"statement",
".",
"length",
"# required by ask since it prints after ",
"@statement",
"=",
"statement",
"# ",
"clear_line",
"print_str",
"statement",
",",
"config",
"end"
] | The basic output method for HighLine objects.
The _statement_ parameter is processed as an ERb template, supporting
embedded Ruby code. The template is evaluated with a binding inside
the HighLine instance.
NOTE: modified from original highline, does not care about space at end of
question. Also, ansi color constants will not work. Be careful what ruby code
you pass in.
NOTE: This uses a window, so it will persist in the last row. You must call
hide_bottomline to remove the window. It is preferable to call say_with_pause
from user programs | [
"The",
"basic",
"output",
"method",
"for",
"HighLine",
"objects",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1103-L1127 |
23,859 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.say_with_pause | def say_with_pause statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible? # 2011-10-14 23:52:52
say statement, config
@window.wrefresh
Ncurses::Panel.update_panels
[email protected]()
hide_bottomline
## return char so we can use for asking for one character
return ch
end | ruby | def say_with_pause statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible? # 2011-10-14 23:52:52
say statement, config
@window.wrefresh
Ncurses::Panel.update_panels
[email protected]()
hide_bottomline
## return char so we can use for asking for one character
return ch
end | [
"def",
"say_with_pause",
"statement",
",",
"config",
"=",
"{",
"}",
"@window",
"||=",
"_create_footer_window",
"#@window.show #unless @window.visible? # 2011-10-14 23:52:52",
"say",
"statement",
",",
"config",
"@window",
".",
"wrefresh",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
"hide_bottomline",
"## return char so we can use for asking for one character",
"return",
"ch",
"end"
] | display some text at bottom and wait for a key before hiding window | [
"display",
"some",
"text",
"at",
"bottom",
"and",
"wait",
"for",
"a",
"key",
"before",
"hiding",
"window"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1131-L1141 |
23,860 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.say_with_wait | def say_with_wait statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible? # 2011-10-14 23:52:59
say statement, config
@window.wrefresh
Ncurses::Panel.update_panels
sleep 0.5
hide_bottomline
end | ruby | def say_with_wait statement, config={}
@window ||= _create_footer_window
#@window.show #unless @window.visible? # 2011-10-14 23:52:59
say statement, config
@window.wrefresh
Ncurses::Panel.update_panels
sleep 0.5
hide_bottomline
end | [
"def",
"say_with_wait",
"statement",
",",
"config",
"=",
"{",
"}",
"@window",
"||=",
"_create_footer_window",
"#@window.show #unless @window.visible? # 2011-10-14 23:52:59",
"say",
"statement",
",",
"config",
"@window",
".",
"wrefresh",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"sleep",
"0.5",
"hide_bottomline",
"end"
] | since say does not leave the screen, it is not exactly recommended
as it will hide what's below. It's better to call pause, or this, which
will quickly go off. If the message is not important enough to ask for a pause,
the will flicker on screen, but not for too long. | [
"since",
"say",
"does",
"not",
"leave",
"the",
"screen",
"it",
"is",
"not",
"exactly",
"recommended",
"as",
"it",
"will",
"hide",
"what",
"s",
"below",
".",
"It",
"s",
"better",
"to",
"call",
"pause",
"or",
"this",
"which",
"will",
"quickly",
"go",
"off",
".",
"If",
"the",
"message",
"is",
"not",
"important",
"enough",
"to",
"ask",
"for",
"a",
"pause",
"the",
"will",
"flicker",
"on",
"screen",
"but",
"not",
"for",
"too",
"long",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1146-L1154 |
23,861 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.explain_error | def explain_error( error )
say_with_pause(@question.responses[error]) unless error.nil?
if @question.responses[:ask_on_error] == :question
say(@question)
elsif @question.responses[:ask_on_error]
say(@question.responses[:ask_on_error])
end
end | ruby | def explain_error( error )
say_with_pause(@question.responses[error]) unless error.nil?
if @question.responses[:ask_on_error] == :question
say(@question)
elsif @question.responses[:ask_on_error]
say(@question.responses[:ask_on_error])
end
end | [
"def",
"explain_error",
"(",
"error",
")",
"say_with_pause",
"(",
"@question",
".",
"responses",
"[",
"error",
"]",
")",
"unless",
"error",
".",
"nil?",
"if",
"@question",
".",
"responses",
"[",
":ask_on_error",
"]",
"==",
":question",
"say",
"(",
"@question",
")",
"elsif",
"@question",
".",
"responses",
"[",
":ask_on_error",
"]",
"say",
"(",
"@question",
".",
"responses",
"[",
":ask_on_error",
"]",
")",
"end",
"end"
] | A helper method for sending the output stream and error and repeat
of the question.
FIXME: since we write on one line in say, this often gets overidden
by next say or ask | [
"A",
"helper",
"method",
"for",
"sending",
"the",
"output",
"stream",
"and",
"error",
"and",
"repeat",
"of",
"the",
"question",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1160-L1167 |
23,862 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.print_str | def print_str(text, config={})
win = config.fetch(:window, @window) # assuming its in App
x = config.fetch :x, 0 # @message_row # Ncurses.LINES-1, 0 since one line window 2011-10-8
y = config.fetch :y, 0
$log.debug "XXX: print_str #{win} with text : #{text} at #{x} #{y} "
color = config[:color_pair] || $datacolor
raise "no window for ask print in #{self.class} name: #{name} " unless win
color=Ncurses.COLOR_PAIR(color);
win.attron(color);
#win.mvprintw(x, y, "%-40s" % text);
win.mvprintw(x, y, "%s" % text);
win.attroff(color);
win.refresh # FFI NW 2011-09-9 , added back gets overwritten
end | ruby | def print_str(text, config={})
win = config.fetch(:window, @window) # assuming its in App
x = config.fetch :x, 0 # @message_row # Ncurses.LINES-1, 0 since one line window 2011-10-8
y = config.fetch :y, 0
$log.debug "XXX: print_str #{win} with text : #{text} at #{x} #{y} "
color = config[:color_pair] || $datacolor
raise "no window for ask print in #{self.class} name: #{name} " unless win
color=Ncurses.COLOR_PAIR(color);
win.attron(color);
#win.mvprintw(x, y, "%-40s" % text);
win.mvprintw(x, y, "%s" % text);
win.attroff(color);
win.refresh # FFI NW 2011-09-9 , added back gets overwritten
end | [
"def",
"print_str",
"(",
"text",
",",
"config",
"=",
"{",
"}",
")",
"win",
"=",
"config",
".",
"fetch",
"(",
":window",
",",
"@window",
")",
"# assuming its in App",
"x",
"=",
"config",
".",
"fetch",
":x",
",",
"0",
"# @message_row # Ncurses.LINES-1, 0 since one line window 2011-10-8 ",
"y",
"=",
"config",
".",
"fetch",
":y",
",",
"0",
"$log",
".",
"debug",
"\"XXX: print_str #{win} with text : #{text} at #{x} #{y} \"",
"color",
"=",
"config",
"[",
":color_pair",
"]",
"||",
"$datacolor",
"raise",
"\"no window for ask print in #{self.class} name: #{name} \"",
"unless",
"win",
"color",
"=",
"Ncurses",
".",
"COLOR_PAIR",
"(",
"color",
")",
";",
"win",
".",
"attron",
"(",
"color",
")",
";",
"#win.mvprintw(x, y, \"%-40s\" % text);",
"win",
".",
"mvprintw",
"(",
"x",
",",
"y",
",",
"\"%s\"",
"%",
"text",
")",
";",
"win",
".",
"attroff",
"(",
"color",
")",
";",
"win",
".",
"refresh",
"# FFI NW 2011-09-9 , added back gets overwritten",
"end"
] | Internal method for printing a string | [
"Internal",
"method",
"for",
"printing",
"a",
"string"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1172-L1185 |
23,863 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.display_text_interactive | def display_text_interactive text, config={}
require 'canis/core/util/rcommandwindow'
ht = config[:height] || 15
layout = { :height => ht, :width => Ncurses.COLS-1, :top => Ncurses.LINES-ht+1, :left => 0 }
rc = CommandWindow.new nil, :layout => layout, :box => true, :title => config[:title]
w = rc.window
#rc.text "There was a quick brown fox who ran over the lazy dog and then went over the moon over and over again and again"
rc.display_interactive(text) { |l|
l.focussed_attrib = 'bold' # Ncurses::A_UNDERLINE
l.focussed_symbol = '>'
}
rc = nil
end | ruby | def display_text_interactive text, config={}
require 'canis/core/util/rcommandwindow'
ht = config[:height] || 15
layout = { :height => ht, :width => Ncurses.COLS-1, :top => Ncurses.LINES-ht+1, :left => 0 }
rc = CommandWindow.new nil, :layout => layout, :box => true, :title => config[:title]
w = rc.window
#rc.text "There was a quick brown fox who ran over the lazy dog and then went over the moon over and over again and again"
rc.display_interactive(text) { |l|
l.focussed_attrib = 'bold' # Ncurses::A_UNDERLINE
l.focussed_symbol = '>'
}
rc = nil
end | [
"def",
"display_text_interactive",
"text",
",",
"config",
"=",
"{",
"}",
"require",
"'canis/core/util/rcommandwindow'",
"ht",
"=",
"config",
"[",
":height",
"]",
"||",
"15",
"layout",
"=",
"{",
":height",
"=>",
"ht",
",",
":width",
"=>",
"Ncurses",
".",
"COLS",
"-",
"1",
",",
":top",
"=>",
"Ncurses",
".",
"LINES",
"-",
"ht",
"+",
"1",
",",
":left",
"=>",
"0",
"}",
"rc",
"=",
"CommandWindow",
".",
"new",
"nil",
",",
":layout",
"=>",
"layout",
",",
":box",
"=>",
"true",
",",
":title",
"=>",
"config",
"[",
":title",
"]",
"w",
"=",
"rc",
".",
"window",
"#rc.text \"There was a quick brown fox who ran over the lazy dog and then went over the moon over and over again and again\"",
"rc",
".",
"display_interactive",
"(",
"text",
")",
"{",
"|",
"l",
"|",
"l",
".",
"focussed_attrib",
"=",
"'bold'",
"# Ncurses::A_UNDERLINE",
"l",
".",
"focussed_symbol",
"=",
"'>'",
"}",
"rc",
"=",
"nil",
"end"
] | XXX FIXME this uses only rcommand so what is it doing here. | [
"XXX",
"FIXME",
"this",
"uses",
"only",
"rcommand",
"so",
"what",
"is",
"it",
"doing",
"here",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1592-L1604 |
23,864 | mare-imbrium/canis | lib/canis/core/util/extras/bottomline.rb | Canis.Bottomline.list | def list( items, mode = :rows, option = nil )
items = items.to_ary.map do |item|
ERB.new(item, nil, "%").result(binding)
end
case mode
when :inline
option = " or " if option.nil?
case items.size
when 0
""
when 1
items.first
when 2
"#{items.first}#{option}#{items.last}"
else
items[0..-2].join(", ") + "#{option}#{items.last}"
end
when :columns_across, :columns_down
max_length = actual_length(
items.max { |a, b| actual_length(a) <=> actual_length(b) }
)
if option.nil?
limit = @wrap_at || 80
option = (limit + 2) / (max_length + 2)
end
items = items.map do |item|
pad = max_length + (item.length - actual_length(item))
"%-#{pad}s" % item
end
row_count = (items.size / option.to_f).ceil
if mode == :columns_across
rows = Array.new(row_count) { Array.new }
items.each_with_index do |item, index|
rows[index / option] << item
end
rows.map { |row| row.join(" ") + "\n" }.join
else
columns = Array.new(option) { Array.new }
items.each_with_index do |item, index|
columns[index / row_count] << item
end
list = ""
columns.first.size.times do |index|
list << columns.map { |column| column[index] }.
compact.join(" ") + "\n"
end
list
end
else
items.map { |i| "#{i}\n" }.join
end
end | ruby | def list( items, mode = :rows, option = nil )
items = items.to_ary.map do |item|
ERB.new(item, nil, "%").result(binding)
end
case mode
when :inline
option = " or " if option.nil?
case items.size
when 0
""
when 1
items.first
when 2
"#{items.first}#{option}#{items.last}"
else
items[0..-2].join(", ") + "#{option}#{items.last}"
end
when :columns_across, :columns_down
max_length = actual_length(
items.max { |a, b| actual_length(a) <=> actual_length(b) }
)
if option.nil?
limit = @wrap_at || 80
option = (limit + 2) / (max_length + 2)
end
items = items.map do |item|
pad = max_length + (item.length - actual_length(item))
"%-#{pad}s" % item
end
row_count = (items.size / option.to_f).ceil
if mode == :columns_across
rows = Array.new(row_count) { Array.new }
items.each_with_index do |item, index|
rows[index / option] << item
end
rows.map { |row| row.join(" ") + "\n" }.join
else
columns = Array.new(option) { Array.new }
items.each_with_index do |item, index|
columns[index / row_count] << item
end
list = ""
columns.first.size.times do |index|
list << columns.map { |column| column[index] }.
compact.join(" ") + "\n"
end
list
end
else
items.map { |i| "#{i}\n" }.join
end
end | [
"def",
"list",
"(",
"items",
",",
"mode",
"=",
":rows",
",",
"option",
"=",
"nil",
")",
"items",
"=",
"items",
".",
"to_ary",
".",
"map",
"do",
"|",
"item",
"|",
"ERB",
".",
"new",
"(",
"item",
",",
"nil",
",",
"\"%\"",
")",
".",
"result",
"(",
"binding",
")",
"end",
"case",
"mode",
"when",
":inline",
"option",
"=",
"\" or \"",
"if",
"option",
".",
"nil?",
"case",
"items",
".",
"size",
"when",
"0",
"\"\"",
"when",
"1",
"items",
".",
"first",
"when",
"2",
"\"#{items.first}#{option}#{items.last}\"",
"else",
"items",
"[",
"0",
"..",
"-",
"2",
"]",
".",
"join",
"(",
"\", \"",
")",
"+",
"\"#{option}#{items.last}\"",
"end",
"when",
":columns_across",
",",
":columns_down",
"max_length",
"=",
"actual_length",
"(",
"items",
".",
"max",
"{",
"|",
"a",
",",
"b",
"|",
"actual_length",
"(",
"a",
")",
"<=>",
"actual_length",
"(",
"b",
")",
"}",
")",
"if",
"option",
".",
"nil?",
"limit",
"=",
"@wrap_at",
"||",
"80",
"option",
"=",
"(",
"limit",
"+",
"2",
")",
"/",
"(",
"max_length",
"+",
"2",
")",
"end",
"items",
"=",
"items",
".",
"map",
"do",
"|",
"item",
"|",
"pad",
"=",
"max_length",
"+",
"(",
"item",
".",
"length",
"-",
"actual_length",
"(",
"item",
")",
")",
"\"%-#{pad}s\"",
"%",
"item",
"end",
"row_count",
"=",
"(",
"items",
".",
"size",
"/",
"option",
".",
"to_f",
")",
".",
"ceil",
"if",
"mode",
"==",
":columns_across",
"rows",
"=",
"Array",
".",
"new",
"(",
"row_count",
")",
"{",
"Array",
".",
"new",
"}",
"items",
".",
"each_with_index",
"do",
"|",
"item",
",",
"index",
"|",
"rows",
"[",
"index",
"/",
"option",
"]",
"<<",
"item",
"end",
"rows",
".",
"map",
"{",
"|",
"row",
"|",
"row",
".",
"join",
"(",
"\" \"",
")",
"+",
"\"\\n\"",
"}",
".",
"join",
"else",
"columns",
"=",
"Array",
".",
"new",
"(",
"option",
")",
"{",
"Array",
".",
"new",
"}",
"items",
".",
"each_with_index",
"do",
"|",
"item",
",",
"index",
"|",
"columns",
"[",
"index",
"/",
"row_count",
"]",
"<<",
"item",
"end",
"list",
"=",
"\"\"",
"columns",
".",
"first",
".",
"size",
".",
"times",
"do",
"|",
"index",
"|",
"list",
"<<",
"columns",
".",
"map",
"{",
"|",
"column",
"|",
"column",
"[",
"index",
"]",
"}",
".",
"compact",
".",
"join",
"(",
"\" \"",
")",
"+",
"\"\\n\"",
"end",
"list",
"end",
"else",
"items",
".",
"map",
"{",
"|",
"i",
"|",
"\"#{i}\\n\"",
"}",
".",
"join",
"end",
"end"
] | Each member of the _items_ Array is passed through ERb and thus can contain
their own expansions. Color escape expansions do not contribute to the
final field width. | [
"Each",
"member",
"of",
"the",
"_items_",
"Array",
"is",
"passed",
"through",
"ERb",
"and",
"thus",
"can",
"contain",
"their",
"own",
"expansions",
".",
"Color",
"escape",
"expansions",
"do",
"not",
"contribute",
"to",
"the",
"final",
"field",
"width",
"."
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/extras/bottomline.rb#L1675-L1733 |
23,865 | avvo/delsolr | lib/delsolr/document.rb | DelSolr.Document.construct_field_tag | def construct_field_tag(name, value, options={})
options[:name] = name.to_s
use_cdata = options.delete(:cdata)
return "<field#{options.to_xml_attribute_string}>#{use_cdata ? cdata(value) : value}</field>\n"
end | ruby | def construct_field_tag(name, value, options={})
options[:name] = name.to_s
use_cdata = options.delete(:cdata)
return "<field#{options.to_xml_attribute_string}>#{use_cdata ? cdata(value) : value}</field>\n"
end | [
"def",
"construct_field_tag",
"(",
"name",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":name",
"]",
"=",
"name",
".",
"to_s",
"use_cdata",
"=",
"options",
".",
"delete",
"(",
":cdata",
")",
"return",
"\"<field#{options.to_xml_attribute_string}>#{use_cdata ? cdata(value) : value}</field>\\n\"",
"end"
] | creates xml field for given inputs | [
"creates",
"xml",
"field",
"for",
"given",
"inputs"
] | 30debacab9e7bf3c6f1907563286c29fb61441b2 | https://github.com/avvo/delsolr/blob/30debacab9e7bf3c6f1907563286c29fb61441b2/lib/delsolr/document.rb#L63-L68 |
23,866 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.goto_next_selection | def goto_next_selection
return if selected_rows().length == 0
row = selected_rows().sort.find { |i| i > @obj.current_index }
row ||= @obj.current_index
#@obj.current_index = row
@obj.goto_line row
end | ruby | def goto_next_selection
return if selected_rows().length == 0
row = selected_rows().sort.find { |i| i > @obj.current_index }
row ||= @obj.current_index
#@obj.current_index = row
@obj.goto_line row
end | [
"def",
"goto_next_selection",
"return",
"if",
"selected_rows",
"(",
")",
".",
"length",
"==",
"0",
"row",
"=",
"selected_rows",
"(",
")",
".",
"sort",
".",
"find",
"{",
"|",
"i",
"|",
"i",
">",
"@obj",
".",
"current_index",
"}",
"row",
"||=",
"@obj",
".",
"current_index",
"#@obj.current_index = row",
"@obj",
".",
"goto_line",
"row",
"end"
] | after selecting, traverse selections forward | [
"after",
"selecting",
"traverse",
"selections",
"forward"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L202-L208 |
23,867 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.goto_prev_selection | def goto_prev_selection
return if selected_rows().length == 0
row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @obj.current_index }
row ||= @obj.current_index
#@obj.current_index = row
@obj.goto_line row
end | ruby | def goto_prev_selection
return if selected_rows().length == 0
row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @obj.current_index }
row ||= @obj.current_index
#@obj.current_index = row
@obj.goto_line row
end | [
"def",
"goto_prev_selection",
"return",
"if",
"selected_rows",
"(",
")",
".",
"length",
"==",
"0",
"row",
"=",
"selected_rows",
"(",
")",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"b",
"<=>",
"a",
"}",
".",
"find",
"{",
"|",
"i",
"|",
"i",
"<",
"@obj",
".",
"current_index",
"}",
"row",
"||=",
"@obj",
".",
"current_index",
"#@obj.current_index = row",
"@obj",
".",
"goto_line",
"row",
"end"
] | after selecting, traverse selections backward | [
"after",
"selecting",
"traverse",
"selections",
"backward"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L211-L217 |
23,868 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.remove_row_selection_interval | def remove_row_selection_interval ix0, ix1
@anchor_selection_index = ix0
@lead_selection_index = ix1
arr = @selected_indices.dup # to un highlight
@selected_indices.delete_if {|x| x >= ix0 and x <= ix1 }
arr.each {|i| @obj.fire_row_changed(i) }
lse = ListSelectionEvent.new(ix0, ix1, @obj, :DELETE)
@obj.fire_handler :LIST_SELECTION_EVENT, lse
end | ruby | def remove_row_selection_interval ix0, ix1
@anchor_selection_index = ix0
@lead_selection_index = ix1
arr = @selected_indices.dup # to un highlight
@selected_indices.delete_if {|x| x >= ix0 and x <= ix1 }
arr.each {|i| @obj.fire_row_changed(i) }
lse = ListSelectionEvent.new(ix0, ix1, @obj, :DELETE)
@obj.fire_handler :LIST_SELECTION_EVENT, lse
end | [
"def",
"remove_row_selection_interval",
"ix0",
",",
"ix1",
"@anchor_selection_index",
"=",
"ix0",
"@lead_selection_index",
"=",
"ix1",
"arr",
"=",
"@selected_indices",
".",
"dup",
"# to un highlight",
"@selected_indices",
".",
"delete_if",
"{",
"|",
"x",
"|",
"x",
">=",
"ix0",
"and",
"x",
"<=",
"ix1",
"}",
"arr",
".",
"each",
"{",
"|",
"i",
"|",
"@obj",
".",
"fire_row_changed",
"(",
"i",
")",
"}",
"lse",
"=",
"ListSelectionEvent",
".",
"new",
"(",
"ix0",
",",
"ix1",
",",
"@obj",
",",
":DELETE",
")",
"@obj",
".",
"fire_handler",
":LIST_SELECTION_EVENT",
",",
"lse",
"end"
] | remove selected indices between given indices inclusive | [
"remove",
"selected",
"indices",
"between",
"given",
"indices",
"inclusive"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L234-L242 |
23,869 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.ask_select | def ask_select prompt="Enter selection pattern: "
ret = get_string prompt
return if ret.nil? || ret == ""
indices = get_matching_indices ret
#$log.debug "listselectionmodel: ask_select got matches#{@indices} "
return if indices.nil? || indices.empty?
indices.each { |e|
# will not work if single select !! FIXME
add_row_selection_interval e,e
}
end | ruby | def ask_select prompt="Enter selection pattern: "
ret = get_string prompt
return if ret.nil? || ret == ""
indices = get_matching_indices ret
#$log.debug "listselectionmodel: ask_select got matches#{@indices} "
return if indices.nil? || indices.empty?
indices.each { |e|
# will not work if single select !! FIXME
add_row_selection_interval e,e
}
end | [
"def",
"ask_select",
"prompt",
"=",
"\"Enter selection pattern: \"",
"ret",
"=",
"get_string",
"prompt",
"return",
"if",
"ret",
".",
"nil?",
"||",
"ret",
"==",
"\"\"",
"indices",
"=",
"get_matching_indices",
"ret",
"#$log.debug \"listselectionmodel: ask_select got matches#{@indices} \"",
"return",
"if",
"indices",
".",
"nil?",
"||",
"indices",
".",
"empty?",
"indices",
".",
"each",
"{",
"|",
"e",
"|",
"# will not work if single select !! FIXME",
"add_row_selection_interval",
"e",
",",
"e",
"}",
"end"
] | Asks user to enter a string or pattern for selecting rows
Selects rows based on pattern, leaving other selections as-is | [
"Asks",
"user",
"to",
"enter",
"a",
"string",
"or",
"pattern",
"for",
"selecting",
"rows",
"Selects",
"rows",
"based",
"on",
"pattern",
"leaving",
"other",
"selections",
"as",
"-",
"is"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L300-L310 |
23,870 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.ask_unselect | def ask_unselect prompt="Enter selection pattern: "
ret = get_string prompt
return if ret.nil? || ret == ""
indices = get_matching_indices ret
return if indices.nil? || indices.empty?
indices.each { |e|
# will not work if single select !! FIXME
remove_row_selection_interval e,e
}
end | ruby | def ask_unselect prompt="Enter selection pattern: "
ret = get_string prompt
return if ret.nil? || ret == ""
indices = get_matching_indices ret
return if indices.nil? || indices.empty?
indices.each { |e|
# will not work if single select !! FIXME
remove_row_selection_interval e,e
}
end | [
"def",
"ask_unselect",
"prompt",
"=",
"\"Enter selection pattern: \"",
"ret",
"=",
"get_string",
"prompt",
"return",
"if",
"ret",
".",
"nil?",
"||",
"ret",
"==",
"\"\"",
"indices",
"=",
"get_matching_indices",
"ret",
"return",
"if",
"indices",
".",
"nil?",
"||",
"indices",
".",
"empty?",
"indices",
".",
"each",
"{",
"|",
"e",
"|",
"# will not work if single select !! FIXME",
"remove_row_selection_interval",
"e",
",",
"e",
"}",
"end"
] | Asks user to enter a string or pattern for UNselecting rows
UNSelects rows based on pattern, leaving other selections as-is | [
"Asks",
"user",
"to",
"enter",
"a",
"string",
"or",
"pattern",
"for",
"UNselecting",
"rows",
"UNSelects",
"rows",
"based",
"on",
"pattern",
"leaving",
"other",
"selections",
"as",
"-",
"is"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L326-L335 |
23,871 | mare-imbrium/canis | lib/canis/core/include/listselectionmodel.rb | Canis.DefaultListSelectionModel.list_bindings | def list_bindings
# freeing space for paging, now trying out 'v' as selector. 2014-04-14 - 18:57
@obj.bind_key($row_selector || 'v'.ord, 'toggle selection') { toggle_row_selection }
# the mode may be set to single after the constructor, so this would have taken effect.
if @obj.selection_mode == :multiple
# freeing ctrl_space for back paging, now trying out 'V' as selector. 2014-04-14 - 18:57
@obj.bind_key($range_selector || 'V'.ord, 'range select') { range_select }
@obj.bind_key(?+, 'ask_select') { ask_select }
@obj.bind_key(?-, 'ask_unselect') { ask_unselect }
@obj.bind_key(?a, 'select_all') {select_all}
@obj.bind_key(?*, 'invert_selection') { invert_selection }
@obj.bind_key(?u, 'clear_selection') { clear_selection }
@obj.bind_key([?g,?n], 'goto next selection'){ goto_next_selection } # mapping double keys like vim
@obj.bind_key([?g,?p], 'goto prev selection'){ goto_prev_selection } # mapping double keys like vim
end
@_header_adjustment ||= 0 # incase caller does not use
#@obj._events << :LIST_SELECTION_EVENT unless @obj._events.include? :LIST_SELECTION_EVENT
end | ruby | def list_bindings
# freeing space for paging, now trying out 'v' as selector. 2014-04-14 - 18:57
@obj.bind_key($row_selector || 'v'.ord, 'toggle selection') { toggle_row_selection }
# the mode may be set to single after the constructor, so this would have taken effect.
if @obj.selection_mode == :multiple
# freeing ctrl_space for back paging, now trying out 'V' as selector. 2014-04-14 - 18:57
@obj.bind_key($range_selector || 'V'.ord, 'range select') { range_select }
@obj.bind_key(?+, 'ask_select') { ask_select }
@obj.bind_key(?-, 'ask_unselect') { ask_unselect }
@obj.bind_key(?a, 'select_all') {select_all}
@obj.bind_key(?*, 'invert_selection') { invert_selection }
@obj.bind_key(?u, 'clear_selection') { clear_selection }
@obj.bind_key([?g,?n], 'goto next selection'){ goto_next_selection } # mapping double keys like vim
@obj.bind_key([?g,?p], 'goto prev selection'){ goto_prev_selection } # mapping double keys like vim
end
@_header_adjustment ||= 0 # incase caller does not use
#@obj._events << :LIST_SELECTION_EVENT unless @obj._events.include? :LIST_SELECTION_EVENT
end | [
"def",
"list_bindings",
"# freeing space for paging, now trying out 'v' as selector. 2014-04-14 - 18:57 ",
"@obj",
".",
"bind_key",
"(",
"$row_selector",
"||",
"'v'",
".",
"ord",
",",
"'toggle selection'",
")",
"{",
"toggle_row_selection",
"}",
"# the mode may be set to single after the constructor, so this would have taken effect.",
"if",
"@obj",
".",
"selection_mode",
"==",
":multiple",
"# freeing ctrl_space for back paging, now trying out 'V' as selector. 2014-04-14 - 18:57 ",
"@obj",
".",
"bind_key",
"(",
"$range_selector",
"||",
"'V'",
".",
"ord",
",",
"'range select'",
")",
"{",
"range_select",
"}",
"@obj",
".",
"bind_key",
"(",
"?+",
",",
"'ask_select'",
")",
"{",
"ask_select",
"}",
"@obj",
".",
"bind_key",
"(",
"?-",
",",
"'ask_unselect'",
")",
"{",
"ask_unselect",
"}",
"@obj",
".",
"bind_key",
"(",
"?a",
",",
"'select_all'",
")",
"{",
"select_all",
"}",
"@obj",
".",
"bind_key",
"(",
"?*",
",",
"'invert_selection'",
")",
"{",
"invert_selection",
"}",
"@obj",
".",
"bind_key",
"(",
"?u",
",",
"'clear_selection'",
")",
"{",
"clear_selection",
"}",
"@obj",
".",
"bind_key",
"(",
"[",
"?g",
",",
"?n",
"]",
",",
"'goto next selection'",
")",
"{",
"goto_next_selection",
"}",
"# mapping double keys like vim",
"@obj",
".",
"bind_key",
"(",
"[",
"?g",
",",
"?p",
"]",
",",
"'goto prev selection'",
")",
"{",
"goto_prev_selection",
"}",
"# mapping double keys like vim",
"end",
"@_header_adjustment",
"||=",
"0",
"# incase caller does not use",
"#@obj._events << :LIST_SELECTION_EVENT unless @obj._events.include? :LIST_SELECTION_EVENT",
"end"
] | bindings related to selection | [
"bindings",
"related",
"to",
"selection"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/include/listselectionmodel.rb#L340-L358 |
23,872 | mare-imbrium/canis | lib/canis/core/util/basestack.rb | RubyCurses.ModStack.item_for | def item_for widget
each do |e|
if e.is_a? Item
if e.widget == widget
return e
end
end
end
return nil
end | ruby | def item_for widget
each do |e|
if e.is_a? Item
if e.widget == widget
return e
end
end
end
return nil
end | [
"def",
"item_for",
"widget",
"each",
"do",
"|",
"e",
"|",
"if",
"e",
".",
"is_a?",
"Item",
"if",
"e",
".",
"widget",
"==",
"widget",
"return",
"e",
"end",
"end",
"end",
"return",
"nil",
"end"
] | given an widget, return the item, so we can change weight or some other config | [
"given",
"an",
"widget",
"return",
"the",
"item",
"so",
"we",
"can",
"change",
"weight",
"or",
"some",
"other",
"config"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/util/basestack.rb#L393-L402 |
23,873 | mare-imbrium/canis | lib/canis/core/widgets/applicationheader.rb | Canis.ApplicationHeader.print_center | def print_center(htext, r = 0, c = 0)
win = @window
len = win.getmaxx
len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS
#
win.printstring r, ((len-htext.length)/2).floor, htext, @color_pair, @attr
end | ruby | def print_center(htext, r = 0, c = 0)
win = @window
len = win.getmaxx
len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS
#
win.printstring r, ((len-htext.length)/2).floor, htext, @color_pair, @attr
end | [
"def",
"print_center",
"(",
"htext",
",",
"r",
"=",
"0",
",",
"c",
"=",
"0",
")",
"win",
"=",
"@window",
"len",
"=",
"win",
".",
"getmaxx",
"len",
"=",
"Ncurses",
".",
"COLS",
"-",
"0",
"if",
"len",
"==",
"0",
"||",
"len",
">",
"Ncurses",
".",
"COLS",
"#",
"win",
".",
"printstring",
"r",
",",
"(",
"(",
"len",
"-",
"htext",
".",
"length",
")",
"/",
"2",
")",
".",
"floor",
",",
"htext",
",",
"@color_pair",
",",
"@attr",
"end"
] | internal method, called by repaint to print text_center in the center | [
"internal",
"method",
"called",
"by",
"repaint",
"to",
"print",
"text_center",
"in",
"the",
"center"
] | 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/applicationheader.rb#L106-L112 |
23,874 | 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",
"# 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"
] | 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 |
23,875 | 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 |
23,876 | 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\"",
"]",
"# 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"
] | returns the update xml buffer | [
"returns",
"the",
"update",
"xml",
"buffer"
] | 30debacab9e7bf3c6f1907563286c29fb61441b2 | https://github.com/avvo/delsolr/blob/30debacab9e7bf3c6f1907563286c29fb61441b2/lib/delsolr/client.rb#L291-L298 |
23,877 | 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 |
23,878 | 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 |
23,879 | 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",
"# 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"
] | 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 |
23,880 | 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 |
23,881 | 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",
"#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"
] | 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 |
23,882 | 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 |
23,883 | 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",
")",
"# 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"
] | 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 |
23,884 | 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( ?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"
] | 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 |
23,885 | 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",
"# 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"
] | 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 |
23,886 | 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",
")",
"#return str if ret == 0",
"#return \"\"",
"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 |
23,887 | 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)",
"ret",
",",
"str",
"=",
"rb_getstr",
"(",
"@form",
".",
"window",
",",
"$error_message_row",
",",
"$error_message_col",
",",
"prompt",
",",
"maxlen",
",",
"config",
")",
"#return str if ret == 0",
"#return \"\"",
"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 |
23,888 | 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",
"# allow documents to reparse that line",
"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 |
23,889 | 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",
"# 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"
] | 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 |
23,890 | 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}\"",
"#textdialog [\"Error in TextPad: #{err} \", *err.backtrace], :title => \"Exception\"",
"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 |
23,891 | 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",
"## 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"
] | 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 |
23,892 | 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 |
23,893 | 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 |
23,894 | 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 |
23,895 | 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",
"## 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"
] | 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 |
23,896 | 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 |
23,897 | 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",
")",
"# 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"
] | 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 |
23,898 | 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 |
23,899 | 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 |
Subsets and Splits