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
sourceimpl SimpleTerminal
impl SimpleTerminal
sourcepub fn set_stay_at_bottom(&mut self, arg1: bool)
pub fn set_stay_at_bottom(&mut self, arg1: bool)
Sets whether the terminal automatically stays at the bottom
sourcepub fn stay_at_bottom(&self) -> bool
pub fn stay_at_bottom(&self) -> bool
Returns whether the terminal automatically stays at the bottom
sourcepub fn set_history_lines(&mut self, arg1: i32)
pub fn set_history_lines(&mut self, arg1: i32)
Sets the max lines allowed in history
sourcepub fn history_lines(&self) -> i32
pub fn history_lines(&self) -> i32
Gets the max lines allowed in history
sourcepub fn set_ansi(&mut self, val: bool)
pub fn set_ansi(&mut self, val: bool)
Enables ANSI sequences within the text to control text colors
sourcepub fn append(&mut self, s: &str)
pub fn append(&mut self, s: &str)
Appends text to the terminal buffer
Examples found in repository?
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()));
}
sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Gets the text of the terminal buffer
Examples found in repository?
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 }
}
sourcepub fn remove_lines(&mut self, start: i32, count: i32)
pub fn remove_lines(&mut self, start: i32, count: i32)
Removes count
lines from start
Trait Implementations
sourceimpl Clone for SimpleTerminal
impl Clone for SimpleTerminal
sourcefn clone(&self) -> SimpleTerminal
fn clone(&self) -> SimpleTerminal
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for SimpleTerminal
impl Debug for SimpleTerminal
sourceimpl Default for SimpleTerminal
impl Default for SimpleTerminal
sourceimpl DisplayExt for SimpleTerminal
impl DisplayExt for SimpleTerminal
sourcefn buffer(&self) -> Option<TextBuffer>
fn buffer(&self) -> Option<TextBuffer>
TextBuffer
sourcefn set_buffer<B: Into<Option<TextBuffer>>>(&mut self, buffer: B)
fn set_buffer<B: Into<Option<TextBuffer>>>(&mut self, buffer: B)
TextBuffer
sourcefn style_buffer(&self) -> Option<TextBuffer>
fn style_buffer(&self) -> Option<TextBuffer>
TextBuffer
sourcefn set_text_font(&mut self, font: Font)
fn set_text_font(&mut self, font: Font)
sourcefn text_color(&self) -> Color
fn text_color(&self) -> Color
sourcefn set_text_color(&mut self, color: Color)
fn set_text_color(&mut self, color: Color)
sourcefn set_text_size(&mut self, sz: i32)
fn set_text_size(&mut self, sz: i32)
sourcefn set_insert_position(&mut self, new_pos: i32)
fn set_insert_position(&mut self, new_pos: i32)
sourcefn insert_position(&self) -> i32
fn insert_position(&self) -> i32
sourcefn position_to_xy(&self, pos: i32) -> (i32, i32)
fn position_to_xy(&self, pos: i32) -> (i32, i32)
sourcefn count_lines(&self, start: i32, end: i32, is_line_start: bool) -> i32
fn count_lines(&self, start: i32, end: i32, is_line_start: bool) -> i32
sourcefn show_cursor(&mut self, val: bool)
fn show_cursor(&mut self, val: bool)
sourcefn set_highlight_data<B: Into<Option<TextBuffer>>>(
&mut self,
style_buffer: B,
entries: Vec<StyleTableEntry>
)
fn set_highlight_data<B: Into<Option<TextBuffer>>>(
&mut self,
style_buffer: B,
entries: Vec<StyleTableEntry>
)
sourcefn set_highlight_data_ext<B: Into<Option<TextBuffer>>>(
&mut self,
style_buffer: B,
entries: Vec<StyleTableEntryExt>
)
fn set_highlight_data_ext<B: Into<Option<TextBuffer>>>(
&mut self,
style_buffer: B,
entries: Vec<StyleTableEntryExt>
)
sourcefn unset_highlight_data(&mut self, style_buffer: TextBuffer)
fn unset_highlight_data(&mut self, style_buffer: TextBuffer)
sourcefn set_cursor_style(&mut self, style: Cursor)
fn set_cursor_style(&mut self, style: Cursor)
sourcefn set_cursor_color(&mut self, color: Color)
fn set_cursor_color(&mut self, color: Color)
sourcefn set_scrollbar_size(&mut self, size: i32)
fn set_scrollbar_size(&mut self, size: i32)
sourcefn set_scrollbar_align(&mut self, align: Align)
fn set_scrollbar_align(&mut self, align: Align)
sourcefn cursor_style(&self) -> Cursor
fn cursor_style(&self) -> Cursor
sourcefn cursor_color(&self) -> Color
fn cursor_color(&self) -> Color
sourcefn scrollbar_size(&self) -> i32
fn scrollbar_size(&self) -> i32
sourcefn scrollbar_align(&self) -> Align
fn scrollbar_align(&self) -> Align
sourcefn line_start(&self, pos: i32) -> i32
fn line_start(&self, pos: i32) -> i32
sourcefn line_end(&self, start_pos: i32, is_line_start: bool) -> i32
fn line_end(&self, start_pos: i32, is_line_start: bool) -> i32
sourcefn skip_lines(&mut self, start_pos: i32, lines: i32, is_line_start: bool) -> i32
fn skip_lines(&mut self, start_pos: i32, lines: i32, is_line_start: bool) -> i32
start_pos
sourcefn rewind_lines(&mut self, start_pos: i32, lines: i32) -> i32
fn rewind_lines(&mut self, start_pos: i32, lines: i32) -> i32
sourcefn previous_word(&mut self)
fn previous_word(&mut self)
sourcefn word_start(&self, pos: i32) -> i32
fn word_start(&self, pos: i32) -> i32
sourcefn word_end(&self, pos: i32) -> i32
fn word_end(&self, pos: i32) -> i32
sourcefn set_linenumber_width(&mut self, w: i32)
fn set_linenumber_width(&mut self, w: i32)
sourcefn linenumber_width(&self) -> i32
fn linenumber_width(&self) -> i32
sourcefn set_linenumber_font(&mut self, font: Font)
fn set_linenumber_font(&mut self, font: Font)
sourcefn linenumber_font(&self) -> Font
fn linenumber_font(&self) -> Font
sourcefn set_linenumber_size(&mut self, size: i32)
fn set_linenumber_size(&mut self, size: i32)
sourcefn linenumber_size(&self) -> i32
fn linenumber_size(&self) -> i32
sourcefn set_linenumber_fgcolor(&mut self, color: Color)
fn set_linenumber_fgcolor(&mut self, color: Color)
sourcefn linenumber_fgcolor(&self) -> Color
fn linenumber_fgcolor(&self) -> Color
sourcefn set_linenumber_bgcolor(&mut self, color: Color)
fn set_linenumber_bgcolor(&mut self, color: Color)
sourcefn linenumber_bgcolor(&self) -> Color
fn linenumber_bgcolor(&self) -> Color
sourcefn set_linenumber_align(&mut self, align: Align)
fn set_linenumber_align(&mut self, align: Align)
sourcefn linenumber_align(&self) -> Align
fn linenumber_align(&self) -> Align
sourcefn in_selection(&self, x: i32, y: i32) -> bool
fn in_selection(&self, x: i32, y: i32) -> bool
sourcefn wrapped_column(&self, row: i32, column: i32) -> i32
fn wrapped_column(&self, row: i32, column: i32) -> i32
sourcefn wrapped_row(&self, row: i32) -> i32
fn wrapped_row(&self, row: i32) -> i32
sourcefn set_grammar_underline_color(&mut self, color: Color)
fn set_grammar_underline_color(&mut self, color: Color)
sourcefn grammar_underline_color(&self) -> Color
fn grammar_underline_color(&self) -> Color
sourcefn set_spelling_underline_color(&mut self, color: Color)
fn set_spelling_underline_color(&mut self, color: Color)
sourcefn spelling_underline_color(&self) -> Color
fn spelling_underline_color(&self) -> Color
sourcefn set_secondary_selection_color(&mut self, color: Color)
fn set_secondary_selection_color(&mut self, color: Color)
sourcefn secondary_selection_color(&self) -> Color
fn secondary_selection_color(&self) -> Color
sourcefn show_insert_position(&mut self)
fn show_insert_position(&mut self)
sourceimpl PartialEq<SimpleTerminal> for SimpleTerminal
impl PartialEq<SimpleTerminal> for SimpleTerminal
sourceimpl WidgetBase for SimpleTerminal
impl WidgetBase for SimpleTerminal
sourcefn new<T: Into<Option<&'static str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T
) -> SimpleTerminal
fn new<T: Into<Option<&'static str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T
) -> SimpleTerminal
sourcefn default_fill() -> Self
fn default_fill() -> Self
sourceunsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
sourceunsafe fn from_widget<W: WidgetExt>(w: W) -> Self
unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
sourcefn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
Fl_Widget::handle(int)
.
Handled or ignored events should return true, unhandled events should return false.
takes the widget as a closure argument Read moresourcefn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
WidgetBase::draw
actually calls drawing functions Read moresourcefn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F
)
fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F
)
sourceunsafe fn assume_derived(&mut self)
unsafe fn assume_derived(&mut self)
sourceimpl WidgetExt for SimpleTerminal
impl WidgetExt for SimpleTerminal
sourcefn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
sourcefn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
sourcefn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
sourcefn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
sourcefn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
sourcefn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
sourcefn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
sourcefn center_of_parent(self) -> Self
fn center_of_parent(self) -> Self
sourcefn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
sourcefn set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
@
sign.
and for the associated formatting. Read moresourcefn measure_label(&self) -> (i32, i32)
fn measure_label(&self) -> (i32, i32)
sourceunsafe fn as_widget_ptr(&self) -> *mut Fl_Widget
unsafe fn as_widget_ptr(&self) -> *mut Fl_Widget
Fl_Widget
, for internal use Read moresourcefn deactivate(&mut self)
fn deactivate(&mut self)
sourcefn redraw_label(&mut self)
fn redraw_label(&mut self)
sourcefn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
sourcefn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
sourcefn set_tooltip(&mut self, txt: &str)
fn set_tooltip(&mut self, txt: &str)
sourcefn label_color(&self) -> Color
fn label_color(&self) -> Color
sourcefn set_label_color(&mut self, color: Color)
fn set_label_color(&mut self, color: Color)
sourcefn label_font(&self) -> Font
fn label_font(&self) -> Font
sourcefn set_label_font(&mut self, font: Font)
fn set_label_font(&mut self, font: Font)
sourcefn label_size(&self) -> i32
fn label_size(&self) -> i32
sourcefn set_label_size(&mut self, sz: i32)
fn set_label_size(&mut self, sz: i32)
sourcefn label_type(&self) -> LabelType
fn label_type(&self) -> LabelType
sourcefn set_label_type(&mut self, typ: LabelType)
fn set_label_type(&mut self, typ: LabelType)
sourcefn set_changed(&mut self)
fn set_changed(&mut self)
sourcefn clear_changed(&mut self)
fn clear_changed(&mut self)
sourcefn set_trigger(&mut self, trigger: CallbackTrigger)
fn set_trigger(&mut self, trigger: CallbackTrigger)
when()
sourcefn trigger(&self) -> CallbackTrigger
fn trigger(&self) -> CallbackTrigger
when()
sourcefn selection_color(&self) -> Color
fn selection_color(&self) -> Color
sourcefn set_selection_color(&mut self, color: Color)
fn set_selection_color(&mut self, color: Color)
sourcefn do_callback(&mut self)
fn do_callback(&mut self)
sourcefn top_window(&self) -> Option<Box<dyn WindowExt>>
fn top_window(&self) -> Option<Box<dyn WindowExt>>
sourcefn takes_events(&self) -> bool
fn takes_events(&self) -> bool
sourcefn set_visible_focus(&mut self)
fn set_visible_focus(&mut self)
sourcefn clear_visible_focus(&mut self)
fn clear_visible_focus(&mut self)
sourcefn visible_focus(&mut self, v: bool)
fn visible_focus(&mut self, v: bool)
sourcefn has_visible_focus(&self) -> bool
fn has_visible_focus(&self) -> bool
sourcefn was_deleted(&self) -> bool
fn was_deleted(&self) -> bool
sourcefn set_damage(&mut self, flag: bool)
fn set_damage(&mut self, flag: bool)
sourcefn damage_type(&self) -> Damage
fn damage_type(&self) -> Damage
sourcefn set_damage_type(&mut self, mask: Damage)
fn set_damage_type(&mut self, mask: Damage)
sourcefn clear_damage(&mut self)
fn clear_damage(&mut self)
sourcefn as_window(&self) -> Option<Box<dyn WindowExt>>
fn as_window(&self) -> Option<Box<dyn WindowExt>>
sourcefn inside<W: WidgetExt>(&self, wid: &W) -> bool
fn inside<W: WidgetExt>(&self, wid: &W) -> bool
sourcefn get_type<T: WidgetType>(&self) -> T
fn get_type<T: WidgetType>(&self) -> T
sourcefn set_type<T: WidgetType>(&mut self, typ: T)
fn set_type<T: WidgetType>(&mut self, typ: T)
sourcefn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
sourcefn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
sourcefn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
sourcefn deimage(&self) -> Option<Box<dyn ImageExt>>
fn deimage(&self) -> Option<Box<dyn ImageExt>>
sourcefn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
sourcefn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
sourceunsafe fn into_widget<W: WidgetBase>(&self) -> W
unsafe fn into_widget<W: WidgetBase>(&self) -> W
WidgetExt
to a Widget Read more