How to control frame size, buffer size, cursor position, and GDI function of the gnome terminal in C with API?

StackOverflow https://stackoverflow.com/questions/21407332

  •  03-10-2022
  •  | 
  •  

Question

I've programmed in Windows with Win32 Console API, and there are some functions that can control console:

Is there any equivalent function in Ubuntu ( without using ncurses )? APIs?

BTW, where is the developers documentation website of Ubuntu like MSDN?

Was it helpful?

Solution

There are a few things you'll want to note:

Without Ncurses you don't really have to many options (Well you do - excape codes, but that's what NCurses does). It's worth understanding why you can't find this functionality though: Gnome-Terminal is a terminal emulator, not a 'console' like cmd.exe is. There is no API for controlling the terminal because it's simply emulating a proper serial terminal and reading in characters from your programs stdout, and sending characters to stdin (In other words, your running program has no idea what type of terminal it's running on, or even if it's outputting or getting input from a terminal. It could be Gnome-terminal, could also be xfce4-terminal, rxvt, xterm, a file, etc... This is true in Windows but not as much, since cmd.exe is basically the only terminal program and you control the terminal through more direct means.). So the simple answer is you can't, control terminal related things like buffer size. You can control the cursor position and set characters on specefic spots on the screen, but you have to do that through excape codes and they get ugly (Ncurses is a great library in that it abstracts all of that from you). Is there a reason you don't want to use Ncurses? I would rethink what you're doing if you don't want to use it. If you're looking for cross-platform, pdcurses is a curses implementation for Windows you could use.

Also worth noting, you keep refering to Ubuntu and asking for their documentation -- You should keep in mind that Gnome and Gnome-Terminal are separate projects from Ubuntu (Which is more or less just a collection of different programs, with some in-house programs like Unity). Looking for Gnome-Terminal information on Ubuntu's website is like looking for Gnome-Terminal information on Microsoft's website, you just won't find it because it's a separate project, it just happens to be installed by default on Ubuntu. If you look on Gnome's website you may find better information. But, they still don't have an API for controlling terminal specefic stuff like the buffer as they support Ncurses, and you're better off not tying yourself to a specefic terminal or OS. Keep in mind that not all Ubuntu users use Gnome-Terminal, and not all Gnome-Terminal users are running Ubuntu. AFAIK They don't have any type of developer site like MSDN, but they also don't really have much they could put on there. If you're developing for Ubuntu, you're probably then targeting other technologies like GTK, Qt, OpenGL, etc... Which do have documentation (And are more platform agnostic then just being 'Ubuntu-specefic' - Chances are if you write a program for Ubuntu, it'll run on most Linux desktop platforms and not just Ubuntu)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top