workflow_terminal/lib.rs
1//!
2//! [<img alt="github" src="https://img.shields.io/badge/github-workflow--rs-8da0cb?style=for-the-badge&labelColor=555555&color=8da0cb&logo=github" height="20">](https://github.com/workflow-rs/workflow-rs)
3//! [<img alt="crates.io" src="https://img.shields.io/crates/v/workflow-terminal.svg?maxAge=2592000&style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/workflow-terminal)
4//! [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-workflow--terminal-56c2a5?maxAge=2592000&style=for-the-badge&logo=docs.rs" height="20">](https://docs.rs/workflow-terminal)
5//! <img alt="license" src="https://img.shields.io/crates/l/workflow-terminal.svg?maxAge=2592000&color=6ac&style=for-the-badge&logoColor=fff" height="20">
6//! <img src="https://img.shields.io/badge/platform- native -informational?style=for-the-badge&color=50a0f0" height="20">
7//! <img src="https://img.shields.io/badge/platform- wasm32/browser -informational?style=for-the-badge&color=50a0f0" height="20">
8//!
9//! [`workflow-terminal`] is a terminal shell that functions uniformly in native
10//! Rust application command-line environment and in WASM-based browser environment.
11//!
12//! This is achieved by combining [`termion`](https://crates.io/crates/termion) and
13//! [xterm.js](http://xtermjs.org) into a unified module and offering an intermediary
14//! API that can interface with both libraries.
15//!
16//! You can initialize this crate from a regular bin project or a WASM project using
17//! dedicated functions and provide a [`Cli`] trait implementing the command-line
18//! interface that will receive input from the underlying terminal.
19//!
20//! Workflow Terminal example can be found at
21//! [https://github.com/workflow-rs/workflow-terminal-examples](https://github.com/workflow-rs/workflow-terminal-examples)
22//!
23//! Loading in both native and WASM-browser application environment:
24//! ```rust
25//! use async_trait::async_trait;
26//! use std::sync::Arc;
27//! use workflow_terminal::Cli;
28//! use workflow_terminal::Terminal;
29//! use workflow_terminal::result::Result;
30//!
31//! struct ExampleCli;
32//! #[async_trait]
33//! impl Cli for ExampleCli {
34//! async fn digest(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<()> {
35//! Ok(())
36//! }
37//! async fn complete(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<Option<Vec<String>>> {
38//! Ok(None)
39//! }
40//! fn prompt(&self) -> Option<String> {
41//! Some("$ ".to_string())
42//! }
43//! }
44//!
45//! #[tokio::test]
46//! # async fn test()->Result<()>{
47//! let cli = Arc::new(ExampleCli{});
48//! let term = Arc::new(Terminal::try_new(cli.clone(),"$ ")?);
49//! term.init().await?;
50//! term.writeln("Terminal example (type 'help' for list of commands)");
51//! term.run().await?;
52//! # Ok(())
53//! # }
54//!
55//! ```
56//!
57//! Loading terminal in specific element
58//! ```rust
59//! use async_trait::async_trait;
60//! use std::sync::Arc;
61//! use workflow_terminal::Cli;
62//! use workflow_terminal::Terminal;
63//! use workflow_terminal::result::Result;
64//! use workflow_terminal::{Options, TargetElement};
65//!
66//! #[derive(Clone)]
67//! struct ExampleCli;
68//! #[async_trait]
69//! impl Cli for ExampleCli {
70//! async fn digest(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<()> {
71//! Ok(())
72//! }
73//! async fn complete(self : Arc<Self>, _term: Arc<Terminal>, _cmd: String) -> Result<Option<Vec<String>>> {
74//! Ok(None)
75//! }
76//! fn prompt(&self) -> Option<String> {
77//! Some("$ ".to_string())
78//! }
79//! }
80//!
81//! # fn test(){
82//!
83//! let cli = Arc::new(ExampleCli{});
84//! let options = Options::new()
85//! .with_prompt("$ ")
86//! .with_element(TargetElement::Id("terminal_container".to_string()));
87//! //.with_element(TargetElement::Element(element));
88//! //.with_element(TargetElement::Body);
89//! //.with_element(TargetElement::TagName("body".to_string()));
90//! let term = Arc::new(Terminal::try_new_with_options(cli.clone(), options).unwrap());
91//!
92//! # }
93//! ```
94//!
95
96extern crate self as workflow_terminal;
97
98pub mod clear;
99pub mod cli;
100pub mod crlf;
101pub mod cursor;
102pub mod error;
103pub mod keys;
104pub mod macros;
105pub mod prelude;
106pub mod result;
107pub mod terminal;
108pub mod unicode;
109
110pub use cli::{Cli, Context, Handler, HandlerCli};
111pub use crlf::CrLf;
112pub use macros::*;
113pub use result::Result;
114pub use terminal::parse;
115pub use terminal::Event;
116pub use terminal::Modifiers;
117pub use terminal::Options;
118pub use terminal::TargetElement;
119pub use terminal::Terminal;
120pub use terminal::{Theme, ThemeOption};
121pub use textwrap;
122pub use unicode::UnicodeString;
123
124cfg_if::cfg_if! {
125 if #[cfg(target_arch = "wasm32")] {
126 pub use terminal::{xterm, bindings};
127 } else {
128 pub use terminal::{disable_raw_mode,init_panic_hook};
129 }
130}