Displaying and reading information from/to the screen...

This is a discussion on Displaying and reading information from/to the screen... within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm a new C++ programmer. I've been going through lots of tutorials, doing the exercises, and reading lots of ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    1

    Displaying and reading information from/to the screen...

    Hello,

    I'm a new C++ programmer. I've been going through lots of tutorials, doing the exercises, and reading lots of books (on my kindle). It's all starting to come together.

    I'm at the stage where I'd like to start my own project as a learning-aid. What I have in mind is a simple, console-based document editor. Something like VIM (obviously not as complex as VIM).

    However, that would require the ability for the user to move the cursor around using the arrow-keys, to select text (by holding down shift), and also to over-write text. This text then needs to be able to be read from the screen and saved. It would also require the ability to "clear" the current console screen of all command prompts, etc., and write to it from a completely blank state.

    I don't have any idea how to do this. Obviously cout and cin, that I've been using so far, are not going to cut it.

    I'd appreciate a nudge in the right direction. Which APIs and libraries should I be researching?

    Thanks.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Location
    Some rock floating in space...
    Posts
    32

    Arrow

    NCURSES Announcing ncurses 5.9 - GNU Project - Free Software Foundation (FSF)

    NCURSES is probably your best bet. It will also help make your code portable to many Unix environments. It's been ported to just about everything with a console/terminal interface to it.

    NOTES:

    (1) ncurses windows only maintain a buffer for currently displayed text. Once the window is scrolled off the display portion of the window/screen, it is then destroyed. So you have to code your own window buffer management code which refreshes the window based on the viewable ( within the displayed portion of the window ) text in the buffer and update the window with your own code.

    (2) wgetch() will wait for input until a key is pressed unless you call the nodelay(your_window,TRUE) function to set nodelay to TRUE. In which case the wgetch() function will return ERR if no input is available rather than waiting for input... you may want to remember that if there are other things you'd like to do in a loop when input isn't available.

    (3) ncurses is a very finicky library if you're new to it ( which I am ). Everything has to be just right for the code to work properly ( doesn't it always, I know ) So you may become frustrated at first trying to learn it.

    (4) ncurses color support is limited. You have to define colors as color pairs using init_pair() function. ncurses on a typical terminal will only allow COLOR_PAIRS-1 color pairs... which on my terminal seems to be 63 color pairs. On other terminals, this value can be zero ( monochrome ) or as little as 7 colors total not counting COLOR_PAIR(0) which is reserved by ncurses. In short, you can't just set a color without it being defined as a color pair first. I'm sure there's a way, but I haven't been able to determine the format of attr_t and it can be different on a given platform, so no use to bother.

    (5) Keep in mind that terminal windows can be resized and you will have to code for this so that your program redraws itself properly. Under most of the Unix environments, this means having a SIGWINCH signal handler. And under windows, you'll have to poll GetConsoleBufferInfo periodically in your main program loop to be sure that the windows and screen are the correct dimensions.



    I'm new to ncurses myself and am currently learning it. So my information I've provided may be incomplete or partially accurate. Your only other option is to use another text mode windowing library such as the one that comes with the borland compilers ( which will limit your code to one compiler system ) or to write your own using the low-level console control functions in the Windows API or termio/termcaps and ioctl for Linux for example

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. displaying debug information
    By steve1_rm in forum C Programming
    Replies: 10
    Last Post: 02-17-2009, 10:36 AM
  2. Displaying Process Information From task_struct?
    By smoothdogg00 in forum C Programming
    Replies: 2
    Last Post: 12-19-2006, 07:05 PM
  3. Storing Information then Displaying
    By peckitt99 in forum C++ Programming
    Replies: 11
    Last Post: 09-05-2006, 11:29 AM
  4. Problems Displaying the Information
    By HAssan in forum C Programming
    Replies: 2
    Last Post: 10-14-2005, 12:50 AM
  5. reading files and displaying them on screen
    By kendals in forum C Programming
    Replies: 4
    Last Post: 03-29-2002, 04:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21