Screen Editing

Discussion in 'C Programming' started by someone, Aug 17, 2006.

  1. someone

    someone Guest

    I was just wondering if there is any way of editing anything already
    printed on the screen with out using the system("cls") command.
    someone, Aug 17, 2006
    1. Advertisements

  2. Not portably, since a standard-conformant implementation need not
    involve anything resembling a "screen". There are a number of choices
    available depending on your needs and platform, but none of them are
    topical here.
    Christopher Benson-Manica, Aug 17, 2006
    1. Advertisements

  3. There is no portable way to do this.

    The comp.lang.c FAQ is at <>. You have asked
    question 19.4.
    Keith Thompson, Aug 17, 2006
  4. printf("\033[2J"); /* clear screen */
    printf("\033[%d;%dH", 10, 20); /* move cursor (row 10, col 20) */
    printf("Hello, ");
    printf("\033[7mworld\033[0m!"); /* inverse video */

    I tried upper commands. Seems does not work proper as the explanations.

    printf("\033[2J"); display"<-2j"
    could anyone tell me his results?
    Chen Shusheng, Aug 17, 2006
  5. flush the output, stdout might be buffered.
    Perhaps your output device doesn't understand these ansi escape
    codes, read its documentation.
    =?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=, Aug 17, 2006
  6. There is no "C" way to do this, as C precedes most CRT terminals,

    Even the few that existed back then cost about $3 to $15 THOUSAND
    dollars each, and each had its own quirky control sequence for clearing
    the screen. The first one I ever saw was in 1969, at a trade show,
    made by Univac, and cost $15,000, retail.

    and it's not clear terminal control falls under the baliwick of the C
    language or th standard C libraries..

    The most portable way is dorky, but works most every place I can think

    for( i=1; i <= 66 + 24 /* for those TALL full page displays,plus
    lagniappe */; i++ )
    puts( "\n" );

    If your intended terminal has some alleged "ANSI" control code
    capability, there's something gross, like puts( "\033;2J" ) that does
    the trick, google for "termcap vt100" or ANSI and see the "cl" entry.
    Ancient_Hacker, Aug 17, 2006
  7. Most terminals, particularly modern ones, will clear the screen if
    you simply send them a formfeed. It's not guaranteed, but it's a
    similar kind of assumption to backspace will move the cursor left
    which seems pretty much standard these days.

    I'd agree looking at the termcap manual would be a good idea, though,
    at least if the OP is talking about a serial terminal or an emulation
    of one.
    Andrew Smallshaw, Aug 17, 2006
  8. Strange. Those CRT terminals that I was using regularly for more than
    10 years before C existed. In fact, the first PDP-1 of 1957 had a CRT
    display (which is iconized in the DECUS logo). I used plenty of VT05s
    and VT52s (the later are still 4 years before C). Even the ANSI
    standard X3.64 predates the publication of K&R1, although Heath's
    implementation and DEC's VT100 were not yet out at K&R1's publication date.
    Martin Ambuhl, Aug 17, 2006
  9. No, because C does know nothing about a screen, TTY, printer or other
    devises. So you may ask in a group related to POSIX or to your OS to
    get a solution beside standard C.


    Visit the home of german eComStation
    eComStation 1.2 Deutsch ist da!
    Herbert Rosenau, Aug 17, 2006
  10. you're confused. Whether you've observed a particular terminal driver,
    or a user application is probably irrelevant.
    Thomas Dickey, Aug 17, 2006
  11. I don't think Andrew is confused. I think you are.

    Tak-Shing Chan, Aug 17, 2006
  12. C does know about character display semantics (ISO 9899/1990
    *and* 1999, 5.2.2), specifically backspaces ('\b'), form feeds
    ('\f'), and carriage returns ('\r'). So yes, it is possible to
    ``edit'' something already printed on a display device (however,
    quality of implementation differs).

    Tak-Shing Chan, Aug 17, 2006
  13. What about ISO 9899:1990, 5.2.2, where escape sequences for
    display devices (such as '\f', '\b' and '\r') are defined? The
    only problem with these are quality of implementation issues.

    Tak-Shing Chan, Aug 17, 2006
  14. [/QUOTE]
    hmm. I have a list in mind. Which "modern" one clears the screen
    when you send a form-feed to it?
    Thomas Dickey, Aug 17, 2006
  15. It occurs to me that you don't know
    (googling to get a sense of your background makes that apparent).

    A quick check shows putty doing this. vt100/etc don't. putty, of course,
    is not a vt100 emulator (or xterm, etc). xterm and anything that emulates
    vt100 will simply move the cursor to the next line.

    There's some useful information on which you might read before
    wasting more bandwidth.

    Thomas Dickey, Aug 17, 2006
  16. Andrew wrote: ``it's not guaranteed''. Which part of ``it's
    not guaranteed'' you don't understand?

    Tak-Shing Chan, Aug 17, 2006
  17. All irrelevant to my point. By the way, PuTTY is more
    "modern" than vt100, but I suppose you are not aware of this
    (judging from what you wrote above).

    Tak-Shing Chan, Aug 17, 2006
  18. [/QUOTE]
    Indeed. You don't know the answer to my question, so you're attempting
    to justify it by changing the question.
    Thomas Dickey, Aug 17, 2006
  19. I don't need to know the answer, since Steve Summit's C-FAQ
    19.4 covered this (``for clearing the screen, a halfway portable
    solution is to print a form-feed character ('\f'), which will
    cause some displays to clear''). Presumably, those displays that
    would clear are still in use.

    Tak-Shing Chan, Aug 17, 2006
  20. [/QUOTE]
    not at all. The statement was that

    "most terminals, particularly modern ones",

    fall into this category. Offhand, I know that xterm, gnome-terminal,
    konsole, mlterm, rxvt (and kindred) all emulate this feature of vt100.
    Even Linux console, now that I think of it.

    Now again - where's your list?

    I'll give a hint: one is smaller than six (even lumping together rxvt,
    Eterm, aterm, wterm, mterm and rxvt-unicode). There are of course
    other terminal emulators running only in Windows - but most of those
    emulate vt100 reasonably well (and it's unlikely that many of them would
    have such an easily observed defect). Still, you're welcome to make a
    list, and (for the edification of _your_ peers), convince them that
    a list of one item makes a general case.

    Thomas Dickey, Aug 17, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.