# \[WIP\] Building text user interfaces in Julia using NCURSES

**URL:** <https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139>\
**Category:** Community\
**Created:** [January 27, 2019, 12:49am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139 "2019-01-27T00:49:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [January 27, 2019, 12:49am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/1 "2019-01-27T00:49:24Z")

</div>

Hi guys!

After my last post [here](https://discourse.julialang.org/t/is-there-a-package-to-construct-tui-in-julia/19801/3), I decided to start building a wrapper to `libncurses` since all that are available seem dead. Given the amazing meta programming capabilities, I managed to have a good set of functions wrapped very quickly.

Today, I tried to create a simple project to proof the concept: whether or not a TUI built in Julia is useful. I came up with the idea of using `Base.@locals` to create a variable viewer for the sake of debugging.

The following code propagates the orbit of a satellite and converts a vector from an ECI to ECEF frame. At each iteration, I call the macro `@showvars` that opens a TUI created with the wrapped Ncurses functions to show all the local variables. When I press `F1` the viewer closes, then I can see all the variables in the next loop iteration:

```julia
using SatelliteToolbox
using ReferenceFrameRotations
import Base.show

include("varviewer.jl")

show(io::IO, ::MIME"text/plain", tle::TLE) = SatelliteToolbox.print_tle(io, tle, false)

function orbit_simulation()
    tle = tle"""
       SCD 1
       1 22490U 93009B 18359.76217587 .00000186 00000-0 84512-6 0 9998
       2 22490 24.9694 116.1709 0043211 90.3968 62.0083 14.44539396366163
       """[1]

    orbp = init_orbit_propagator(Val{:sgp4}, tle)

    for t = 1:1:100*60
        o, r_teme, v_teme = propagate!(orbp, t)
        D_PEF_TEME = rECItoECEF(TEME(), PEF(), o.t)
        r_pef = D_PEF_TEME*r_teme
        lat, lon, h = ECEFtoGeodetic(r_teme)

        @showvars
    end

    nothing
end

```

Here is a gif of what I see.

 ![varviewers](https://global.discourse-cdn.com/julialang/original/3X/b/a/ba3bf63ec523a0039a53fe4cb1e4f8755b7be9d0.gif)

To be honest, I found this very useful and it was built very quickly. I think I will continue with this project. The idea of this post is to gather ideas and ask if anyone wants to help.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 27, 2019, 4:41am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/2 "2019-01-27T04:41:06Z")

</div>

See my request here for a javascript alternative to ncurses (but ncurses is fine too!). I need some ability to make terminal based dashboards for our lab.

I’ll be happy to work on it with you.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [January 27, 2019, 6:10am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/3 "2019-01-27T06:10:47Z")

</div>

So you are using it for debugging? Perhaps it can be combined with some of the other debugging programs out there

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 27, 2019, 6:39am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/4 "2019-01-27T06:39:12Z")

</div>

I love ncurses even though I have NEVER used it before

But to be able to print out text messages in COLOR would be wonderful!!! Which i believe ncurses can handle.

---

<div class="post-metadata">

**Author:** ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Post date:** [January 27, 2019, 9:48am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/5 "2019-01-27T09:48:11Z")

</div>

I’d love to port to Julia code written in other languages using ncurses.  
Could you put your ncurses bindings in a separate package (with minimal documentation: an example should be enough) I am willing to help by filling out the documentation.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [January 27, 2019, 11:28am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/6 "2019-01-27T11:28:55Z")

</div>

> [@affans](#):
>
> See my request here for a javascript alternative to ncurses (but ncurses is fine too!). I need some ability to make terminal based dashboards for our lab.
> 
> I’ll be happy to work on it with you.

Thanks! I will organize que code and add it to Github hopefully in this week.

> [@chakravala](#):
>
> So you are using it for debugging?

In fact, I want to create a package to built text user interfaces. This was just my very first thought.

> [@StevenSiew](#):
>
> But to be able to print out text messages in COLOR would be wonderful!!! Which i believe ncurses can handle.

Yes it can. But we really need some kind of translation. Julia color messages uses ANSI escape sequences that are not handled by ncurses. If we manage to create a parser between escape sequences and ncurses color code, then we could mimic Julia colored output easier.

> [@Jean\_Michel](#):
>
> Could you put your ncurses bindings in a separate package (with minimal documentation: an example should be enough) I am willing to help by filling out the documentation.

My plan is to create a package with the bindings, so that the user can access all the low level ncurses functions, and also provide a more Julian API to build text user interfaces.

The first part is very advance. I will organize the code and publish on github hopefully this week. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 28, 2019, 12:49am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/7 "2019-01-28T00:49:42Z")

</div>

@jpsamaroo tagging you for this.

@Ronis_BR is there a GitHub repository for this

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [January 28, 2019, 12:50am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/8 "2019-01-28T00:50:45Z")

</div>

> [@affans](#):
>
> @Ronis_BR is there a GitHub repository for this

Not yet! I will organize the code and will submit to one hopefully this week.

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [January 28, 2019, 1:28pm UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/9 "2019-01-28T13:28:04Z")

</div>

> [@Ronis\_BR](#):
>
> If we manage to create a parser between escape sequences and ncurses color code, then we could mimic Julia colored output easier

Checkout Keno’s VT100.jl, that’s what I’ve used for any parsing of control characters. `VT100.ScreenEmulator` has a `parseall!` function which accepts an IO to feed it ANSI terminal stuff (text or control characters), and then stores the representation within an internal `Matrix`-like representation of character `Cell`s which hold the character’s information (colors, attrs, etc.).

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [January 28, 2019, 3:23pm UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/10 "2019-01-28T15:23:45Z")

</div>

Perfect! Thanks for the tip.

---

<div class="post-metadata">

**Author:** ![dm3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dm3/32/2755_2.png) [@dm3](https://discourse.julialang.org/u/dm3)\
**Post date:** [February 26, 2019, 9:22am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/11 "2019-02-26T09:22:31Z")

</div>

@Ronis_BR - did you have a chance to publish the code? I’d love to take it for a spin 🙂

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 26, 2019, 11:02am UTC](https://discourse.julialang.org/t/wip-building-text-user-interfaces-in-julia-using-ncurses/20139/12 "2019-02-26T11:02:28Z")

</div>

Yes! It is not registered yet because there is many work to do:

> **[GitHub - ronisbr/TextUserInterfaces.jl: Text user interfaces for Julia](https://github.com/ronisbr/TextUserInterfaces.jl)**
>
> Text user interfaces for Julia. Contribute to ronisbr/TextUserInterfaces.jl development by creating an account on GitHub.

It has some examples. I still working on creating a Julian interface to ncurses, but the low level functions are working fine.
