workflow_terminal/terminal/
options.rs

1//!
2//! Terminal creation options
3//!
4
5use web_sys::Element;
6
7/// Indicates the target element to which the Terminal instance should be
8/// bound to in DOM (WASM-browser only)
9pub enum TargetElement {
10    /// Bind to the document body
11    Body,
12    /// Bind to a specific supplied [`web_sys::Element`]
13    Element(Element),
14    /// Bind to the element with a specific tag name
15    TagName(String),
16    /// Bind to the element with a specific id
17    Id(String),
18}
19
20/// Terminal options
21pub struct Options {
22    /// Default prompt (string such as `"$ "`)
23    pub prompt: Option<String>,
24    /// Target DOM element (when running under WASM)
25    pub element: TargetElement,
26    /// Disable internal clipboard handling
27    /// (useful when using clipboard API calls externally)
28    pub disable_clipboard_handling: bool,
29    /// Default font family (xterm.js only)
30    pub font_family: Option<String>,
31    /// Default font size (xterm.js only)
32    pub font_size: Option<f64>,
33    /// Default scrollback limit (xterm.js only)
34    pub scrollback: Option<u32>,
35}
36
37impl Default for Options {
38    fn default() -> Self {
39        Options {
40            prompt: None,
41            element: TargetElement::Body,
42            disable_clipboard_handling: false,
43            font_family: None,
44            font_size: None,
45            scrollback: Some(2048),
46        }
47    }
48}
49
50impl Options {
51    /// Create new default options
52    pub fn new() -> Options {
53        Options::default()
54    }
55
56    /// Set prompt string
57    pub fn with_prompt(mut self, prompt: &str) -> Self {
58        self.prompt = Some(prompt.into());
59        self
60    }
61
62    /// Set scrollback limit
63    pub fn with_scrollback(mut self, scrollback: u32) -> Self {
64        self.scrollback = Some(scrollback);
65        self
66    }
67
68    /// Set target element
69    pub fn with_element(mut self, element: TargetElement) -> Self {
70        self.element = element;
71        self
72    }
73
74    /// Get prompt string
75    pub fn prompt(&self) -> String {
76        self.prompt.as_ref().unwrap_or(&"$ ".to_string()).clone()
77    }
78}