Skip to main content

InputAppBuilder

Struct InputAppBuilder 

Source
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>

Source

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 - true to close on Escape, false to 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);
Source

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, or None to 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")));
Source

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).

Source

pub fn size(self, terminal_size: Size) -> Self

Sets the size of the terminal in character cells.

If not specified, the backend uses the current terminal size (or a backend-specific default).

§Parameters
  • terminal_size - Width and height of the terminal, in character cells.
§Examples
use appcui::prelude::*;

App::new().size(Size::new(80, 25));
Source

pub fn title(self, title: &str) -> Self

Sets the title shown by the terminal window or browser tab.

Support depends on the selected backend. If not specified, a backend default title is used.

§Parameters
  • title - The application title.
§Examples
use appcui::prelude::*;

App::new().title("My Application");
Source

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 - If true, new logs are appended; if false, the file is overwritten.
§Examples
use appcui::prelude::*;

App::new().log_file("appcui.log", false);
Source

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 - true to use the terminal color schema, false to disable it.
§Examples
use appcui::prelude::*;

App::new().color_schema(false);
Source

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 - true to restore the original screen, false to 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);
Source

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
§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();
Source

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 parameters x and y are a screen position, while the parameter button is one of left, right or center
  • Mouse.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 pressed
  • Mouse.Wheel(x,y,direction,times) simulates the wheel mouse being rotated into a direction (one of top, bottom, left, right) for a number of times. The times parameter 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. value is a boolean value (true or false). If set to false all subsequent calls to command Paint will be ignored.

System events

  • Resize(width,height) simulates a resize of the virtual terminal to the size represented by width and height parameters

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more