Struct fltk::text::SimpleTerminal

source ·
pub struct SimpleTerminal { /* private fields */ }
Expand description

Creates an editable text display widget to handle terminal-like behavior, such as logging events or debug information. SimpleTerminal already has an internal buffer. It is NOT is a full terminal emulator; it does NOT handle stdio redirection, pipes, pseudo ttys, termio character cooking, keyboard input processing, screen addressing, random cursor positioning, curses compatibility, or VT100/xterm emulation.

Implementations

Sets whether the terminal automatically stays at the bottom

Returns whether the terminal automatically stays at the bottom

Sets the max lines allowed in history

Gets the max lines allowed in history

Enables ANSI sequences within the text to control text colors

Returns whether ANSI sequences are enabled

Appends text to the terminal buffer

Examples found in repository?
examples/terminal.rs (line 26)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    fn append_txt(&mut self, txt: &str) {
        self.append(txt);
        self.style_buffer().unwrap().append(&"A".repeat(txt.len()));
    }

    fn append_dir(&mut self, dir: &str) {
        self.append(dir);
        self.style_buffer().unwrap().append(&"C".repeat(dir.len()));
    }

    fn append_error(&mut self, txt: &str) {
        self.append(txt);
        self.style_buffer().unwrap().append(&"B".repeat(txt.len()));
    }

Appends data to the terminal buffer

Sets the text of the terminal buffer

Gets the text of the terminal buffer

Examples found in repository?
examples/terminal.rs (line 173)
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    pub fn new() -> Term {
        let mut cmd = String::new();

        // Enable different colored text in TestDisplay
        let styles: Vec<StyleTableEntry> = vec![
            StyleTableEntry {
                color: Color::Green,
                font: Font::Courier,
                size: 16,
            },
            StyleTableEntry {
                color: Color::Red,
                font: Font::Courier,
                size: 16,
            },
            StyleTableEntry {
                color: Color::from_u32(0x8000ff),
                font: Font::Courier,
                size: 16,
            },
        ];

        let mut sbuf = TextBuffer::default();
        let mut term = SimpleTerminal::new(5, 5, WIDTH - 10, HEIGHT - 10, "");

        term.set_highlight_data(sbuf.clone(), styles);

        let mut curr = std::env::current_dir()
            .unwrap()
            .to_string_lossy()
            .to_string();
        curr.push_str("$ ");

        term.append_dir(&curr);

        let (s, r) = app::channel();

        term.handle(move |t, ev| {
            // println!("{:?}", app::event());
            // println!("{:?}", app::event_key());
            // println!("{:?}", app::event_text());
            match ev {
                Event::KeyDown => match app::event_key() {
                    Key::Enter => {
                        t.append_txt("\n");
                        t.run_command(&cmd, &mut curr, r);
                        cmd.clear();
                        true
                    }
                    Key::BackSpace => {
                        if !cmd.is_empty() {
                            let c = cmd.pop().unwrap();
                            let len = if c.is_ascii() {
                                1
                            } else {
                                utils::char_len(c) as i32
                            };
                            let text_len = t.text().len() as i32;
                            t.buffer().unwrap().remove(text_len - len, text_len);
                            sbuf.remove(text_len - len, text_len);
                            true
                        } else {
                            false
                        }
                    }
                    _ => {
                        if let Some(ch) = app::event_text().chars().next() {
                            if app::compose().is_some() {
                                let temp = ch.to_string();
                                cmd.push_str(&temp);
                                t.append_txt(&temp);
                                true
                            } else {
                                false
                            }
                        } else {
                            false
                        }
                    }
                },
                Event::KeyUp => {
                    if app::event_state() == Shortcut::Ctrl
                        && app::event_key() == Key::from_char('c')
                    {
                        s.send(true);
                    }
                    false
                }
                _ => false,
            }
        });

        Self { term }
    }

Clears the terminal

Removes count lines from start

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Get the associated TextBuffer
Sets the associated TextBuffer
Get the associated style TextBuffer
Return the text font
Sets the text font
Return the text color
Sets the text color
Return the text size
Sets the text size
Scroll down the Display widget
Insert into Display widget
Set the insert position
Return the insert position
Gets the x and y positions of the cursor
Counts the lines from start to end
Moves the cursor right Read more
Moves the cursor left Read more
Moves the cursor up Read more
Moves the cursor down Read more
Shows/hides the cursor
Sets the style of the text widget
Sets the style of the text widget
Unset the style of the text widget
Sets the cursor style
Sets the cursor color
Sets the scrollbar size in pixels
Sets the scrollbar alignment
Returns the cursor style
Returns the cursor color
Returns the scrollbar size in pixels
Returns the scrollbar alignment
Returns the beginning of the line from the current position. Returns new position as index Read more
Returns the ending of the line from the current position. Returns new position as index Read more
Skips lines from start_pos
Rewinds the lines
Goes to the next word
Goes to the previous word
Returns the position of the start of the word, relative to the current position
Returns the position of the end of the word, relative to the current position
Convert an x pixel position into a column number.
Convert a column number into an x pixel position
Sets the linenumber width
Gets the linenumber width
Sets the linenumber font
Gets the linenumber font
Sets the linenumber size
Gets the linenumber size
Sets the linenumber foreground color
Gets the linenumber foreground color
Sets the linenumber background color
Gets the linenumber background color
Sets the linenumber alignment
Gets the linenumber alignment
Checks whether a pixel is within a text selection
Sets the wrap mode of the Display widget. If the wrap mode is AtColumn, wrap margin is the column. If the wrap mode is AtPixel, wrap margin is the pixel. For more info Read more
Correct a column number based on an unconstrained position
Correct a row number from an unconstrained position
Set the grammar underline color
Get the grammar underline color
Set the spelling underline color
Get the spelling underline color
Set the secondary selection color
Get the secondary selection color
Scrolls the text buffer to show the current insert position
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Creates a new widget, takes an x, y coordinates, as well as a width and height, plus a title Read more
Constructs a widget with the size of its parent
Deletes widgets and their children.
transforms a widget pointer to a Widget, for internal use Read more
Get a widget from base widget Read more
Set a custom handler, where events are managed manually, akin to Fl_Widget::handle(int). Handled or ignored events should return true, unhandled events should return false. takes the widget as a closure argument Read more
Set a custom draw method. takes the widget as a closure argument. macOS requires that WidgetBase::draw actually calls drawing functions Read more
Perform a callback on resize. Avoid resizing the parent or the same widget to avoid infinite recursion Read more
Makes the widget derived Read more

Initialize center of another widget

Initialize center of another widget

Initialize to a position x, y
Initialize to size width, height
Initialize with a label
Initialize with alignment
Initialize with type
Initialize at bottom of another widget
Initialize above of another widget
Initialize right of another widget
Initialize left of another widget
Initialize center of another widget
Initialize center of parent
Initialize to the size of another widget
Initialize to the size of the parent
Set to position x, y
Set to dimensions width and height
Sets the widget’s label. labels support special symbols preceded by an @ sign. and for the associated formatting. Read more
Redraws a widget, necessary for resizing and changing positions
Shows the widget
Hides the widget
Returns the x coordinate of the widget
Returns the y coordinate of the widget
Returns the width of the widget
Returns the height of the widget
Returns the width of the widget
Returns the height of the widget
Returns the label of the widget
Measures the label’s width and height
transforms a widget to a base Fl_Widget, for internal use Read more
Activates the widget
Deactivates the widget
Redraws the label of the widget
Resizes and/or moves the widget, takes x, y, width and height
Does a simple resize ignoring class-specific resize functionality
Returns the tooltip text
Sets the tooltip text
Returns the widget color
Sets the widget’s color
Returns the widget label’s color
Sets the widget label’s color
Returns the widget label’s font
Sets the widget label’s font
Returns the widget label’s size
Sets the widget label’s size
Returns the widget label’s type
Sets the widget label’s type
Returns the widget’s frame type
Sets the widget’s frame type
Returns whether the widget was changed
Mark the widget as changed
Clears the changed status of the widget
Returns the alignment of the widget
Sets the alignment of the widget
Sets the default callback trigger for a widget, equivalent to when()
Return the callback trigger, equivalent to when()
Returns the parent of the widget
Gets the selection color of the widget
Sets the selection color of the widget
Runs the already registered callback
Returns the direct window holding the widget
Returns the topmost window holding the widget
Checks whether a widget is capable of taking events
Make the widget take focus Read more
Set the widget to have visible focus
Clear visible focus
Set the visible focus using a flag
Return whether the widget has visible focus
Return whether the widget has focus
Check if a widget was deleted
Return whether the widget was damaged
Signal the widget as damaged and it should be redrawn in the next event loop cycle
Return the damage mask
Signal the type of damage a widget received
Clear the damaged flag
Return the widget as a window if it’s a window
Return the widget as a group widget if it’s a group widget
Checks whether the self widget is inside another widget
Returns the widget type when applicable
Sets the widget type
Sets the image of the widget
Sets the image of the widget scaled to the widget’s size
Gets the image associated with the widget
Sets the deactivated image of the widget
Sets the deactivated image of the widget scaled to the widget’s size
Gets the deactivated image associated with the widget
Sets the callback when the widget is triggered (clicks for example) takes the widget as a closure argument Read more
Emits a message on callback using a sender
Upcast a WidgetExt to a Widget Read more
Returns whether a widget is visible
Returns whether a widget or any of its parents are visible (recursively)
Return whether two widgets object point to the same widget
Returns whether a widget is active
Returns whether a widget or any of its parents are active (recursively)
Handle a specific event
Check whether a widget is derived

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.