ANSI.SYS is missing in windows 8.1; so how do I create cursor control in a console display?
I am currently using C; if it cannot be done in C, can it be done in C++? Config.sys is supposed to have DEVICE=ANSI.SYS.
You want to mix the ancient ancient ancient MS-DOS technologies with the modern Windows NT console. ANSI.SYS is missing because it's looong dead.
What you want to do instead is take advantage of the NT console. Here's a starting point in the API documentation. In particular, there's a guide on handling mouse input that you can use as a starting point.
You may find it easier to use a library like Termbox or pdcurses, depending on the type of program you want to write. There are even some text-based user interface (TUI) libraries, such as Turbo Vision, if you want to write that kind of program instead.
Related
I have made a decent console application in C. The issue is that arrow keys print an escape sequence to the input instead of moving the cursor or navigating previous input. On Windows it works well (same behavior of command prompt).
How can I pull the same thing on Linux?
The C++ programming language is made to be a very efficient language. As such, the language itself (i.e. without including any libraries) can't really do that much, basically you can only get input through argc and argv and you can only send output through the return value.
The standard library helps a lot, giving us access things such as files, allowing us to do a lot more. As console developers it also allows us to use the standard input and the standard output through std::cin and std::cout (also the standard error stream through std::cerr but we usually hope nothing will be written to it). Since we get access to those tools through streams, to our program there's no such thing as "The second line from the top of the console", it's only a long line of letters. As such it's absolutely impossible to do this using only C++ and the standard library.
What about windows then? It can do it! Yes, but that's a windows thing, not a C++ thing (it's being a while since I used windows but I remember it sometimes causing issues with streams), third-parties windows-compatible console emulators can function exactly like Linux terminals (and I guess Linux terminals could work just like windows, I just haven't seen one yet) so we need something to guaranty us this behavior.
Thankfully, one of the main advantage of C/C++ is the sheer number of libraries available to us. An big part of C++ programs don't even use a console anymore, bypassing completely the issue.
What I'd recommend is to find a good library (I sometimes use ncurses although I think it's Linux-only and probably a bit too feature full for your usecase) and use it to control the cursor to make it do what you want
I'm trying to write a small programme that needs to load a few files chosen by the user. I thought it'd be easier to use the Linux system's default file picker rather than write my own, but I literally don't have a clue where to even start looking.
So, can anyone recommend a quick and easy way to use the system's file picker on Linux in C?
As I commented, many Linux systems (e.g. a rented VPS, a consumer router box, ...) don't have any graphical user interfaces (often above X11).
If you want a GUI toolkit in C for Linux, consider using GTK. Then look at GtkFileChooserWidget & GtkFileChooser
If you want a GUI toolkit in C++ for Linux, consider using Qt.
If you want a terminal interface, learn ncurses.
If you want a web interface, use some HTTP server library like libonion or Wt, or make a FastCGI program for your existing web server.
Perhaps coding a simple shell script might be easier. Read Advanced Bash Scripting Guide. You could also use a scripting language like Python, Ruby, Ocaml, ...
If you don't know about Linux programming, read Advanced Linux Programming first. See also intro(2) & intro(3)
... a small program that needs to load a few files chosen by the user.
Just pass them as command-line arguments. It's much easier and doesn't tie you to a given GUI toolkit.
You can easily write a shell wrapper using kdialog on KDE, or dialog if you want curses in a terminal, or ... whatever other tool for whatever other environment.
I've programmed in Windows with Win32 Console API, and there are some functions that can control console:
SetConsoleWindowInfo: Sets the current size and position of a console screen buffer's window.
SetConsoleScreenBufferSize: Changes the size of the specified console screen buffer.
SetConsoleCursorPosition: Sets the cursor position in the specified console screen buffer.
SetPixel: The SetPixel function sets the pixel at the specified coordinates to the specified color.
Is there any equivalent function in Ubuntu ( without using ncurses )? APIs?
BTW, where is the developers documentation website of Ubuntu like MSDN?
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)
I'd like to write an application (in C) that uses the terminal of a *nix OS as its GUI. I mean an application of the kinds of emacs, vi etc. that take up the whole terminal window and jump back to the input prompt after quitting.
How would you go about doing that, preferably in C? Can someone point me to a tutorial covering that?
You need to use ncurses:
http://en.wikipedia.org/wiki/Ncurses
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
It is available on all major distros.
Well, actually this is not GUI (graphic user interface) but a text based interface. You can use the library ncurses to create such applications in C.
Use a library like ncurses, it is specifically designed for this purpose.
Throwing in alternate solutions so that this question thread does not look so monotonic:
the slang library (mc uses it, for example)
I would like to know how to create console applications with better control of input and output using C. For example, how does the text-editor nano display the file contents in a certain portion of the screen and then keep a list of commands stationary on the bottom. I know you can use the win32 api to do this in Windows, but what is the Unix/Linux equivalent?
More than likely there's a ncurses interface that controls the screen drawing and placement of items on the screen in a certain position. The api is standard across the linux systems and on unix also, some may be implementation defined depending on the variant of curses used under the commercial variants of unix but otherwise some standard ncurses functionality are compatible.
Besides ncurses and depending on the task at hands you may find newt, a library for color text mode, widget-based user interfaces, a suitable alternative also. Sometimes visual results are better with newt.
If you just want to do the low level stuff, you probably want to use the termcap or terminfo library.
If you want to do it the way nano and just about every other interactive terminal app does it, you probably want to use ncurses. That way you will spend less time implementing terminal control logic, and more time on the actual app you are developing.