# Ui-terminal-mojo

**URL:** <https://forum.modular.com/t/ui-terminal-mojo/1371>\
**Category:** Community Showcase\
**Created:** [May 5, 2025, 7:49pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371 "2025-05-05T19:49:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rd4com](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@rd4com](https://forum.modular.com/u/rd4com)\
**Post date:** [May 5, 2025, 7:49pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/1 "2025-05-05T19:49:58Z")

</div>

Repo: [GitHub - rd4com/ui-terminal-mojo: terminal ui mojo programming language](https://github.com/rd4com/ui-terminal-mojo)  
Demo: [ui-terminal-mojo/learn/learn\_6\_scalable\_layouts.mojo at main · rd4com/ui-terminal-mojo · GitHub](https://github.com/rd4com/ui-terminal-mojo/blob/main/learn/learn_6_scalable_layouts.mojo)

Hello 👋

I worked on this terminal ui for a while,  
based on `LinearType` for layout measurements,  
and `SIMD` for events handlings, and more.

Because this was first steps into ui from scratch,  
the philosophy had to become learn by building.  
So far, it worked and features came out.

At first, `SIMD` came to the rescue for events,  
because the terminal sends many numbers for key combos.  
this was a small nightmare, and `SIMD` was there to solve that.  
Then, adding `shift_left[1]()` turned the vector into a queue.

Now for user to create a layout, thing became really difficult,  
the datastructure was a nested tree at first,  
this introduced complexity, Variant, and recursion.

But there was no way to create an API that makes it possible to:

- nested areas that scale the outer ones vertically and horizontally,
- events on the fly with no callbacks
- in the 60FPS loop
- in an user-friendly way

So the `LinearType` solution emerged, for measuring 📐!  
If we can only move the cursor below or after an measured area,  
no squares/rectangles should overlap with the previous one.  
(only building “on top of” previous things)

So it became possible to simplify the datastructure into a flat list.  
Now each position is calculated and known at creation time,  
and events can be handled in the loop with no callbacks.

───  
API  
───

The ui already has a small foundational API,  
making it possible for a person to create all it’s already available widgets,  
with only a few tools **that don’t really need to change**!  
(but let’s give time to the design to evolve a little more)

`ui.start_measuring()`  
`..let any widgets do nested things..`  
`some_measurement.peek_dimension()`  
`some_measurement^.stop_measuring()`

`ui.move_cursor_after(some_completed_measurement^)`  
`ui.move_cursor_below(some_completed_measurement^)`

`Text("Hello world") | Fg.green in ui`

`ui[-2].click()`  
`ui[-1].hover()`  
`ui[-1] |= Bg.magenta`

`start_border` and `end_border`  
(to use with measurement api, as borders are measured too!)

To keep it user-friendly,  
things can be appended vertically by default with no measuring.  
(below previous item)

───

I really hope you’ll all like it,  
please share any feedback: positive and not positive 😃

![out4](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/4873823f5e0c06b6078e357dededce057999c21e.gif)  
 ![out2](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/303ecb0b1c414fc11bbdb7922bb2ba9193b144f6.gif)  
 ![out3](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/aedc30aa5d01602411dca8a29e51808947cef782.gif)

Please check the repo,  
there are many examples,  
and an step by step progressive walk-trough 👍

---

<div class="post-metadata">

**Author:** ![clattner](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/clattner/32/201_2.png) [@clattner](https://forum.modular.com/u/clattner)\
**Post date:** [May 5, 2025, 8:11pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/2 "2025-05-05T20:11:34Z")

</div>

This is pretty cool!

---

<div class="post-metadata">

**Author:** ![rd4com](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@rd4com](https://forum.modular.com/u/rd4com)\
**Post date:** [May 5, 2025, 8:42pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/3 "2025-05-05T20:42:31Z")

</div>

Thanks !

---

<div class="post-metadata">

**Author:** ![rd4com](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@rd4com](https://forum.modular.com/u/rd4com)\
**Post date:** [May 8, 2025, 9:58pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/4 "2025-05-08T21:58:36Z")

</div>

🆙🩹 Fix version ! (pin to `25.4.0.dev2025050705`)  
(the `mojoproject.toml` was not pinned to the same version as locally)

The ui could not work for people that cloned the repo i think.  
Sorry for the inconvenience, (learning by building), it should work now 🟢!  
On the way, updated it for latest nightly 👍

---

<div class="post-metadata">

**Author:** ![rd4com](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@rd4com](https://forum.modular.com/u/rd4com)\
**Post date:** [July 2, 2025, 9:50pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/5 "2025-07-02T21:50:01Z")

</div>

Hello everybody 👋,  
i’ve created an simple explorer (100loc) with the ui,  
It will be in example folder on next git push!  
Here is the demo:  
 ![output](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/d5b77554820007f619f60e0cd75595372f13fe6a.gif)

---

<div class="post-metadata">

**Author:** ![rd4com](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@rd4com](https://forum.modular.com/u/rd4com)\
**Post date:** [July 5, 2025, 8:28pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/6 "2025-07-05T20:28:10Z")

</div>

Quick update:  
Managed to squeeze all the linear type things (measuring, border, move cursor)  
into one context manager with this commit:

> <https://github.com/rd4com/ui-terminal-mojo/commit/135f527253598adac588d1d8c9bb5e743ff6c1ba>
>
> It is an struct that currently does 3 things:
> \- start and stop measuring
> \- move …cursor below or after
> \- integrate optional border with style and colors
> 
> See example:
> \`📂 wip\_api\_playground/context\_managers.mojo\`

(Check out the example, it is all now simpler)

And working on an live system app to showcase some features,  
it also helps to learn what features to add!

 ![screenshot](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/a75ca886b1918ce879a8ff89bbd280a2816ecdc5.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [January 1, 2026, 8:29pm UTC](https://forum.modular.com/t/ui-terminal-mojo/1371/7 "2026-01-01T20:29:00Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
