2

Simply like vim, nano, and some other command line text editors. When entering the application, it turns into another text-based screen, and the application can modify every single characters as UI independently without any command line screen scrolling (when simply outputing characters to fill the screen in my own program, the terminal would do auto scrolling), and can even handle mouse events within the console screen.

  1 
~                                          
~                                          
~                                          
~                                          
~                                          
~                                          
~                                          
-- VISUAL --             0,0-1         All

And then exiting the application, the screen restores and looks like that the the application never outputs (the application screen is not likely to overwrite the external output at all):

~$ vim

~$ 

As for Windows, there used to be a "EDIT" command that worked similarly.

How can I make a similar one to implement a text-based UI? Which sort of API should I call?

Does it depend on the OS or the terminal type?

I wish it could work on both Linux (as well as via SSH) and Windows command line. Is there any solution that works on both or I have to implement them separately?

I need to develop it in C# (.NET Core) so managed code solutions are preferred, but native (C language) solutions are OK.

Alsein
  • 4,268
  • 1
  • 15
  • 35
  • Mostly this is asking about xterm's *alternate screen* (which would make it a [duplicate](https://stackoverflow.com/questions/51070011/how-to-write-to-the-alternate-screen-buffer-on-windows-using-only-the-standard-l)), but aside from that, the question is overly broad. – Thomas Dickey Aug 19 '18 at 22:11

1 Answers1

5

There are a variety of ways this could theoretically be done, but the most obvious solution that comes to mind is ncurses. It is widely used in console-based applications, including Vim.

It is a C library, with a good tutorial at http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

When I was a very novice C programmer, ncurses was the first library I played around with, so I can say that in my experience it is fairly easy to use, provided you already know a small amount of C.

Although you say you might be content with a pure C library, a search demonstrates that C# wrappers exist for it, eg https://github.com/sushihangover/CursesSharp

Edit: I have answered from a Linux perspective; I now realise you also want a Windows answer. I haven't tried ncurses in Windows, but the ncurses website linked above claims that it has been ported to MinGW and it has been made to work in Windows 7.

cryptarch
  • 170
  • 4
  • 1
    For Windows you'd need to call [`CreateConsoleScreenBuffer`](https://learn.microsoft.com/en-us/windows/console/createconsolescreenbuffer). But a curses library will handle this for you. – Eryk Sun Aug 20 '18 at 00:59