mruby binding for editline(3) library.
el = EditLine.new
el.set_prompt "prompt> "
el.set_addfn("mruby-editline-sample-complete", "complete a word") do |ch|
el.insertstr "hello!"
EditLine::CC_REFRESH
end
el.set_bind("^I", "mruby-editline-sample-complete")
while line = el.gets
puts "cmd =>" + line
end
.new
- Create a new EditLine instance. (
el_init
)
- Create a new EditLine instance. (
#gets -> String|nil
- Read a line from the tty. Returns the line read if successful, returns
nil if no characters were read, or raises a RuntimeError if an error
occurred. (
el_gets
)
- Read a line from the tty. Returns the line read if successful, returns
nil if no characters were read, or raises a RuntimeError if an error
occurred. (
#deletestr(str)
- Delete
count
characters before the cursor.
- Delete
#insertstr(str) -> Fixnum
- Insert str into the line at the cursor. Returns -1 if str is empty or
won't fit, and 0 otherwise. (
el_insertstr
)
- Insert str into the line at the cursor. Returns -1 if str is empty or
won't fit, and 0 otherwise. (
#line -> [String, Fixnum]
- Return the current line and the position of cursor. (
el_line
)
- Return the current line and the position of cursor. (
#parse(argv) -> Fixnum
- Parses the
argv
array to execute builtin editline commands. If the command is prefixed with "prog:" then el_parse() will only execute the command if "prog" matches the prog argument supplied to el_init(). The return value is -1 if the command is unknown, 0 if there was no error or "prog" didn't match, or 1 if the command returned an error. Refer to editrc(5) for more information. (el_parse
)
- Parses the
#push(str)
- Pushes str back onto the input stream. This is used by the macro expansion mechanism. Refer to the description of bind -s in editrc(5) for more information.
#resize
- Must be called if the terminal size changes. If
#set_signal(flag)
has been called with non-zeroflag
, then this is done automatically. Otherwise, it's the responsibility of the application to callel_resize()
on the appropriate occasions. (el_resize
)
- Must be called if the terminal size changes. If
#set_addfn(name, help, &proc)
- add an user defined function
name
.help
is a description of it.proc
is a callback function. The return value ofproc
should be one of EditLine::CC_nnn. (el_set(EL_ADDFN)
) - Caveats: You cannot define more than 10 functions. If you need more,
change lines around the definition of
USERFUNCTIONS
in src/editline.c.
- add an user defined function
#set_bind(key, proc)
proc
can be String or Proc. (el_set(EL_BIND)
)
#set_prompt(proc, c=nil)
- Define prompt printing function as
proc
, which is to return a string that contains the prompt. (el_set(EL_PROMPT)
,el_set(EL_PROMPT_ESC)
)- Note: ANSI escape sequence in prompt string does not work as expected due to a bug in editline library.
- Define prompt printing function as
#set_setty(*args) -> Fixnum
- Perform the setty builtin command. Refer to editrc(5) for more
information. (
el_set(EL_SETTY)
)
- Perform the setty builtin command. Refer to editrc(5) for more
information. (
#set_signal(flag) -> Fixnum
- If flag is non-zero, editline will install its own signal handler
for the following signals when reading command input: SIGCONT,
SIGHUP, SIGINT, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP, and SIGWINCH.
Otherwise, the current signal handlers will be used.
(
el_set(EL_SIGNAL)
)
- If flag is non-zero, editline will install its own signal handler
for the following signals when reading command input: SIGCONT,
SIGHUP, SIGINT, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP, and SIGWINCH.
Otherwise, the current signal handlers will be used.
(
#get_gettc(name) -> String|Fixnum
- If name is a valid termcap(5) capability, return the current value of
that capability. (
el_get(EL_GETTC)
)- If not, raises an ArgumentError.
- If name is a valid termcap(5) capability, return the current value of
that capability. (
(Descriptions above are from editline(3) manual page.)
Copyright (c) 2017 Internet Initiative Japan Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.