Expand description

github crates.io docs.rs license

[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, _term: Arc<Terminal>, _cmd: String) -> Result<()>{
        Ok(())
    }
    async fn complete(&self, _term: Arc<Terminal>, _cmd: String) -> Result<Vec<String>>{
        Ok(vec![])
    }
}

#[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, _term: Arc<Terminal>, _cmd: String) -> Result<()>{
        Ok(())
    }
    async fn complete(&self, _term: Arc<Terminal>, _cmd: String) -> Result<Vec<String>>{
        Ok(vec![])
    }
}


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

Modules