Is there anyway to check the terminal (Linux, and Windows) for characters at certain positions? I have external methods loaded via an explicitly loaded dll that prints certain characters onto the screen. I need to see if the functions printed what they were supposed to with minimal cross talk between the between the plugins. So at the core I am wondering if C++ has any feature for pulling chars off of the termial/command line?
This is not possible on VT100-like terminals (the kind popular in Linux.)
For Windows I can't say, but if you are using a cygwin terminal (not the power shell or the "DOS shell") the answer is again no.
You could use tmux or screen to set up a virtual terminal. The display state can then be captured, which seems to be what you want. But something in my brain is telling me that, whatever you are trying to do, this is probably not the right solution. What exactly is your problem?
Related
I want to be able to control the program with direct input without pauseing the program and without waiting for the user to press enter.
I can currently achieve this with kbhit, but it appears that is a windows only solution.
Ncurses also looks promising, but it appears to only work for linux (and maybe mac? Is unix the structure mac is based on?).
I especially like the kbhit for it's simplicity, and I like the tool set that ncurses, but I was wondering if there was a simple, easy way to get something running cross-platform without having to maintain essentially 2-3 versions of the code using these different tools?
I figured out my problem. I'm trying to do many things that cpp was never intended to do by default, so the options are to use libraries like allegro, or, in my case it turns out what I needed was a game engine. I found that Unity with text mesh pro can do everything I need it to. It comes with an entire input management system.
actually i'm thinking of creating a cool interface for my programming assignment , so i go around searching on how to do it so that such an effect can be create , below is the image .
The Question
1.)What is needed in order to create a program that run pseudographic(semigraphic or whatever they called it) that has menu like BIOS wizard did??I always see some program run in console but it could have graphical-like looking , for example blue environment , and user can use keyboard to choose a list of setting in a menu.
Thanks for spending time reading my question.
It's called Text-based user interface. There're several libraries for doing this. I think this is what you're looking for. :)
Cross platform, Interactive text-based interface with command completion
http://www.gnu.org/s/ncurses/
Ncurses(or maybe pdcurses) is probably what you need.
In the days of 16-bit Windows console windows used to support ANSI escape sequences (via the ansi.sys driver), but they no longer do.
For the apparent line graphics you need to use a platform specific solution anyway, so I recommend just writing an abstraction (functions, class) over the Windows APIs console functions.
The line graphics is done by using characters from the original IBM PC character set, codepage 437. At first you can just hardcode the various patterns. In order to make it seem more like line drawing to the code, or from the code's perspective, so to speak, you'll have to abstract things again. As I remember there is some partial but not complete system in the original codepage 437 character codes. But for Windows console you will need to use the Unicode character codes, which probably do not preserve the original system, so perhaps just define a map where these graphics characters are placed more systematically.
Possibly that already exists.
If you don't care about portability, the Windows API for this can be found here. It will supply all the functions you need, without the need to pack additional libraries with your application.
You can also look in to graphics.h, a non-standard Borland extension that a lot of older graphical games used to use. It goes far beyond the normal limits of the console, but is only supported by 16 bit systems, of which Microsoft has all but removed support for from Windows. You'd also need an ancient Borland compiler, or an emulation, though you probably want the original look and feel.
I am writing a simple program in C++ to be run in a terminal window. I would like the output text to be locked in position on the screen. Instead of each new line appearing at the bottom of the screen and pushing everything up, I would like to be able to change a line of text or some characters in a line of text, while keeping other lines above and below it static. I know I have seen this done in terminal, and I believe it was done with C++, but I can't find any documentation on it. I cannot even think of what this type of display might be called. My google fu has failed me; please help. If you can tell me what commands/library to use, that would be great, but even being able to tell me what commands accomplish this in a programming language other than C++ would give me more to go on than I have now.
You want ncurses, a library for displaying text on a terminal.
If you are programming for Microsoft Windows, try googling for Win32 Console Functions.
I am trying to write a C++ program where the screen updates every 1 second. However, I want the screen to be similar to htop, where it updates and does not have to scroll with each update. That way, I don't have a step-by-step iteration in my terminal.
Does anyone know what this style is called or how to program it?
Thanks!
The usual way is with something like ncurses. If you're on Windows, it has console functions built in so you can do the same without any extra libraries (though they do take a while to understand). If you only want one line of output, you can use a '\r' to return to the beginning of the current line and/or \b to backspace over previous characters (handy if yoy only want to overwrite a few little bits and pieces).
You'll need a library like curses (on *nix) or pdcurses for Windows (conio functions would probably still work on windows).
I was wondering if you can add a link to a website in a C++ program running in the CMD Prompt type window (No GUI)
If it's possible can some one please give me a few examples?
You mean output text in the command prompt that the user can then click on? No, not unless the terminal supported it. Linux terminals usually autolink text that matches a URL pattern, so you could just printf("http://stackoverflow.com/\n"); and it would be clickable, but that's up to the terminal, not your program
When you write 'direct link' it is not clear if you mean clickable text or a means to open a url. At any rate, command line programs usually respond to command line parameters. Your program could open a url in the default browser in response to a command line flag. On Windows, you could call ShellExecute - on other systems, system might be appropriate.
It depends. In Windows, for example, yes, it's entirely possible, though somewhat non-trivial. You can receive mouse events via ReadConsoleInput, so in theory it's a fairly straightforward matter of reading the input event, and if it's a mouse click over the area you've defined as a link, you direct the user to the link as you see fit -- if you want to display the web site in text mode, that's possible (though, again, distinctly non-trivial). If you want to start up the user's normal web browser, that's a lot simpler (normally just ShellExecute the URL).
In reality, the details get a bit ugly. You have to enable mouse input for it to work at all. ReadConsoleInput gives you an INPUT_RECORD, which is a union of a number of different input record types, one of which is a mouse input record. By the time you get to react to a mouse click, your code is nested fairly deeply. None of it is unmanageable by any means, but unless you already have a fair amount of experience with Windows console programming, it might easily take most of a day (maybe even a bit more) before you have it working, rather than the hour or two you'd initially guess.
That, of course, is strictly for Windows -- if you ever want to port the code to another system, I'd guess there's a pretty good chance you'd be looking at a complete rewrite. For GUIs there are a fair number of cross-platform libraries, but text mode mouse operations aren't nearly so well supported.