2

I'm creating a console app with Node.js which is going to have a TUI (Text User Interface). But I want to run it in a full screen mode inside the terminal (I don't know if it's the correct way to say it) instead of just printing stuff in the same layout that we run the app. Like how Vim, htop or similar applications work, and it seems like they are run in a different layout.

Actually, I'm more interested to know how it happens. I mean, does terminal have different mode for running an app? Or it's programmer's job to save everything that is on the screen, then use the whole terminal, and when he's done, write back everything that were there before?

It's also fine if you just recommend me a library that does this (I can check its code to understand how it works)

romainl
  • 186,200
  • 21
  • 280
  • 313
Bawbak
  • 87
  • 5

2 Answers2

2

This CLI console app appears to be a node.js console app with a full screen interface UI.

Open source FTW for you :grin:

Just looking down the libraries/npm modules it's using:

From those three libraries, I'm sure you'll be able to do exactly what you describe. There are others listed on the inital sitepoint app's page - like chalk to colourise output - sure, you could do this with raw ansi codes, but if theres a library for it, why not use it (assuming theres no hefy overheads)?

To answer your inital question about what to call it - I'm with you, full screen interface is how I'd refer to it - TUI got your point across, especially when you cited vim (I use nano) as an example. Perhaps adding CLI/UI/terminal, to be less ambiguous. Full screen terminal interface UI app.

EDIT I hope you get an audience for your finished product - I say this with my face in my hands, having just having read this numpty wondering why on earth anyone would still use vim or nano in the modern age. I cry. I do hope he was being sincere with a touch of naivety - the cynic in me doubts this. Is this a gen-Z thing?

vim is super useful for just changing configs or quickly editing a small script or whatever, but there are people who will write entire software applications in Nano or Vim, and they are also serial killers (probably)

(this quote was not from the hopefully naive OP, but freaked me out enough to want to quote it)

Noscere
  • 417
  • 3
  • 8
  • Thanks for the answer. I'm pretty sure you got what I mean, but I've checked the links, and it seems like they all put the output in the same layout. But apps like Vim or htop kind of create a new layer for their UI and when you exit the app, you will be back to the previous layer that you ran the app. And everything looks clean as it was before. – Bawbak Dec 11 '22 at 22:17
  • Unlike a GUI environs (OS or framework deals with screen drawing), blit-ing the gfx elements at screen refresh, terminal interface apps have to do it themselves. With UI text in memory, say 80x24, they will clear screen then write again each update. Luckily there are libs for txt UIs - but it's piecemeal. Not one lib does all you need. My referenced one uses several NPMs; a lib clearing the console, another for text-based UI menu - yet another creates text-based widgets - all subsequently rendered by code you'll prob. write yourself - clear screen, blit, wait for input, then clear & redraw. – Noscere Dec 11 '22 at 22:42
0

Take a look at https://github.com/vadimdemedes/ink

Ink provides the same component-based UI building experience that React offers in the browser, but for command-line apps

Sergei Voronezhskii
  • 2,184
  • 19
  • 32