Run the maintained counter.
The repository includes a complete application in examples/src/counter.adb. The site build compiles this source before it generates the documentation captures.
git clone git@github.com:flyology-ada/flyology-tui.git
cd flyology-tui/examples
alr run counterThe following sections explain extracts from that complete program.
Add the crate.
Flyology TUI requires Alire 2.1 or newer and GNAT 13 through 16. Add the crate to an Ada application.
alr with flyology_tuiThe public contract is platform-neutral. The POSIX backend currently supports macOS and Linux.
Define typed state and messages.
Instantiate Flyology_TUI.Application_Events with the application message type. Instantiate Flyology_TUI.Transitions with the command type.
type Message is (Loaded);
type Command is (Load);
type Model is limited record
Count : Integer := 0;
Width : Natural := 80;
Height : Natural := 24;
end record;
package Events is new Flyology_TUI.Application_Events (Message);
package Transitions is new Flyology_TUI.Transitions (Command);The application has one model owner and processes events serially. A detached command value contains no reference to the live model or component state. The runner queues that value for the command worker, which can return a typed application message.
Handle one event at a time.
Update the model for terminal input or application messages. When a resize event arrives, update the dimensions before the next presentation.
procedure Update
(Item : in out Model;
Event : Events.Event;
Next : in out Transitions.Transition) is
begin
case Event.Kind is
when Events.Application_Message => null;
when Events.Terminal_Input =>
case Event.Terminal.Kind is
when Flyology_TUI.Events.Resize =>
Item.Width := Event.Terminal.Width;
Item.Height := Event.Terminal.Height;
when Flyology_TUI.Events.Interrupt =>
Transitions.Quit (Next);
when others => null;
end case;
end case;
end Update;Return the complete desired view.
Create styled cells with Flyology_TUI.Surfaces. Compose them with Flyology_TUI.Layouts. Return terminal policy and the root surface through Flyology_TUI.Views.
Presentation does not write terminal bytes. The renderer compares the view with the previous frame and emits changed cells.
Instantiate the runner and start the application loop.
Flyology_TUI.Runners supplies bounded input and command orchestration. Flyology_TUI.Backends.POSIX owns terminal mode and reports resize events.
package Runtime is new Flyology_TUI.Runners
(Events => Events,
Transitions => Transitions,
Model_Type => Model,
Initialize => Initialize,
Update => Update,
Present => Present,
Execute => Execute);
State : Model;
Terminal : Flyology_TUI.Backends.POSIX.POSIX_Backend;
Runtime.Run (State, Terminal);Add layout, input, and skins.
- Application loop explains commands and ownership.
- Layout and input explains snapshots and mouse capture.
- Themes and skins explains render-time appearance.
- Testing explains the headless backend.
- Components documents every public component package.