Docs.rs
  • workflow-terminal-0.18.0
    • workflow-terminal 0.18.0
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • aspect
    • surinder83singh
    • Dependencies
      • async-std ^1.12.0 normal
      • async-trait ^0.1.74 normal
      • cfg-if ^1.0.0 normal
      • downcast ^0.11.0 normal
      • futures ^0.3.29 normal
      • js-sys ^0.3.64 normal
      • numtoa ^0.2.4 normal
      • nw-sys ^0.1.6 normal
      • pad ^0.1.6 normal
      • regex ^1.10.2 normal
      • textwrap ^0.16.0 normal
      • thiserror ^1.0.50 normal
      • wasm-bindgen ^0.2.93 normal
      • wasm-bindgen-futures ^0.4.43 normal
      • web-sys ^0.3.70 normal
      • workflow-core ^0.18.0 normal
      • workflow-dom ^0.18.0 normal
      • workflow-log ^0.18.0 normal
      • workflow-terminal-macros ^0.18.0 normal
      • workflow-wasm ^0.18.0 normal
      • tokio ^1.33.0 dev
      • crossterm ^0.27.0 normal
      • termion ^4.0.2 normal optional
    • Versions
    • 16.78% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate workflow_terminal

workflow_terminal0.18.0

  • All Items

Crate Items

  • Re-exports
  • Modules
  • Macros
  • Functions
  • Derive Macros

Crates

  • workflow_terminal

Crate workflow_terminal

Source
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 : 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 terminal Error and CliResult encapsulating a String error (for output in the terminal)
terminal
Module implementing the terminal interface abstraction
unicode

Macros§

terrorln
tpara
tprint
tprintln
twarnln

Functions§

disable_raw_mode
Disables raw mode.

Derive Macros§

Handler

Results

Settings
Help

Query parser error: "Unexpected - (did you mean ->?)".