Crates.io | revolver |
lib.rs | revolver |
version | 0.2.0 |
source | src |
created_at | 2022-11-24 23:07:28.228295 |
updated_at | 2022-12-22 02:17:46.700631 |
description | A library for building REPL applications. |
homepage | |
repository | https://github.com/kindredgroup/revolver |
max_upload_size | |
id | 722456 |
size | 85,157 |
A library for building REPL applications.
The Command
trait is a specification of an executable command — the 'execute' part of a REPL application. A command will typically be accompanied by a NamedCommandParser
implementation for converting command strings into Command
objects.
Command
s and NamedCommandParser
s are the only two traits that you must implement. Everything else is just configuration.
A Commander
decodes user input (typically a line read from a terminal interface) into a dynamic Command
object, using a preconfigured map of NamedCommandParser
s.
Revolver comes with two useful built-in commands that can be used out-of-the-box.
help
— A self-help guide, outlining the available commands and how to use them.quit
— Terminates the REPL. (It only exits the loop; it does not terminate the application.)These commands are opt-in, meaning that you must explicitly include their parsers in your Commander
to enable them.
The Terminal
trait represents a text-based interface with the user. It fulfils the 'read' and 'print' parts of a REPL application.
Revolver is currently bundled with two Terminal
implementations:
Streaming
— A terminal device that composes over I/O streams using Input
and Output
traits. Out-of-the-box adapters exist for stdin
and stdout
streams. Adapters may be written to interface with nonstandard streams by supplying a custom closure.Mock
— A way of mocking a terminal device for feeding input, capturing output, and performing various assertions.Looper
is a mechanism for iteratively running commands based on successive user input. It fulfils the 'loop' part of a REPL application.
cargo add revolver
See examples/calculator.rs
for a simple calculator REPL.