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