Getting started

Build the first interface.

Create a typed application loop, return a complete view, and run it against the POSIX terminal backend. Then add responsive layout and bounded components.

Working baseline

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.

Terminal
git clone git@github.com:flyology-ada/flyology-tui.git
cd flyology-tui/examples
alr run counter

The following sections explain extracts from that complete program.

Step 01

Add the crate.

Flyology TUI requires Alire 2.1 or newer and GNAT 13 through 16. Add the crate to an Ada application.

Terminal
alr with flyology_tui

The public contract is platform-neutral. The POSIX backend currently supports macOS and Linux.

Step 02

Define typed state and messages.

Instantiate Flyology_TUI.Application_Events with the application message type. Instantiate Flyology_TUI.Transitions with the command type.

Application types
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.

Step 03

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.

Update procedure
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;
Step 04

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.

Step 05

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.

Runner instance
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);
Next

Add layout, input, and skins.