pub struct InputAppBuilder<T: InputApp + 'static> { /* private fields */ }Expand description
Builder for an input-driven AppCUI application.
Obtain this builder with App::input_app.
Configure close behavior, the clear character, and the terminal, then call
run to start the event loop.
§Examples
use appcui::prelude::*;
struct HelloWorld;
impl InputApp for HelloWorld {
fn on_paint(&self, surface: &mut Surface) {
surface.write_string(0, 0, "Hello World !", charattr!("white"), false);
}
}
fn main() -> Result<(), appcui::system::Error> {
App::input_app(HelloWorld {})
.title("Hello")
.run()
}Implementations§
Source§impl<T: InputApp + 'static> InputAppBuilder<T>
impl<T: InputApp + 'static> InputAppBuilder<T>
Sourcepub fn auto_close(self, value: bool) -> Self
pub fn auto_close(self, value: bool) -> Self
Enables or disables closing the application with the Escape key.
When enabled (the default), pressing Escape calls App::close.
When disabled, Escape is forwarded to InputApp::on_key_event.
§Parameters
value-trueto close onEscape,falseto handle it yourself.
§Examples
use appcui::prelude::*;
struct HelloWorld;
impl InputApp for HelloWorld {
fn on_paint(&self, _surface: &mut Surface) {}
}
App::input_app(HelloWorld {}).auto_close(false);Sourcepub fn clear_char(self, ch: Option<Character>) -> Self
pub fn clear_char(self, ch: Option<Character>) -> Self
Sets the character used to clear the surface before each paint.
The default is a space with a white foreground and black background.
Pass None to skip the fill and only reset clip and origin.
§Parameters
ch- The clear character, orNoneto leave the previous frame in place.
§Examples
use appcui::prelude::*;
struct HelloWorld;
impl InputApp for HelloWorld {
fn on_paint(&self, _surface: &mut Surface) {}
}
App::input_app(HelloWorld {}).clear_char(Some(char!("' ',white,black")));Sourcepub fn run(self) -> Result<(), Error>
pub fn run(self) -> Result<(), Error>
Builds the application from the current settings and starts the event loop.
This method consumes the builder, creates the runtime, and blocks until
the application closes. InputApp::on_paint is called whenever the
runtime requests a redraw.
§Errors
Returns crate::system::Error if the application cannot be initialized
(for example, if another application is already running).
Sourcepub fn log_file(self, name: &str, append: bool) -> Self
pub fn log_file(self, name: &str, append: bool) -> Self
Sets the log file used when the crate is compiled in debug mode.
This option has no effect in release builds.
§Parameters
name- Path of the log file.append- Iftrue, new logs are appended; iffalse, the file is overwritten.
§Examples
use appcui::prelude::*;
App::new().log_file("appcui.log", false);Sourcepub fn color_schema(self, enabled: bool) -> Self
pub fn color_schema(self, enabled: bool) -> Self
Enables or disables the terminal color schema.
When enabled (the default), the backend may map AppCUI colors through the terminal’s color schema. Disable this to keep the exact colors defined by the theme.
§Parameters
enabled-trueto use the terminal color schema,falseto disable it.
§Examples
use appcui::prelude::*;
App::new().color_schema(false);Sourcepub fn restore_screen(self, enable: bool) -> Self
pub fn restore_screen(self, enable: bool) -> Self
Controls whether the original screen is restored when the application ends.
When enabled (the default), the backend attempts to restore the original screen content and cursor position. When disabled, the screen is cleared on exit.
§Parameters
enable-trueto restore the original screen,falseto clear it.
§Remarks
Not all backends can restore the original screen. Backends without this support always clear the screen when the application ends.
§Examples
use appcui::prelude::*;
App::new().restore_screen(false);Sourcepub fn backend(self, backend: Type) -> Self
pub fn backend(self, backend: Type) -> Self
Selects the terminal backend used to render the application.
If not specified, AppCUI picks a backend appropriate for the current platform and enabled crate features.
§Parameters
backend- Thecrate::backend::Typeto use.
§Examples
use appcui::prelude::*;
#[cfg(target_os = "windows")]
let _builder = App::new().backend(appcui::backend::Type::WindowsVT);
#[cfg(not(target_os = "windows"))]
let _builder = App::new();Sourcepub fn debug_script(self, script: &str) -> Self
pub fn debug_script(self, script: &str) -> Self
Configures a debug script that simulates input for unit tests.
Each line of script is a command executed in order against a virtual
terminal. After the last command the application ends.
Combine this method with size to set the simulated
terminal dimensions (width and height).
§Parameters
script- Commands to execute, one per line.
§Debug commands
Mouse related commands
Mouse.Hold(x,y,button)simulates an event where the mouse button is being pressed while the mouse is located at a specific position on screen. The parametersxandyare a screen position, while the parameterbuttonis one ofleft,rightorcenterMouse.Release(x,y)simulates the release of all mouse buttons while the mouse is located at a specific screen position.Mouse.Click(x,y,button)simulates a click (hold an release)Mouse.Move(x,y)simulates the movement of a mouse to coordonates (x,y). No mouse button are being pressed.Mouse.Drag(x1,y1,x2,y2)simulates the movement of a mouse from (x1,y1) to (x2,y2) while the left button is being pressedMouse.Wheel(x,y,direction,times)simulates the wheel mouse being rotated into a direction (one oftop,bottom,left,right) for a number of times. Thetimesparameter must be biggen than 0.
Key related commands
Key.Pressed(key)where key can be any combination of keys
Paint related commands
Paint(name)paints the current virtual screen into the current screen using ANSI codes.Paint.Enable(value)enables or disables painting.valueis a boolean value (true or false). If set to false all subsequent calls to commandPaintwill be ignored.
System events
Resize(width,height)simulates a resize of the virtual terminal to the size represented bywidthandheightparameters
Validation commands
CheckHash(hash)checks if the hash computer over the current virtual screen is as expected. If not it will panic. This is useful for unit testing.
§Examples
use appcui::prelude::*;
let script = "
Paint(initial)
Key.Pressed(Escape)
";
App::new()
.size(Size::new(60, 10))
.debug_script(script)
.window(|| window!("'Test',a:c,w:20,h:6"));Auto Trait Implementations§
impl<T> !RefUnwindSafe for InputAppBuilder<T>
impl<T> !Send for InputAppBuilder<T>
impl<T> !Sync for InputAppBuilder<T>
impl<T> !UnwindSafe for InputAppBuilder<T>
impl<T> Freeze for InputAppBuilder<T>where
T: Freeze,
impl<T> Unpin for InputAppBuilder<T>where
T: Unpin,
impl<T> UnsafeUnpin for InputAppBuilder<T>where
T: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.