repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
kristianmandrup/cream | lib/cream/controller/user_control.rb | Cream.UserControl.sign_in | def sign_in(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
expire_session_data_after_sign_in!
warden.set_user(resource, options.merge!(:scope => scope))
# set user id
post_signin resource, options
end | ruby | def sign_in(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
expire_session_data_after_sign_in!
warden.set_user(resource, options.merge!(:scope => scope))
# set user id
post_signin resource, options
end | [
"def",
"sign_in",
"(",
"resource_or_scope",
",",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"scope",
"=",
"Devise",
"::",
"Mapping",
".",
"find_scope!",
"(",
"resource_or_scope",
")",
"resource",
"=",
"args",
".",
"last",
"||",
"resource_or_scope",
"expire_session_data_after_sign_in!",
"warden",
".",
"set_user",
"(",
"resource",
",",
"options",
".",
"merge!",
"(",
":scope",
"=>",
"scope",
")",
")",
"post_signin",
"resource",
",",
"options",
"end"
]
| Sign in an user that already was authenticated. This helper is useful for logging
users in after sign up.
Examples:
sign_in :user, @user # sign_in(scope, resource)
sign_in @user # sign_in(resource)
sign_in @user, :event => :authentication # sign_in(resource, options) | [
"Sign",
"in",
"an",
"user",
"that",
"already",
"was",
"authenticated",
".",
"This",
"helper",
"is",
"useful",
"for",
"logging",
"users",
"in",
"after",
"sign",
"up",
"."
]
| 6edbdc8796b4a942e11d1054649b2e058c90c9d8 | https://github.com/kristianmandrup/cream/blob/6edbdc8796b4a942e11d1054649b2e058c90c9d8/lib/cream/controller/user_control.rb#L54-L63 | train |
kristianmandrup/cream | lib/cream/controller/user_control.rb | Cream.UserControl.sign_out | def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
warden.user(scope) # Without loading user here, before_logout hook is not called
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
# user id
post_signout scope
end | ruby | def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
warden.user(scope) # Without loading user here, before_logout hook is not called
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
# user id
post_signout scope
end | [
"def",
"sign_out",
"(",
"resource_or_scope",
")",
"scope",
"=",
"Devise",
"::",
"Mapping",
".",
"find_scope!",
"(",
"resource_or_scope",
")",
"warden",
".",
"user",
"(",
"scope",
")",
"warden",
".",
"raw_session",
".",
"inspect",
"warden",
".",
"logout",
"(",
"scope",
")",
"post_signout",
"scope",
"end"
]
| Sign out a given user or scope. This helper is useful for signing out an user
after deleting accounts.
Examples:
sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource) | [
"Sign",
"out",
"a",
"given",
"user",
"or",
"scope",
".",
"This",
"helper",
"is",
"useful",
"for",
"signing",
"out",
"an",
"user",
"after",
"deleting",
"accounts",
"."
]
| 6edbdc8796b4a942e11d1054649b2e058c90c9d8 | https://github.com/kristianmandrup/cream/blob/6edbdc8796b4a942e11d1054649b2e058c90c9d8/lib/cream/controller/user_control.rb#L78-L85 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.insert | def insert off0, data
_maxlen = @maxlen || @width - @internal_width
if data.length > _maxlen
data = wrap_text data
# $log.debug "after wrap text done :#{data}"
data = data.split("\n")
data[-1] << "\r" #XXXX
data.each do |row|
@list.insert off0, row
off0 += 1
end
else
data << "\r" if data[-1,1] != "\r" #XXXX
@list.insert off0, data
end
# expecting array !!
#data.each do |row|
#@list.insert off0, row
#off0 += 1
#end
#$log.debug " AFTER INSERT: #{@list}"
end | ruby | def insert off0, data
_maxlen = @maxlen || @width - @internal_width
if data.length > _maxlen
data = wrap_text data
# $log.debug "after wrap text done :#{data}"
data = data.split("\n")
data[-1] << "\r" #XXXX
data.each do |row|
@list.insert off0, row
off0 += 1
end
else
data << "\r" if data[-1,1] != "\r" #XXXX
@list.insert off0, data
end
# expecting array !!
#data.each do |row|
#@list.insert off0, row
#off0 += 1
#end
#$log.debug " AFTER INSERT: #{@list}"
end | [
"def",
"insert",
"off0",
",",
"data",
"_maxlen",
"=",
"@maxlen",
"||",
"@width",
"-",
"@internal_width",
"if",
"data",
".",
"length",
">",
"_maxlen",
"data",
"=",
"wrap_text",
"data",
"data",
"=",
"data",
".",
"split",
"(",
"\"\\n\"",
")",
"data",
"[",
"-",
"1",
"]",
"<<",
"\"\\r\"",
"data",
".",
"each",
"do",
"|",
"row",
"|",
"@list",
".",
"insert",
"off0",
",",
"row",
"off0",
"+=",
"1",
"end",
"else",
"data",
"<<",
"\"\\r\"",
"if",
"data",
"[",
"-",
"1",
",",
"1",
"]",
"!=",
"\"\\r\"",
"@list",
".",
"insert",
"off0",
",",
"data",
"end",
"end"
]
| trying to wrap and insert | [
"trying",
"to",
"wrap",
"and",
"insert"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L114-L135 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.<< | def << data
# if width if nil, either set it, or add this to a container that sets it before calling this method
_maxlen = @maxlen || @width - @internal_width
if data.length > _maxlen
#$log.debug "wrapped append for #{data}"
data = wrap_text data
#$log.debug "after wrap text for :#{data}"
data = data.split("\n")
# 2009-01-01 22:24 the \n was needed so we would put a space at time of writing.
# we need a soft return so a space can be added when pushing down.
# commented off 2008-12-28 21:59
#data.each {|line| @list << line+"\n"}
data.each {|line| @list << line}
@list[-1] << "\r" #XXXX
else
#$log.debug "normal append for #{data}"
data << "\r" if data[-1,1] != "\r" #XXXX
@list << data
end
set_modified # added 2009-03-07 18:29
goto_end if @auto_scroll
self
end | ruby | def << data
# if width if nil, either set it, or add this to a container that sets it before calling this method
_maxlen = @maxlen || @width - @internal_width
if data.length > _maxlen
#$log.debug "wrapped append for #{data}"
data = wrap_text data
#$log.debug "after wrap text for :#{data}"
data = data.split("\n")
# 2009-01-01 22:24 the \n was needed so we would put a space at time of writing.
# we need a soft return so a space can be added when pushing down.
# commented off 2008-12-28 21:59
#data.each {|line| @list << line+"\n"}
data.each {|line| @list << line}
@list[-1] << "\r" #XXXX
else
#$log.debug "normal append for #{data}"
data << "\r" if data[-1,1] != "\r" #XXXX
@list << data
end
set_modified # added 2009-03-07 18:29
goto_end if @auto_scroll
self
end | [
"def",
"<<",
"data",
"_maxlen",
"=",
"@maxlen",
"||",
"@width",
"-",
"@internal_width",
"if",
"data",
".",
"length",
">",
"_maxlen",
"data",
"=",
"wrap_text",
"data",
"data",
"=",
"data",
".",
"split",
"(",
"\"\\n\"",
")",
"data",
".",
"each",
"{",
"|",
"line",
"|",
"@list",
"<<",
"line",
"}",
"@list",
"[",
"-",
"1",
"]",
"<<",
"\"\\r\"",
"else",
"data",
"<<",
"\"\\r\"",
"if",
"data",
"[",
"-",
"1",
",",
"1",
"]",
"!=",
"\"\\r\"",
"@list",
"<<",
"data",
"end",
"set_modified",
"goto_end",
"if",
"@auto_scroll",
"self",
"end"
]
| wraps line sent in if longer than _maxlen
Typically a line is sent in. We wrap and put a hard return at end. | [
"wraps",
"line",
"sent",
"in",
"if",
"longer",
"than",
"_maxlen",
"Typically",
"a",
"line",
"is",
"sent",
"in",
".",
"We",
"wrap",
"and",
"put",
"a",
"hard",
"return",
"at",
"end",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L139-L161 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.undo_delete | def undo_delete
# added 2008-11-27 12:43 paste delete buffer into insertion point
return if @delete_buffer.nil?
$log.warn "undo_delete is broken! perhaps cannot be used . textarea 347 "
# FIXME - can be an array
case @delete_buffer
when Array
# we need to unroll array, and it could be lines not just a string
str = @delete_buffer.first
else
str = @delete_buffer
end
@buffer.insert @curpos, str
set_modified
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, @current_index, @delete_buffer) # 2008-12-24 18:34
end | ruby | def undo_delete
# added 2008-11-27 12:43 paste delete buffer into insertion point
return if @delete_buffer.nil?
$log.warn "undo_delete is broken! perhaps cannot be used . textarea 347 "
# FIXME - can be an array
case @delete_buffer
when Array
# we need to unroll array, and it could be lines not just a string
str = @delete_buffer.first
else
str = @delete_buffer
end
@buffer.insert @curpos, str
set_modified
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, @current_index, @delete_buffer) # 2008-12-24 18:34
end | [
"def",
"undo_delete",
"return",
"if",
"@delete_buffer",
".",
"nil?",
"$log",
".",
"warn",
"\"undo_delete is broken! perhaps cannot be used . textarea 347 \"",
"case",
"@delete_buffer",
"when",
"Array",
"str",
"=",
"@delete_buffer",
".",
"first",
"else",
"str",
"=",
"@delete_buffer",
"end",
"@buffer",
".",
"insert",
"@curpos",
",",
"str",
"set_modified",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"@curpos",
",",
"@curpos",
"+",
"@delete_buffer",
".",
"length",
",",
"self",
",",
":INSERT",
",",
"@current_index",
",",
"@delete_buffer",
")",
"end"
]
| this is broken, delete_buffer could be a line or a string or array of lines | [
"this",
"is",
"broken",
"delete_buffer",
"could",
"be",
"a",
"line",
"or",
"a",
"string",
"or",
"array",
"of",
"lines"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L376-L391 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.insert_break | def insert_break
return -1 unless @editable
# insert a blank row and append rest of this line to cursor
$log.debug "ENTER PRESSED at #{@curpos}, on row #{@current_index}"
@delete_buffer = (delete_eol || "")
@list[@current_index] << "\r"
$log.debug "DELETE BUFFER #{@delete_buffer}"
@list.insert @current_index+1, @delete_buffer
@curpos = 0
down
col = @orig_col + @col_offset
setrowcol @row+1, col
# FIXME maybe this should be insert line since line inserted, not just data, undo will delete it
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT_LINE, @current_index, @delete_buffer) # 2008-12-24 18:34
end | ruby | def insert_break
return -1 unless @editable
# insert a blank row and append rest of this line to cursor
$log.debug "ENTER PRESSED at #{@curpos}, on row #{@current_index}"
@delete_buffer = (delete_eol || "")
@list[@current_index] << "\r"
$log.debug "DELETE BUFFER #{@delete_buffer}"
@list.insert @current_index+1, @delete_buffer
@curpos = 0
down
col = @orig_col + @col_offset
setrowcol @row+1, col
# FIXME maybe this should be insert line since line inserted, not just data, undo will delete it
fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT_LINE, @current_index, @delete_buffer) # 2008-12-24 18:34
end | [
"def",
"insert_break",
"return",
"-",
"1",
"unless",
"@editable",
"$log",
".",
"debug",
"\"ENTER PRESSED at #{@curpos}, on row #{@current_index}\"",
"@delete_buffer",
"=",
"(",
"delete_eol",
"||",
"\"\"",
")",
"@list",
"[",
"@current_index",
"]",
"<<",
"\"\\r\"",
"$log",
".",
"debug",
"\"DELETE BUFFER #{@delete_buffer}\"",
"@list",
".",
"insert",
"@current_index",
"+",
"1",
",",
"@delete_buffer",
"@curpos",
"=",
"0",
"down",
"col",
"=",
"@orig_col",
"+",
"@col_offset",
"setrowcol",
"@row",
"+",
"1",
",",
"col",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"@curpos",
",",
"@curpos",
"+",
"@delete_buffer",
".",
"length",
",",
"self",
",",
":INSERT_LINE",
",",
"@current_index",
",",
"@delete_buffer",
")",
"end"
]
| FIXME - fire event not correct, not undo'ing correctly, check row and also slash r append | [
"FIXME",
"-",
"fire",
"event",
"not",
"correct",
"not",
"undo",
"ing",
"correctly",
"check",
"row",
"and",
"also",
"slash",
"r",
"append"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L393-L407 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.set_form_col | def set_form_col col1=@curpos
@curpos = col1
@cols_panned ||= 0
cursor_bounds_check
## added win_col on 2009-12-28 20:21 for embedded forms BUFFERED TRYING OUT
win_col = 0 # 2010-02-07 23:19 new cursor stuff
#col = win_col + @orig_col + @col_offset + @curpos
#col = win_col + @orig_col + @col_offset + @curpos + @cols_panned
# 2010-01-14 13:31 changed orig_col to col for embedded forms, splitpanes.
col = win_col + @col + @col_offset + @curpos + @cols_panned
$log.debug "sfc: wc:#{win_col} col:#{@col}, coff:#{@col_offset}. cp:#{@curpos} colsp:#{@cols_panned} . "
#@form.setrowcol @form.row, col # added 2009-12-29 18:50 BUFFERED
$log.debug " TA calling setformrow col nil, #{col} "
setrowcol nil, col # added 2009-12-29 18:50 BUFFERED
@repaint_footer_required = true
end | ruby | def set_form_col col1=@curpos
@curpos = col1
@cols_panned ||= 0
cursor_bounds_check
## added win_col on 2009-12-28 20:21 for embedded forms BUFFERED TRYING OUT
win_col = 0 # 2010-02-07 23:19 new cursor stuff
#col = win_col + @orig_col + @col_offset + @curpos
#col = win_col + @orig_col + @col_offset + @curpos + @cols_panned
# 2010-01-14 13:31 changed orig_col to col for embedded forms, splitpanes.
col = win_col + @col + @col_offset + @curpos + @cols_panned
$log.debug "sfc: wc:#{win_col} col:#{@col}, coff:#{@col_offset}. cp:#{@curpos} colsp:#{@cols_panned} . "
#@form.setrowcol @form.row, col # added 2009-12-29 18:50 BUFFERED
$log.debug " TA calling setformrow col nil, #{col} "
setrowcol nil, col # added 2009-12-29 18:50 BUFFERED
@repaint_footer_required = true
end | [
"def",
"set_form_col",
"col1",
"=",
"@curpos",
"@curpos",
"=",
"col1",
"@cols_panned",
"||=",
"0",
"cursor_bounds_check",
"win_col",
"=",
"0",
"col",
"=",
"win_col",
"+",
"@col",
"+",
"@col_offset",
"+",
"@curpos",
"+",
"@cols_panned",
"$log",
".",
"debug",
"\"sfc: wc:#{win_col} col:#{@col}, coff:#{@col_offset}. cp:#{@curpos} colsp:#{@cols_panned} . \"",
"$log",
".",
"debug",
"\" TA calling setformrow col nil, #{col} \"",
"setrowcol",
"nil",
",",
"col",
"@repaint_footer_required",
"=",
"true",
"end"
]
| set cursor on correct column | [
"set",
"cursor",
"on",
"correct",
"column"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L409-L425 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.insert_wrap | def insert_wrap lineno, pos, lastchars
_maxlen = @maxlen || @width - @internal_width
@list[lineno].insert pos, lastchars
len = @list[lineno].length
if len > _maxlen
push_last_word lineno #- sometime i may push down 10 chars but the last word is less
end
end | ruby | def insert_wrap lineno, pos, lastchars
_maxlen = @maxlen || @width - @internal_width
@list[lineno].insert pos, lastchars
len = @list[lineno].length
if len > _maxlen
push_last_word lineno #- sometime i may push down 10 chars but the last word is less
end
end | [
"def",
"insert_wrap",
"lineno",
",",
"pos",
",",
"lastchars",
"_maxlen",
"=",
"@maxlen",
"||",
"@width",
"-",
"@internal_width",
"@list",
"[",
"lineno",
"]",
".",
"insert",
"pos",
",",
"lastchars",
"len",
"=",
"@list",
"[",
"lineno",
"]",
".",
"length",
"if",
"len",
">",
"_maxlen",
"push_last_word",
"lineno",
"end",
"end"
]
| this attempts to recursively insert into a row, seeing that any stuff exceeding is pushed down further.
Yes, it should check for a para end and insert. Currently it could add to next para. | [
"this",
"attempts",
"to",
"recursively",
"insert",
"into",
"a",
"row",
"seeing",
"that",
"any",
"stuff",
"exceeding",
"is",
"pushed",
"down",
"further",
".",
"Yes",
"it",
"should",
"check",
"for",
"a",
"para",
"end",
"and",
"insert",
".",
"Currently",
"it",
"could",
"add",
"to",
"next",
"para",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L686-L693 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.putch | def putch char
_maxlen = @maxlen || @width - @internal_width
@buffer ||= @list[@current_index]
return -1 if !@editable #or @buffer.length >= _maxlen
#if @chars_allowed != nil # remove useless functionality
#return if char.match(@chars_allowed).nil?
#end
raise "putch expects only one char" if char.length != 1
oldcurpos = @curpos
#$log.debug "putch : pr:#{@current_index}, cp:#{@curpos}, char:#{char}, lc:#{@buffer[-1]}, buf:(#{@buffer})"
if @overwrite_mode
@buffer[@curpos] = char
else
@buffer.insert(@curpos, char)
end
@curpos += 1
#$log.debug "putch INS: cp:#{@curpos}, max:#{_maxlen}, buf:(#{@buffer.length})"
if @curpos-1 > _maxlen or @buffer.length()-1 > _maxlen
lastchars, lastspace = push_last_word @current_index
#$log.debug "last sapce #{lastspace}, lastchars:#{lastchars},lc:#{lastchars[-1]}, #{@list[@current_index]} "
## wrap on word XX If last char is 10 then insert line
@buffer = @list[@current_index]
if @curpos-1 > _maxlen or @curpos-1 > @buffer.length()-1
ret = down
# keep the cursor in the same position in the string that was pushed down.
@curpos = oldcurpos - lastspace #lastchars.length # 0
end
end
set_form_row
@buffer = @list[@current_index]
set_form_col
@modified = true
fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, @current_index, char) # 2008-12-24 18:34
@repaint_required = true
0
end | ruby | def putch char
_maxlen = @maxlen || @width - @internal_width
@buffer ||= @list[@current_index]
return -1 if !@editable #or @buffer.length >= _maxlen
#if @chars_allowed != nil # remove useless functionality
#return if char.match(@chars_allowed).nil?
#end
raise "putch expects only one char" if char.length != 1
oldcurpos = @curpos
#$log.debug "putch : pr:#{@current_index}, cp:#{@curpos}, char:#{char}, lc:#{@buffer[-1]}, buf:(#{@buffer})"
if @overwrite_mode
@buffer[@curpos] = char
else
@buffer.insert(@curpos, char)
end
@curpos += 1
#$log.debug "putch INS: cp:#{@curpos}, max:#{_maxlen}, buf:(#{@buffer.length})"
if @curpos-1 > _maxlen or @buffer.length()-1 > _maxlen
lastchars, lastspace = push_last_word @current_index
#$log.debug "last sapce #{lastspace}, lastchars:#{lastchars},lc:#{lastchars[-1]}, #{@list[@current_index]} "
## wrap on word XX If last char is 10 then insert line
@buffer = @list[@current_index]
if @curpos-1 > _maxlen or @curpos-1 > @buffer.length()-1
ret = down
# keep the cursor in the same position in the string that was pushed down.
@curpos = oldcurpos - lastspace #lastchars.length # 0
end
end
set_form_row
@buffer = @list[@current_index]
set_form_col
@modified = true
fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, @current_index, char) # 2008-12-24 18:34
@repaint_required = true
0
end | [
"def",
"putch",
"char",
"_maxlen",
"=",
"@maxlen",
"||",
"@width",
"-",
"@internal_width",
"@buffer",
"||=",
"@list",
"[",
"@current_index",
"]",
"return",
"-",
"1",
"if",
"!",
"@editable",
"raise",
"\"putch expects only one char\"",
"if",
"char",
".",
"length",
"!=",
"1",
"oldcurpos",
"=",
"@curpos",
"if",
"@overwrite_mode",
"@buffer",
"[",
"@curpos",
"]",
"=",
"char",
"else",
"@buffer",
".",
"insert",
"(",
"@curpos",
",",
"char",
")",
"end",
"@curpos",
"+=",
"1",
"if",
"@curpos",
"-",
"1",
">",
"_maxlen",
"or",
"@buffer",
".",
"length",
"(",
")",
"-",
"1",
">",
"_maxlen",
"lastchars",
",",
"lastspace",
"=",
"push_last_word",
"@current_index",
"@buffer",
"=",
"@list",
"[",
"@current_index",
"]",
"if",
"@curpos",
"-",
"1",
">",
"_maxlen",
"or",
"@curpos",
"-",
"1",
">",
"@buffer",
".",
"length",
"(",
")",
"-",
"1",
"ret",
"=",
"down",
"@curpos",
"=",
"oldcurpos",
"-",
"lastspace",
"end",
"end",
"set_form_row",
"@buffer",
"=",
"@list",
"[",
"@current_index",
"]",
"set_form_col",
"@modified",
"=",
"true",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"oldcurpos",
",",
"@curpos",
",",
"self",
",",
":INSERT",
",",
"@current_index",
",",
"char",
")",
"@repaint_required",
"=",
"true",
"0",
"end"
]
| add one char. careful, i shoved a string in yesterday. | [
"add",
"one",
"char",
".",
"careful",
"i",
"shoved",
"a",
"string",
"in",
"yesterday",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L696-L731 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.remove_last_word | def remove_last_word lineno
@list[lineno].chomp!
line=@list[lineno]
lastspace = line.rindex(" ")
if !lastspace.nil?
lastchars = line[lastspace+1..-1]
@list[lineno].slice!(lastspace..-1)
$log.debug " remove_last: lastspace #{lastspace},#{lastchars},#{@list[lineno]}"
fire_handler :CHANGE, InputDataEvent.new(lastspace,lastchars.length, self, :DELETE, lineno, lastchars) # 2008-12-26 23:06
return lastchars
end
return nil
end | ruby | def remove_last_word lineno
@list[lineno].chomp!
line=@list[lineno]
lastspace = line.rindex(" ")
if !lastspace.nil?
lastchars = line[lastspace+1..-1]
@list[lineno].slice!(lastspace..-1)
$log.debug " remove_last: lastspace #{lastspace},#{lastchars},#{@list[lineno]}"
fire_handler :CHANGE, InputDataEvent.new(lastspace,lastchars.length, self, :DELETE, lineno, lastchars) # 2008-12-26 23:06
return lastchars
end
return nil
end | [
"def",
"remove_last_word",
"lineno",
"@list",
"[",
"lineno",
"]",
".",
"chomp!",
"line",
"=",
"@list",
"[",
"lineno",
"]",
"lastspace",
"=",
"line",
".",
"rindex",
"(",
"\" \"",
")",
"if",
"!",
"lastspace",
".",
"nil?",
"lastchars",
"=",
"line",
"[",
"lastspace",
"+",
"1",
"..",
"-",
"1",
"]",
"@list",
"[",
"lineno",
"]",
".",
"slice!",
"(",
"lastspace",
"..",
"-",
"1",
")",
"$log",
".",
"debug",
"\" remove_last: lastspace #{lastspace},#{lastchars},#{@list[lineno]}\"",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"lastspace",
",",
"lastchars",
".",
"length",
",",
"self",
",",
":DELETE",
",",
"lineno",
",",
"lastchars",
")",
"return",
"lastchars",
"end",
"return",
"nil",
"end"
]
| removes and returns last word in given line number, or nil if no whitespace | [
"removes",
"and",
"returns",
"last",
"word",
"in",
"given",
"line",
"number",
"or",
"nil",
"if",
"no",
"whitespace"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L733-L745 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.move_chars_up | def move_chars_up
oldprow = @current_index
oldcurpos = @curpos
_maxlen = @maxlen || @width - @internal_width
space_left = _maxlen - @buffer.length
can_move = [space_left, next_line.length].min
carry_up = @list[@current_index+1].slice!(0, can_move)
@list[@current_index] << carry_up
delete_line(@current_index+1) if next_line().length==0
fire_handler :CHANGE, InputDataEvent.new(oldcurpos,oldcurpos+can_move, self, :INSERT, oldprow, carry_up) # 2008-12-24 18:34
end | ruby | def move_chars_up
oldprow = @current_index
oldcurpos = @curpos
_maxlen = @maxlen || @width - @internal_width
space_left = _maxlen - @buffer.length
can_move = [space_left, next_line.length].min
carry_up = @list[@current_index+1].slice!(0, can_move)
@list[@current_index] << carry_up
delete_line(@current_index+1) if next_line().length==0
fire_handler :CHANGE, InputDataEvent.new(oldcurpos,oldcurpos+can_move, self, :INSERT, oldprow, carry_up) # 2008-12-24 18:34
end | [
"def",
"move_chars_up",
"oldprow",
"=",
"@current_index",
"oldcurpos",
"=",
"@curpos",
"_maxlen",
"=",
"@maxlen",
"||",
"@width",
"-",
"@internal_width",
"space_left",
"=",
"_maxlen",
"-",
"@buffer",
".",
"length",
"can_move",
"=",
"[",
"space_left",
",",
"next_line",
".",
"length",
"]",
".",
"min",
"carry_up",
"=",
"@list",
"[",
"@current_index",
"+",
"1",
"]",
".",
"slice!",
"(",
"0",
",",
"can_move",
")",
"@list",
"[",
"@current_index",
"]",
"<<",
"carry_up",
"delete_line",
"(",
"@current_index",
"+",
"1",
")",
"if",
"next_line",
"(",
")",
".",
"length",
"==",
"0",
"fire_handler",
":CHANGE",
",",
"InputDataEvent",
".",
"new",
"(",
"oldcurpos",
",",
"oldcurpos",
"+",
"can_move",
",",
"self",
",",
":INSERT",
",",
"oldprow",
",",
"carry_up",
")",
"end"
]
| tries to move up as many as possible
should not be called if line ends in "\r" | [
"tries",
"to",
"move",
"up",
"as",
"many",
"as",
"possible",
"should",
"not",
"be",
"called",
"if",
"line",
"ends",
"in",
"\\",
"r"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L775-L785 | train |
mare-imbrium/canis | lib/canis/core/widgets/extras/rtextarea.rb | Canis.TextArea.get_text | def get_text
l = getvalue
str = ""
old = " "
l.each_with_index do |line, i|
tmp = line.gsub("\n","")
tmp.gsub!("\r", "\n")
if old[-1,1] !~ /\s/ and tmp[0,1] !~ /\s/
str << " "
end
str << tmp
old = tmp
end
str
end | ruby | def get_text
l = getvalue
str = ""
old = " "
l.each_with_index do |line, i|
tmp = line.gsub("\n","")
tmp.gsub!("\r", "\n")
if old[-1,1] !~ /\s/ and tmp[0,1] !~ /\s/
str << " "
end
str << tmp
old = tmp
end
str
end | [
"def",
"get_text",
"l",
"=",
"getvalue",
"str",
"=",
"\"\"",
"old",
"=",
"\" \"",
"l",
".",
"each_with_index",
"do",
"|",
"line",
",",
"i",
"|",
"tmp",
"=",
"line",
".",
"gsub",
"(",
"\"\\n\"",
",",
"\"\"",
")",
"tmp",
".",
"gsub!",
"(",
"\"\\r\"",
",",
"\"\\n\"",
")",
"if",
"old",
"[",
"-",
"1",
",",
"1",
"]",
"!~",
"/",
"\\s",
"/",
"and",
"tmp",
"[",
"0",
",",
"1",
"]",
"!~",
"/",
"\\s",
"/",
"str",
"<<",
"\" \"",
"end",
"str",
"<<",
"tmp",
"old",
"=",
"tmp",
"end",
"str",
"end"
]
| def to_s this was just annoying in debugs | [
"def",
"to_s",
"this",
"was",
"just",
"annoying",
"in",
"debugs"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/extras/rtextarea.rb#L812-L826 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtree.rb | Canis.Tree.root | def root node=nil, asks_allow_children=false, &block
if @treemodel
return @treemodel.root unless node
raise ArgumentError, "Root already set"
end
raise ArgumentError, "root: node cannot be nil" unless node
@treemodel = Canis::DefaultTreeModel.new(node, asks_allow_children, &block)
end | ruby | def root node=nil, asks_allow_children=false, &block
if @treemodel
return @treemodel.root unless node
raise ArgumentError, "Root already set"
end
raise ArgumentError, "root: node cannot be nil" unless node
@treemodel = Canis::DefaultTreeModel.new(node, asks_allow_children, &block)
end | [
"def",
"root",
"node",
"=",
"nil",
",",
"asks_allow_children",
"=",
"false",
",",
"&",
"block",
"if",
"@treemodel",
"return",
"@treemodel",
".",
"root",
"unless",
"node",
"raise",
"ArgumentError",
",",
"\"Root already set\"",
"end",
"raise",
"ArgumentError",
",",
"\"root: node cannot be nil\"",
"unless",
"node",
"@treemodel",
"=",
"Canis",
"::",
"DefaultTreeModel",
".",
"new",
"(",
"node",
",",
"asks_allow_children",
",",
"&",
"block",
")",
"end"
]
| Sets the given node as root and returns treemodel.
Returns root if no argument given.
Now we return root if already set
Made node nillable so we can return root.
@raise ArgumentError if setting a root after its set
or passing nil if its not been set. | [
"Sets",
"the",
"given",
"node",
"as",
"root",
"and",
"returns",
"treemodel",
".",
"Returns",
"root",
"if",
"no",
"argument",
"given",
".",
"Now",
"we",
"return",
"root",
"if",
"already",
"set",
"Made",
"node",
"nillable",
"so",
"we",
"can",
"return",
"root",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtree.rb#L159-L167 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtree.rb | Canis.Tree.select_default_values | def select_default_values
return if @default_value.nil?
# NOTE list not yet created
raise "list has not yet been created" unless @list
index = node_to_row @default_value
raise "could not find node #{@default_value}, #{@list} " unless index
return unless index
@current_index = index
toggle_row_selection
@default_value = nil
end | ruby | def select_default_values
return if @default_value.nil?
# NOTE list not yet created
raise "list has not yet been created" unless @list
index = node_to_row @default_value
raise "could not find node #{@default_value}, #{@list} " unless index
return unless index
@current_index = index
toggle_row_selection
@default_value = nil
end | [
"def",
"select_default_values",
"return",
"if",
"@default_value",
".",
"nil?",
"raise",
"\"list has not yet been created\"",
"unless",
"@list",
"index",
"=",
"node_to_row",
"@default_value",
"raise",
"\"could not find node #{@default_value}, #{@list} \"",
"unless",
"index",
"return",
"unless",
"index",
"@current_index",
"=",
"index",
"toggle_row_selection",
"@default_value",
"=",
"nil",
"end"
]
| thanks to shoes, not sure how this will impact since widget has text.
show default value as selected and fire handler for it
This is called in repaint, so can raise an error if called on creation
or before repaint. Just set @default_value, and let us handle the rest.
Suggestions are welcome. | [
"thanks",
"to",
"shoes",
"not",
"sure",
"how",
"this",
"will",
"impact",
"since",
"widget",
"has",
"text",
".",
"show",
"default",
"value",
"as",
"selected",
"and",
"fire",
"handler",
"for",
"it",
"This",
"is",
"called",
"in",
"repaint",
"so",
"can",
"raise",
"an",
"error",
"if",
"called",
"on",
"creation",
"or",
"before",
"repaint",
".",
"Just",
"set"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtree.rb#L244-L254 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtree.rb | Canis.Tree.node_to_row | def node_to_row node
crow = nil
@list.each_with_index { |e,i|
if e == node
crow = i
break
end
}
crow
end | ruby | def node_to_row node
crow = nil
@list.each_with_index { |e,i|
if e == node
crow = i
break
end
}
crow
end | [
"def",
"node_to_row",
"node",
"crow",
"=",
"nil",
"@list",
".",
"each_with_index",
"{",
"|",
"e",
",",
"i",
"|",
"if",
"e",
"==",
"node",
"crow",
"=",
"i",
"break",
"end",
"}",
"crow",
"end"
]
| convert a given node to row | [
"convert",
"a",
"given",
"node",
"to",
"row"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtree.rb#L563-L572 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtree.rb | Canis.Tree.expand_parents | def expand_parents node
_path = node.tree_path
_path.each do |e|
# if already expanded parent then break we should break
#set_expanded_state(e, true)
expand_node(e)
end
end | ruby | def expand_parents node
_path = node.tree_path
_path.each do |e|
# if already expanded parent then break we should break
#set_expanded_state(e, true)
expand_node(e)
end
end | [
"def",
"expand_parents",
"node",
"_path",
"=",
"node",
".",
"tree_path",
"_path",
".",
"each",
"do",
"|",
"e",
"|",
"expand_node",
"(",
"e",
")",
"end",
"end"
]
| goes up to root of this node, and expands down to this node
this is often required to make a specific node visible such
as in a dir listing when current dir is deep in heirarchy. | [
"goes",
"up",
"to",
"root",
"of",
"this",
"node",
"and",
"expands",
"down",
"to",
"this",
"node",
"this",
"is",
"often",
"required",
"to",
"make",
"a",
"specific",
"node",
"visible",
"such",
"as",
"in",
"a",
"dir",
"listing",
"when",
"current",
"dir",
"is",
"deep",
"in",
"heirarchy",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtree.rb#L620-L627 | train |
mare-imbrium/canis | lib/canis/core/widgets/deprecated/rtree.rb | Canis.Tree.expand_children | def expand_children node=:current_index
$multiplier = 999 if !$multiplier || $multiplier == 0
node = row_to_node if node == :current_index
return if node.children.empty? # or node.is_leaf?
#node.children.each do |e|
#expand_node e # this will keep expanding parents
#expand_children e
#end
node.breadth_each($multiplier) do |e|
expand_node e
end
$multiplier = 0
_structure_changed true
end | ruby | def expand_children node=:current_index
$multiplier = 999 if !$multiplier || $multiplier == 0
node = row_to_node if node == :current_index
return if node.children.empty? # or node.is_leaf?
#node.children.each do |e|
#expand_node e # this will keep expanding parents
#expand_children e
#end
node.breadth_each($multiplier) do |e|
expand_node e
end
$multiplier = 0
_structure_changed true
end | [
"def",
"expand_children",
"node",
"=",
":current_index",
"$multiplier",
"=",
"999",
"if",
"!",
"$multiplier",
"||",
"$multiplier",
"==",
"0",
"node",
"=",
"row_to_node",
"if",
"node",
"==",
":current_index",
"return",
"if",
"node",
".",
"children",
".",
"empty?",
"node",
".",
"breadth_each",
"(",
"$multiplier",
")",
"do",
"|",
"e",
"|",
"expand_node",
"e",
"end",
"$multiplier",
"=",
"0",
"_structure_changed",
"true",
"end"
]
| this expands all the children of a node, recursively
we can't use multiplier concept here since we are doing a preorder enumeration
we need to do a breadth first enumeration to use a multiplier | [
"this",
"expands",
"all",
"the",
"children",
"of",
"a",
"node",
"recursively",
"we",
"can",
"t",
"use",
"multiplier",
"concept",
"here",
"since",
"we",
"are",
"doing",
"a",
"preorder",
"enumeration",
"we",
"need",
"to",
"do",
"a",
"breadth",
"first",
"enumeration",
"to",
"use",
"a",
"multiplier"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/deprecated/rtree.rb#L632-L645 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.DefaultTableRowSorter.sort | def sort
return unless @model
return if @sort_keys.empty?
$log.debug "TABULAR SORT KEYS #{sort_keys} "
# first row is the header which should remain in place
# We could have kept column headers separate, but then too much of mucking around
# with textpad, this way we avoid touching it
header = @model.delete_at 0
begin
# next line often can give error "array within array" - i think on date fields that
# contain nils
@model.sort!{|x,y|
res = 0
@sort_keys.each { |ee|
e = ee.abs-1 # since we had offsetted by 1 earlier
abse = e.abs
if ee < 0
xx = x[abse]
yy = y[abse]
# the following checks are since nil values cause an error to be raised
if xx.nil? && yy.nil?
res = 0
elsif xx.nil?
res = 1
elsif yy.nil?
res = -1
else
res = y[abse] <=> x[abse]
end
else
xx = x[e]
yy = y[e]
# the following checks are since nil values cause an error to be raised
# whereas we want a nil to be wither treated as a zero or a blank
if xx.nil? && yy.nil?
res = 0
elsif xx.nil?
res = -1
elsif yy.nil?
res = 1
else
res = x[e] <=> y[e]
end
end
break if res != 0
}
res
}
ensure
@model.insert 0, header if header
end
end | ruby | def sort
return unless @model
return if @sort_keys.empty?
$log.debug "TABULAR SORT KEYS #{sort_keys} "
# first row is the header which should remain in place
# We could have kept column headers separate, but then too much of mucking around
# with textpad, this way we avoid touching it
header = @model.delete_at 0
begin
# next line often can give error "array within array" - i think on date fields that
# contain nils
@model.sort!{|x,y|
res = 0
@sort_keys.each { |ee|
e = ee.abs-1 # since we had offsetted by 1 earlier
abse = e.abs
if ee < 0
xx = x[abse]
yy = y[abse]
# the following checks are since nil values cause an error to be raised
if xx.nil? && yy.nil?
res = 0
elsif xx.nil?
res = 1
elsif yy.nil?
res = -1
else
res = y[abse] <=> x[abse]
end
else
xx = x[e]
yy = y[e]
# the following checks are since nil values cause an error to be raised
# whereas we want a nil to be wither treated as a zero or a blank
if xx.nil? && yy.nil?
res = 0
elsif xx.nil?
res = -1
elsif yy.nil?
res = 1
else
res = x[e] <=> y[e]
end
end
break if res != 0
}
res
}
ensure
@model.insert 0, header if header
end
end | [
"def",
"sort",
"return",
"unless",
"@model",
"return",
"if",
"@sort_keys",
".",
"empty?",
"$log",
".",
"debug",
"\"TABULAR SORT KEYS #{sort_keys} \"",
"header",
"=",
"@model",
".",
"delete_at",
"0",
"begin",
"@model",
".",
"sort!",
"{",
"|",
"x",
",",
"y",
"|",
"res",
"=",
"0",
"@sort_keys",
".",
"each",
"{",
"|",
"ee",
"|",
"e",
"=",
"ee",
".",
"abs",
"-",
"1",
"abse",
"=",
"e",
".",
"abs",
"if",
"ee",
"<",
"0",
"xx",
"=",
"x",
"[",
"abse",
"]",
"yy",
"=",
"y",
"[",
"abse",
"]",
"if",
"xx",
".",
"nil?",
"&&",
"yy",
".",
"nil?",
"res",
"=",
"0",
"elsif",
"xx",
".",
"nil?",
"res",
"=",
"1",
"elsif",
"yy",
".",
"nil?",
"res",
"=",
"-",
"1",
"else",
"res",
"=",
"y",
"[",
"abse",
"]",
"<=>",
"x",
"[",
"abse",
"]",
"end",
"else",
"xx",
"=",
"x",
"[",
"e",
"]",
"yy",
"=",
"y",
"[",
"e",
"]",
"if",
"xx",
".",
"nil?",
"&&",
"yy",
".",
"nil?",
"res",
"=",
"0",
"elsif",
"xx",
".",
"nil?",
"res",
"=",
"-",
"1",
"elsif",
"yy",
".",
"nil?",
"res",
"=",
"1",
"else",
"res",
"=",
"x",
"[",
"e",
"]",
"<=>",
"y",
"[",
"e",
"]",
"end",
"end",
"break",
"if",
"res",
"!=",
"0",
"}",
"res",
"}",
"ensure",
"@model",
".",
"insert",
"0",
",",
"header",
"if",
"header",
"end",
"end"
]
| sorts the model based on sort keys and reverse flags
@sort_keys contains indices to sort on
@reverse_flags is an array of booleans, true for reverse, nil or false for ascending | [
"sorts",
"the",
"model",
"based",
"on",
"sort",
"keys",
"and",
"reverse",
"flags"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L117-L168 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.DefaultTableRowSorter.toggle_sort_order | def toggle_sort_order index
index += 1 # increase by 1, since 0 won't multiple by -1
# internally, reverse sort is maintained by multiplying number by -1
@sort_keys ||= []
if @sort_keys.first && index == @sort_keys.first.abs
@sort_keys[0] *= -1
else
@sort_keys.delete index # in case its already there
@sort_keys.delete(index*-1) # in case its already there
@sort_keys.unshift index
# don't let it go on increasing
if @sort_keys.size > 3
@sort_keys.pop
end
end
end | ruby | def toggle_sort_order index
index += 1 # increase by 1, since 0 won't multiple by -1
# internally, reverse sort is maintained by multiplying number by -1
@sort_keys ||= []
if @sort_keys.first && index == @sort_keys.first.abs
@sort_keys[0] *= -1
else
@sort_keys.delete index # in case its already there
@sort_keys.delete(index*-1) # in case its already there
@sort_keys.unshift index
# don't let it go on increasing
if @sort_keys.size > 3
@sort_keys.pop
end
end
end | [
"def",
"toggle_sort_order",
"index",
"index",
"+=",
"1",
"@sort_keys",
"||=",
"[",
"]",
"if",
"@sort_keys",
".",
"first",
"&&",
"index",
"==",
"@sort_keys",
".",
"first",
".",
"abs",
"@sort_keys",
"[",
"0",
"]",
"*=",
"-",
"1",
"else",
"@sort_keys",
".",
"delete",
"index",
"@sort_keys",
".",
"delete",
"(",
"index",
"*",
"-",
"1",
")",
"@sort_keys",
".",
"unshift",
"index",
"if",
"@sort_keys",
".",
"size",
">",
"3",
"@sort_keys",
".",
"pop",
"end",
"end",
"end"
]
| toggle the sort order if given column offset is primary sort key
Otherwise, insert as primary sort key, ascending. | [
"toggle",
"the",
"sort",
"order",
"if",
"given",
"column",
"offset",
"is",
"primary",
"sort",
"key",
"Otherwise",
"insert",
"as",
"primary",
"sort",
"key",
"ascending",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L171-L186 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.DefaultTableRenderer.convert_value_to_text | def convert_value_to_text r
str = []
fmt = nil
field = nil
# we need to loop through chash and get index from it and get that row from r
each_column {|c,i|
e = r[c.index]
w = c.width
l = e.to_s.length
# if value is longer than width, then truncate it
if l > w
fmt = "%.#{w}s "
else
case c.align
when :right
fmt = "%#{w}s "
else
fmt = "%-#{w}s "
end
end
field = fmt % e
# if we really want to print a single column with color, we need to print here itself
# each cell. If we want the user to use tmux formatting in the column itself ...
# FIXME - this must not be done for headers.
#if c.color
#field = "#[fg=#{c.color}]#{field}#[/end]"
#end
str << field
}
return str
end | ruby | def convert_value_to_text r
str = []
fmt = nil
field = nil
# we need to loop through chash and get index from it and get that row from r
each_column {|c,i|
e = r[c.index]
w = c.width
l = e.to_s.length
# if value is longer than width, then truncate it
if l > w
fmt = "%.#{w}s "
else
case c.align
when :right
fmt = "%#{w}s "
else
fmt = "%-#{w}s "
end
end
field = fmt % e
# if we really want to print a single column with color, we need to print here itself
# each cell. If we want the user to use tmux formatting in the column itself ...
# FIXME - this must not be done for headers.
#if c.color
#field = "#[fg=#{c.color}]#{field}#[/end]"
#end
str << field
}
return str
end | [
"def",
"convert_value_to_text",
"r",
"str",
"=",
"[",
"]",
"fmt",
"=",
"nil",
"field",
"=",
"nil",
"each_column",
"{",
"|",
"c",
",",
"i",
"|",
"e",
"=",
"r",
"[",
"c",
".",
"index",
"]",
"w",
"=",
"c",
".",
"width",
"l",
"=",
"e",
".",
"to_s",
".",
"length",
"if",
"l",
">",
"w",
"fmt",
"=",
"\"%.#{w}s \"",
"else",
"case",
"c",
".",
"align",
"when",
":right",
"fmt",
"=",
"\"%#{w}s \"",
"else",
"fmt",
"=",
"\"%-#{w}s \"",
"end",
"end",
"field",
"=",
"fmt",
"%",
"e",
"str",
"<<",
"field",
"}",
"return",
"str",
"end"
]
| Takes the array of row data and formats it using column widths
and returns an array which is used for printing
return an array so caller can color columns if need be | [
"Takes",
"the",
"array",
"of",
"row",
"data",
"and",
"formats",
"it",
"using",
"column",
"widths",
"and",
"returns",
"an",
"array",
"which",
"is",
"used",
"for",
"printing"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L244-L274 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.DefaultTableRenderer.render_data | def render_data pad, lineno, text
text = text.join
# FIXME why repeatedly getting this colorpair
cp = @color_pair
att = @attrib
# added for selection, but will crash if selection is not extended !!! XXX
if @source.is_row_selected? lineno
att = REVERSE
# FIXME currentl this overflows into next row
end
FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
FFI::NCurses.mvwaddstr(pad, lineno, 0, text)
FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
end | ruby | def render_data pad, lineno, text
text = text.join
# FIXME why repeatedly getting this colorpair
cp = @color_pair
att = @attrib
# added for selection, but will crash if selection is not extended !!! XXX
if @source.is_row_selected? lineno
att = REVERSE
# FIXME currentl this overflows into next row
end
FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
FFI::NCurses.mvwaddstr(pad, lineno, 0, text)
FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
end | [
"def",
"render_data",
"pad",
",",
"lineno",
",",
"text",
"text",
"=",
"text",
".",
"join",
"cp",
"=",
"@color_pair",
"att",
"=",
"@attrib",
"if",
"@source",
".",
"is_row_selected?",
"lineno",
"att",
"=",
"REVERSE",
"end",
"FFI",
"::",
"NCurses",
".",
"wattron",
"(",
"pad",
",",
"FFI",
"::",
"NCurses",
".",
"COLOR_PAIR",
"(",
"cp",
")",
"|",
"att",
")",
"FFI",
"::",
"NCurses",
".",
"mvwaddstr",
"(",
"pad",
",",
"lineno",
",",
"0",
",",
"text",
")",
"FFI",
"::",
"NCurses",
".",
"wattroff",
"(",
"pad",
",",
"FFI",
"::",
"NCurses",
".",
"COLOR_PAIR",
"(",
"cp",
")",
"|",
"att",
")",
"end"
]
| passes padded data for final printing or data row
this allows user to do row related coloring without having to tamper
with the headers or other internal workings. This will not be called
if column specific colorign is in effect.
@param text is an array of strings, in the order of actual printing with hidden cols removed | [
"passes",
"padded",
"data",
"for",
"final",
"printing",
"or",
"data",
"row",
"this",
"allows",
"user",
"to",
"do",
"row",
"related",
"coloring",
"without",
"having",
"to",
"tamper",
"with",
"the",
"headers",
"or",
"other",
"internal",
"workings",
".",
"This",
"will",
"not",
"be",
"called",
"if",
"column",
"specific",
"colorign",
"is",
"in",
"effect",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L307-L321 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.DefaultTableRenderer.check_colors | def check_colors
each_column {|c,i|
if c.color || c.bgcolor || c.attrib
@_check_coloring = true
return
end
@_check_coloring = false
}
end | ruby | def check_colors
each_column {|c,i|
if c.color || c.bgcolor || c.attrib
@_check_coloring = true
return
end
@_check_coloring = false
}
end | [
"def",
"check_colors",
"each_column",
"{",
"|",
"c",
",",
"i",
"|",
"if",
"c",
".",
"color",
"||",
"c",
".",
"bgcolor",
"||",
"c",
".",
"attrib",
"@_check_coloring",
"=",
"true",
"return",
"end",
"@_check_coloring",
"=",
"false",
"}",
"end"
]
| check if we need to individually color columns or we can do the entire
row in one shot | [
"check",
"if",
"we",
"need",
"to",
"individually",
"color",
"columns",
"or",
"we",
"can",
"do",
"the",
"entire",
"row",
"in",
"one",
"shot"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L343-L351 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.get_column | def get_column index
return @chash[index] if @chash[index]
# create a new entry since none present
c = ColumnInfo.new
c.index = index
@chash[index] = c
return c
end | ruby | def get_column index
return @chash[index] if @chash[index]
# create a new entry since none present
c = ColumnInfo.new
c.index = index
@chash[index] = c
return c
end | [
"def",
"get_column",
"index",
"return",
"@chash",
"[",
"index",
"]",
"if",
"@chash",
"[",
"index",
"]",
"c",
"=",
"ColumnInfo",
".",
"new",
"c",
".",
"index",
"=",
"index",
"@chash",
"[",
"index",
"]",
"=",
"c",
"return",
"c",
"end"
]
| retrieve the column info structure for the given offset. The offset
pertains to the visible offset not actual offset in data model.
These two differ when we move a column.
@return ColumnInfo object containing width align color bgcolor attrib hidden | [
"retrieve",
"the",
"column",
"info",
"structure",
"for",
"the",
"given",
"offset",
".",
"The",
"offset",
"pertains",
"to",
"the",
"visible",
"offset",
"not",
"actual",
"offset",
"in",
"data",
"model",
".",
"These",
"two",
"differ",
"when",
"we",
"move",
"a",
"column",
"."
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L450-L457 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.content_cols | def content_cols
total = 0
#@chash.each_pair { |i, c|
#@chash.each_with_index { |c, i|
#next if c.hidden
each_column {|c,i|
w = c.width
# if you use prepare_format then use w+2 due to separator symbol
total += w + 1
}
return total
end | ruby | def content_cols
total = 0
#@chash.each_pair { |i, c|
#@chash.each_with_index { |c, i|
#next if c.hidden
each_column {|c,i|
w = c.width
# if you use prepare_format then use w+2 due to separator symbol
total += w + 1
}
return total
end | [
"def",
"content_cols",
"total",
"=",
"0",
"each_column",
"{",
"|",
"c",
",",
"i",
"|",
"w",
"=",
"c",
".",
"width",
"total",
"+=",
"w",
"+",
"1",
"}",
"return",
"total",
"end"
]
| calculate pad width based on widths of columns | [
"calculate",
"pad",
"width",
"based",
"on",
"widths",
"of",
"columns"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L465-L476 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table.fire_column_event | def fire_column_event eve
require 'canis/core/include/ractionevent'
aev = TextActionEvent.new self, eve, get_column(@column_pointer.current_index), @column_pointer.current_index, @column_pointer.last_index
fire_handler eve, aev
end | ruby | def fire_column_event eve
require 'canis/core/include/ractionevent'
aev = TextActionEvent.new self, eve, get_column(@column_pointer.current_index), @column_pointer.current_index, @column_pointer.last_index
fire_handler eve, aev
end | [
"def",
"fire_column_event",
"eve",
"require",
"'canis/core/include/ractionevent'",
"aev",
"=",
"TextActionEvent",
".",
"new",
"self",
",",
"eve",
",",
"get_column",
"(",
"@column_pointer",
".",
"current_index",
")",
",",
"@column_pointer",
".",
"current_index",
",",
"@column_pointer",
".",
"last_index",
"fire_handler",
"eve",
",",
"aev",
"end"
]
| a column traversal has happened.
FIXME needs to be looked into. is this consistent naming wise and are we using the correct object
In old system it was TABLE_TRAVERSAL_EVENT | [
"a",
"column",
"traversal",
"has",
"happened",
".",
"FIXME",
"needs",
"to",
"be",
"looked",
"into",
".",
"is",
"this",
"consistent",
"naming",
"wise",
"and",
"are",
"we",
"using",
"the",
"correct",
"object",
"In",
"old",
"system",
"it",
"was",
"TABLE_TRAVERSAL_EVENT"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L551-L555 | train |
mare-imbrium/canis | lib/canis/core/widgets/table.rb | Canis.Table._init_model | def _init_model array
# clear the column data -- this line should be called otherwise previous tables stuff will remain.
@chash.clear
array.each_with_index { |e,i|
# if columns added later we could be overwriting the width
c = get_column(i)
c.width ||= 10
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new array.size()-1
end | ruby | def _init_model array
# clear the column data -- this line should be called otherwise previous tables stuff will remain.
@chash.clear
array.each_with_index { |e,i|
# if columns added later we could be overwriting the width
c = get_column(i)
c.width ||= 10
}
# maintains index in current pointer and gives next or prev
@column_pointer = Circular.new array.size()-1
end | [
"def",
"_init_model",
"array",
"@chash",
".",
"clear",
"array",
".",
"each_with_index",
"{",
"|",
"e",
",",
"i",
"|",
"c",
"=",
"get_column",
"(",
"i",
")",
"c",
".",
"width",
"||=",
"10",
"}",
"@column_pointer",
"=",
"Circular",
".",
"new",
"array",
".",
"size",
"(",
")",
"-",
"1",
"end"
]
| size each column based on widths of this row of data.
Only changed width if no width for that column | [
"size",
"each",
"column",
"based",
"on",
"widths",
"of",
"this",
"row",
"of",
"data",
".",
"Only",
"changed",
"width",
"if",
"no",
"width",
"for",
"that",
"column"
]
| 8bce60ff9dad321e299a6124620deb4771740b0b | https://github.com/mare-imbrium/canis/blob/8bce60ff9dad321e299a6124620deb4771740b0b/lib/canis/core/widgets/table.rb#L649-L659 | train |
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",
"|",
"ch",
"=",
"get_column",
"(",
"i",
")",
"ch",
".",
"width",
"=",
"c",
".",
"to_s",
".",
"length",
"+",
"2",
"}",
"@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 | train |
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",
"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 | train |
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",
")",
"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 | train |
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 | train |
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",
"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 | train |
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",
"]",
"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 | train |
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",
"=",
"[",
"]",
"@list",
".",
"each_with_index",
"do",
"|",
"fields",
",",
"ix",
"|",
"flag",
"=",
"yield",
"ix",
",",
"fields",
"if",
"flag",
"@indices",
"<<",
"ix",
"end",
"end",
"if",
"@indices",
".",
"count",
">",
"0",
"fire_dimension_changed",
"init_vars",
"else",
"@indices",
"=",
"nil",
"end",
"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 | train |
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",
"|",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"if",
"@positioning",
"==",
":stack",
"c",
".",
"row",
"=",
"@last_row",
"c",
".",
"col",
"=",
"@col",
"+",
"inset",
"@last_row",
"+=",
"1",
"elsif",
"@positioning",
"==",
":relative",
"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",
"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",
"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 | train |
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 | train |
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",
")",
"while",
"true",
"catch",
":close",
"do",
"while",
"(",
"(",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
")",
"!=",
"999",
")",
"if",
"ch",
"==",
"@break_key",
"||",
"ch",
"==",
"@quit_key",
"break",
"end",
"begin",
"if",
"@keyblock",
"str",
"=",
"keycode_tos",
"ch",
"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",
"stopping",
"=",
"@window",
".",
"fire_close_handler",
"@window",
".",
"wrefresh",
"break",
"if",
"stopping",
".",
"nil?",
"||",
"stopping",
"end",
"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 | train |
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",
"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 | train |
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 | train |
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",
"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 | train |
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 | train |
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",
"@window",
"=",
"Canis",
"::",
"Window",
".",
"root_window",
"awin",
"=",
"@window",
"catch",
"(",
":close",
")",
"do",
"@form",
"=",
"Form",
".",
"new",
"@window",
"@form",
".",
"bind_key",
"(",
"[",
"?q",
",",
"?q",
"]",
",",
"'quit'",
")",
"{",
"throw",
":close",
"}",
"if",
"$log",
".",
"debug?",
"$status_message",
"||=",
"Variable",
".",
"new",
"$status_message",
".",
"value",
"=",
"\"\"",
"if",
"block",
"begin",
"yield_or_eval",
"&",
"block",
"if",
"block_given?",
"loop",
"rescue",
"=>",
"ex",
"$log",
".",
"debug",
"(",
"\"APP.rb rescue reached \"",
")",
"$log",
".",
"debug",
"(",
"ex",
")",
"if",
"ex",
"$log",
".",
"debug",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"if",
"ex",
"ensure",
"close",
"if",
"ex",
"puts",
"\"========== EXCEPTION ==========\"",
"p",
"ex",
"puts",
"\"===============================\"",
"puts",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end",
"nil",
"else",
"self",
"end",
"end",
"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 | train |
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",
"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",
"row",
",",
"col",
",",
"width",
",",
"height",
"=",
"arg",
"config",
"[",
":row",
"]",
"=",
"row",
"config",
"[",
":col",
"]",
"=",
"col",
"config",
"[",
":width",
"]",
"=",
"width",
"if",
"width",
"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",
"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 | train |
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",
"@color_pair",
"||=",
"get_color",
"(",
"$datacolor",
",",
"config",
"[",
":color",
"]",
",",
"config",
"[",
":bgcolor",
"]",
")",
"@attrib",
"||=",
"config",
"[",
":attrib",
"]",
"||",
"Ncurses",
"::",
"A_REVERSE",
"ftext",
"=",
"nil",
"if",
"@command_text",
"ftext",
"=",
"text",
"(",
"comp",
")",
"else",
"if",
"!",
"@right_text",
"ftext",
"=",
"\"#{comp.current_index} of #{comp.size} \"",
"end",
"end",
"g",
".",
"printstring",
"(",
"row",
",",
"col",
",",
"ftext",
",",
"@color_pair",
",",
"@attrib",
")",
"if",
"ftext",
"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 | train |
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",
"@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 | train |
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",
"$global_windows",
".",
"delete",
"self",
"Ncurses",
"::",
"Panel",
".",
"del_panel",
"(",
"@panel",
".",
"pointer",
")",
"if",
"@panel",
"delwin",
"(",
")",
"if",
"@window",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"@pads",
".",
"each",
"{",
"|",
"pad",
"|",
"FFI",
"::",
"NCurses",
".",
"delwin",
"(",
"pad",
")",
"if",
"pad",
"pad",
"=",
"nil",
"}",
"if",
"@pads",
"Window",
".",
"refresh_all",
"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 | train |
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",
"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 | train |
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",
"att",
"=",
"get_attrib",
"attr",
"len",
"=",
"width",
"len",
"=",
"Ncurses",
".",
"COLS",
"-",
"0",
"if",
"len",
"==",
"0",
"space_char",
"=",
"\" \"",
".",
"codepoints",
".",
"first",
"(",
"row",
"-",
"1",
")",
".",
"upto",
"(",
"row",
"+",
"height",
"-",
"1",
")",
"do",
"|",
"r",
"|",
"mvwhline",
"(",
"r",
",",
"col",
",",
"space_char",
",",
"len",
")",
"end",
"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 | train |
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",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"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",
"button",
"=",
"Button",
".",
"new",
"nil",
"do",
"text",
"text",
"name",
"bname",
"row",
"brow",
"col",
"bcol",
"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",
";",
"fire_handler",
":PRESS",
",",
"ActionEvent",
".",
"new",
"(",
"tpp",
",",
"index",
",",
"button",
".",
"text",
")",
"}",
"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 | train |
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",
"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",
"32",
",",
"KEY_DOWN",
"+",
"META_KEY",
"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 | train |
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",
"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 | train |
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",
"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 | train |
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",
"@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 | train |
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 | train |
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",
"=",
"{",
"}",
"field",
".",
"instance_variables",
".",
"each",
"do",
"|",
"v",
"|",
"val",
"=",
"field",
".",
"instance_variable_get",
"(",
"v",
")",
"klass",
"=",
"val",
".",
"class",
"if",
"val",
".",
"is_a?",
"Array",
"text",
"<<",
"{",
"v",
".",
"to_s",
"=>",
"val",
"}",
"val",
"=",
"val",
".",
"size",
"elsif",
"val",
".",
"is_a?",
"Hash",
"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",
"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 | train |
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",
".",
"mvwhline",
"(",
"@row",
",",
"1",
",",
"Ncurses",
"::",
"ACS_HLINE",
",",
"@width",
")",
"@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 | train |
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?",
"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",
"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 | train |
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",
"}",
"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 | train |
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",
"if",
"cmenu",
".",
"is_a?",
"Canis",
"::",
"Menu",
"end",
"when",
"KEY_UP",
"cmenu",
".",
"select_prev_item",
"when",
"KEY_ENTER",
",",
"10",
",",
"13",
",",
"32",
"return",
"cmenu",
".",
"fire",
"when",
"KEY_LEFT",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"Menu",
"end",
"ret",
"=",
"cmenu",
".",
"select_left_item",
"if",
"ret",
"==",
":UNHANDLED",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"MenuBar",
"cmenu",
".",
"current_menu",
".",
"pop",
"@@menus",
".",
"pop",
"cmenu",
".",
"destroy",
"return",
":UNHANDLED",
"end",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"Menu",
"cmenu",
".",
"current_menu",
".",
"pop",
"@@menus",
".",
"pop",
"cmenu",
".",
"destroy",
"end",
"end",
"when",
"KEY_RIGHT",
"$log",
".",
"debug",
"\"RIGHTIN MENU : #{text} \"",
"if",
"cmenu",
".",
"active_index",
"if",
"cmenu",
".",
"items",
"[",
"cmenu",
".",
"active_index",
"]",
".",
"is_a?",
"Canis",
"::",
"Menu",
"cmenu",
".",
"fire",
"return",
"end",
"end",
"ret",
"=",
"cmenu",
".",
"select_right_item",
"if",
"ret",
"==",
":UNHANDLED",
"if",
"cmenu",
".",
"parent",
".",
"is_a?",
"Canis",
"::",
"MenuBar",
"$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 | train |
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",
"menu",
"=",
"@items",
"[",
"@active_index",
"]",
"menu",
".",
"on_leave",
"@active_index",
"=",
"index",
"menu",
"=",
"@items",
"[",
"@active_index",
"]",
"menu",
".",
"on_enter",
"@window",
".",
"wmove",
"menu",
".",
"row",
",",
"menu",
".",
"col",
"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 | train |
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",
"@toggle_key",
"||=",
"27",
"set_menu",
"0",
"begin",
"catch",
"(",
":menubarclose",
")",
"do",
"while",
"(",
"(",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
")",
"!=",
"@toggle_key",
")",
"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",
"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",
")",
"throw",
":menubarclose",
"else",
"ret",
"=",
"current_menu",
".",
"handle_key",
"ch",
"if",
"ret",
"==",
":UNHANDLED",
"Ncurses",
".",
"beep",
"else",
"break",
"end",
"end",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"(",
")",
";",
"Ncurses",
".",
"doupdate",
"(",
")",
";",
"@window",
".",
"wrefresh",
"end",
"end",
"ensure",
"$log",
".",
"debug",
"\" DESTROY IN ENSURE\"",
"current_menu",
".",
"clear_menus",
"@repaint_required",
"=",
"false",
"destroy",
"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 | train |
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 | train |
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",
")",
"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",
"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",
"if",
"ret",
"==",
":UNHANDLED",
"case",
"ch",
"when",
"KEY_UP",
"return",
"goto_prev_component",
"when",
"KEY_LEFT",
"return",
"goto_prev_component",
"unless",
"on_first_component?",
"when",
"KEY_RIGHT",
"return",
"goto_next_component",
"when",
"KEY_DOWN",
"return",
"goto_next_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 | train |
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",
"@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 | train |
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",
"if",
"@selected_indices",
".",
"include?",
"crow",
"min",
".",
"upto",
"(",
"max",
")",
"{",
"|",
"i",
"|",
"@selected_indices",
".",
"delete",
"i",
"}",
"lse",
"=",
"ListSelectionEvent",
".",
"new",
"(",
"min",
",",
"max",
",",
"self",
",",
":DELETE",
")",
"fire_handler",
":LIST_SELECTION_EVENT",
",",
"lse",
"else",
"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 | train |
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",
"bind_key",
"(",
"$row_selector",
"||",
"32",
",",
"'toggle selection'",
")",
"{",
"toggle_row_selection",
"}",
"if",
"@selection_mode",
"==",
":multiple",
"bind_key",
"(",
"0",
",",
"'range select'",
")",
"{",
"add_to_selection",
"}",
"bind_key",
"(",
"?+",
",",
":ask_select",
")",
"bind_key",
"(",
"?-",
",",
":ask_unselect",
")",
"bind_key",
"(",
"?a",
",",
":select_all",
")",
"bind_key",
"(",
"?*",
",",
":invert_selection",
")",
"bind_key",
"(",
"?u",
",",
":clear_selection",
")",
"end",
"@_header_adjustment",
"||=",
"0",
"@_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 | train |
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",
"$log",
".",
"debug",
"\" XXX def add of DTM #{nodechild} to root \"",
"node",
"=",
"@root",
".",
"add",
"nodechild",
",",
"allows_children",
",",
"&",
"block",
"if",
"@handler",
"tme",
"=",
"TreeModelEvent",
".",
"new",
"(",
"row",
",",
"row",
",",
":ALL_COLUMNS",
",",
"self",
",",
":INSERT",
")",
"fire_handler",
":TREE_MODEL_EVENT",
",",
"tme",
"end",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"$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",
"@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 | train |
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",
"say",
"statement",
",",
"config",
"@window",
".",
"wrefresh",
"Ncurses",
"::",
"Panel",
".",
"update_panels",
"ch",
"=",
"@window",
".",
"getchar",
"(",
")",
"hide_bottomline",
"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 | train |
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",
"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 | train |
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 | train |
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",
")",
"x",
"=",
"config",
".",
"fetch",
":x",
",",
"0",
"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",
",",
"\"%s\"",
"%",
"text",
")",
";",
"win",
".",
"attroff",
"(",
"color",
")",
";",
"win",
".",
"refresh",
"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 | train |
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",
".",
"display_interactive",
"(",
"text",
")",
"{",
"|",
"l",
"|",
"l",
".",
"focussed_attrib",
"=",
"'bold'",
"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 | train |
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 | train |
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 | train |
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",
".",
"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 | train |
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",
".",
"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 | train |
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",
"@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 | train |
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",
"return",
"if",
"indices",
".",
"nil?",
"||",
"indices",
".",
"empty?",
"indices",
".",
"each",
"{",
"|",
"e",
"|",
"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 | train |
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",
"|",
"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 | train |
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",
"@obj",
".",
"bind_key",
"(",
"$row_selector",
"||",
"'v'",
".",
"ord",
",",
"'toggle selection'",
")",
"{",
"toggle_row_selection",
"}",
"if",
"@obj",
".",
"selection_mode",
"==",
":multiple",
"@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",
"}",
"@obj",
".",
"bind_key",
"(",
"[",
"?g",
",",
"?p",
"]",
",",
"'goto prev selection'",
")",
"{",
"goto_prev_selection",
"}",
"end",
"@_header_adjustment",
"||=",
"0",
"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 | train |
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 | train |
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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.