class Fancyline
- Fancyline
- Reference
- Object
Overview
Readline-esque library with some fancy features.
Quick usage
A simple greeter can be built like this:
require "fancyline"
fancy = Fancyline.new
name = fancy.readline("Name: ")
puts "Hello, #{name}"
Have a look in the samples/
directory for more!
Defined in:
fancyline.crfancyline/completion.cr
fancyline/context.cr
fancyline/drawable.cr
fancyline/editor.cr
fancyline/history.cr
fancyline/key.cr
fancyline/key_action.cr
fancyline/string_util.cr
fancyline/tty.cr
fancyline/tty/dumb.cr
fancyline/tty/vt100.cr
fancyline/version.cr
fancyline/widget.cr
fancyline/widget/completion.cr
fancyline/widget/history.cr
fancyline/widget/history_search.cr
Constant Summary
-
VERSION =
"0.4.1"
Constructors
Instance Method Summary
-
#actions : KeyAction
Key bindings (or "key map")
-
#autocomplete : Middleware_autocomplete
Returns the autocomplete middleware object.
-
#call_autocomplete(ctx : Context, range : Range(Int32, Int32), word : String)
Calls the final stage of autocomplete directly, without calling any previous stages.
-
#call_display(ctx : Context, line : String)
Calls the final stage of display directly, without calling any previous stages.
-
#call_sub_info(ctx : Context)
Calls the final stage of sub_info directly, without calling any previous stages.
-
#context : Context | Nil
Currently active context, if any
-
#display : Middleware_display
Returns the display middleware object.
-
#grab_output(&)
Grabs the output: If there's a running prompt, clears it from the screen.
-
#history : History
History of previous input
-
#input : IO
Device to read input from
-
#output : IO
Device to write terminal output to
-
#raw_from_tc_mode!(fd, mode)
Copied from IO::FileDescriptor, as this method is sadly
private
. -
#readline(prompt, rprompt : String | Nil = nil, history = true) : String | Nil
Reads a line, showing the prompt.
-
#sub_info : Middleware_sub_info
Returns the sub_info middleware object.
-
#tty : Tty
TTY control
-
#tty=(tty : Tty)
TTY control
Constructor Detail
Instance Method Detail
Calls the final stage of autocomplete directly, without calling any previous stages.
Calls the final stage of display directly, without calling any previous stages.
Calls the final stage of sub_info directly, without calling any previous stages.
Grabs the output: If there's a running prompt, clears it from the screen.
Then yield
s with no arguments. Upon returning, redraws the prompt.
If there's no running prompt yield
s.
Use this method to write data onto the screen while the user is editing the prompt. Such data could be log output while letting the user give commands to a running process.
The redrawing of the prompt happens in an ensure
block. Thus, if the
block raises, the prompt will be redrawn anyway.
See sample/concurrent_output.cr
for sample code.
Note: Raw mode, if currently active on the output, is temporarily disabled during execution of the block.
Reads a line, showing the prompt. If history is true
, the input is
added to the #history
. Returns the input string, or nil
, if the input
stream went EOF, this may happen when the user inputs Ctrl-D
. The
returned string does not end with a new-line, but surrounding whitespace as
input by the user is retained.
If rprompt is given, it'll be displayed on the right-hand end of the
terminal. If the users input comes near it (Editor::RPROMPT_MARGIN
), it
will be hidden. If no rprompt is given, none is shown.
If this instance already has a context running it will raise.
Ctrl-C, or an interrupt
By default a key press of Ctrl-C
(^C
) will raise an Interrupt
. Do not
confuse this with SIGINT
, which is not raised by this method. Nor is a
SIGINT
sent by a different process caught or handled.
To change the behaviour of raising Interrupt
, change the mapping of it:
fancyline.actions.set(Fancyline::Key::Control::CtrlC) do |ctx|
ctx.reject! # Reject input, make `Fancyline#readline` return `nil`
end