Expand description
[workflow-terminal
] is a terminal shell that functions uniformly in native
Rust application command-line environment and in WASM-based browser environment.
This is achieved by combining termion
and
xterm.js into a unified module and offering an intermediary
API that can interface with both libraries.
You can initialize this crate from a regular bin project or a WASM project using
dedicated functions and provide a Cli
trait implementing the command-line
interface that will receive input from the underlying terminal.
Workflow Terminal example can be found at https://github.com/workflow-rs/workflow-terminal-examples
Loading in both native and WASM-browser application environment:
use async_trait::async_trait;
use std::sync::Arc;
use workflow_terminal::Cli;
use workflow_terminal::Terminal;
use workflow_terminal::result::Result;
struct ExampleCli;
#[async_trait]
impl Cli for ExampleCli {
async fn digest(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<()> {
Ok(())
}
async fn complete(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<Option<Vec<String>>> {
Ok(None)
}
fn prompt(&self) -> Option<String> {
Some("$ ".to_string())
}
}
#[tokio::test]
let cli = Arc::new(ExampleCli{});
let term = Arc::new(Terminal::try_new(cli.clone(),"$ ")?);
term.init().await?;
term.writeln("Terminal example (type 'help' for list of commands)");
term.run().await?;
Loading terminal in specific element
use async_trait::async_trait;
use std::sync::Arc;
use workflow_terminal::Cli;
use workflow_terminal::Terminal;
use workflow_terminal::result::Result;
use workflow_terminal::{Options, TargetElement};
#[derive(Clone)]
struct ExampleCli;
#[async_trait]
impl Cli for ExampleCli {
async fn digest(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<()> {
Ok(())
}
async fn complete(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<Option<Vec<String>>> {
Ok(None)
}
fn prompt(&self) -> Option<String> {
Some("$ ".to_string())
}
}
let cli = Arc::new(ExampleCli{});
let options = Options::new()
.with_prompt("$ ")
.with_element(TargetElement::Id("terminal_container".to_string()));
//.with_element(TargetElement::Element(element));
//.with_element(TargetElement::Body);
//.with_element(TargetElement::TagName("body".to_string()));
let term = Arc::new(Terminal::try_new_with_options(cli.clone(), options).unwrap());
Re-exports§
pub use cli::Cli;
pub use cli::Context;
pub use cli::Handler;
pub use cli::HandlerCli;
pub use crlf::CrLf;
pub use result::Result;
pub use terminal::parse;
pub use terminal::Event;
pub use terminal::Modifiers;
pub use terminal::Options;
pub use terminal::TargetElement;
pub use terminal::Terminal;
pub use terminal::Theme;
pub use terminal::ThemeOption;
pub use unicode::UnicodeString;
pub use terminal::init_panic_hook;
pub use textwrap;
pub use macros::*;
Modules§
- clear
- Clear line helper (ANSI escape codes to clear the terminal line)
- cli
- Cli trait for implementing a user-side command-line processor.
- crlf
- cursor
- Cursor helper structs (from https://crates.io/crates/termion)
- error
- Errors produced by
workflow_terminal
- keys
- Terminal key definitions
- macros
- prelude
- result
Result
encapsulating internal terminalError
andCliResult
encapsulating a String error (for output in the terminal)- terminal
- Module implementing the terminal interface abstraction
- unicode
Macros§
Functions§
- disable_
raw_ mode - Disables raw mode.