egui_console/
lib.rs

1/// A console window for egui / eframe applications
2///
3/// [Egui / eframe ]: <https://github.com/emilk/egui>
4///
5/// # Example
6///
7/// You need a [`ConsoleWindow`] instance in your egui App
8/// ```ignore
9///pub struct ConsoleDemo {
10///     ...
11///    console: ConsoleWindow,
12///}
13/// ```
14/// Then in the construction phase use [`ConsoleBuilder`] to create a new ConsoleWindow
15/// ```ignore
16/// impl Default for ConsoleDemo {
17///    fn default() -> Self {
18///       Self {
19///          ...
20///         console: ConsoleBuilder::new().prompt(">> ").history_size(20).build()
21///      }
22///    }
23/// }
24/// ```
25///
26/// Now in the egui update callback you must [`ConsoleWindow::draw`] the console in a host container, typically an egui Window
27///
28/// ```ignore
29///  let mut console_response: ConsoleEvent = ConsoleEvent::None;
30///  egui::Window::new("Console Window")
31///      .default_height(500.0)
32///      .resizable(true)
33///      .show(ctx, |ui| {
34///        console_response = self.console.draw(ui);
35///  });
36///```
37///
38/// The draw method returns a [`ConsoleEvent`] that you can use to respond to user input. If the user entered a command then you can hndle that command as you like.
39/// The code here simply echos the command back to the user and reissues the prompt.
40///
41///```ignore
42/// if let ConsoleEvent::Command(command) = console_response {
43///    self.console.print(format!("You entered: {}", command));
44///    self.console.prompt();
45/// }
46///
47///```
48///
49///
50///#  Command history
51///
52/// - ctrl-r searches the command history
53/// - up and down arrow walk though the command history
54///
55/// If you want the command history to be automatically persisted you need to enable the persistence feature. This will use the eframe storage to save the command history between sessions.
56///
57/// Alternatively you can use [`ConsoleWindow::load_history`] and [`ConsoleWindow::get_history`] to manually save and load the command history.    
58#[warn(missing_docs)]
59pub mod console;
60mod tab;
61pub use crate::console::ConsoleBuilder;
62pub use crate::console::ConsoleEvent;
63pub use crate::console::ConsoleWindow;