<p>How do some programs edit whats being displayed on the terminal (to pick a random example, the program 'sl')? I'm thinking of the Linux terminal here, it may happen in other OS's too, I don't know.  I've always thought once some text was displayed, it stayed there. How do you change it without redrawing the entire screen? </p>

[{'answer_id': 78007, 'author': 'Sarien', 'author_id': 1994377, 'author_profile': 'https://Stackoverflow.com/users/1994377', 'pm_score': 2, 'selected': False, 'text': '<p>There are characters that can be sent to the terminal that move the cursor back. Then text can be overwritten.</p>\n\n<p>There is a list <a href="http://ascii-table.com/ansi-escape-sequences-vt-100.php" rel="nofollow noreferrer">here</a>. Note the "move cursor something" lines.</p>\n'}, {'answer_id': 78017, 'author': 'deemer', 'author_id': 11192, 'author_profile': 'https://Stackoverflow.com/users/11192', 'pm_score': 2, 'selected': False, 'text': '<p>If you terminate a line sent to the terminal with a carriage return (\'\\r\') instead of a linefeed (\'\\n\'), it will move the cursor to the beginning of the current line, allowing the program to print more text over top of what it printed before.  I use this occasionally for progress messages for long tasks.</p>\n\n<p>If you ever need to do more terminal editing than that, use <a href="http://www.gnu.org/software/ncurses/ncurses.html" rel="nofollow noreferrer">ncurses</a> or a variant thereof.</p>\n'}, {'answer_id': 78028, 'author': 'pix0r', 'author_id': 72, 'author_profile': 'https://Stackoverflow.com/users/72', 'pm_score': 0, 'selected': False, 'text': '<p>To build on @Corporal Touchy\'s answer, there are libraries available that will handle some of this functionality for you such as <a href="http://en.wikipedia.org/wiki/Curses_(programming_library)" rel="nofollow noreferrer">curses/ncurses</a></p>\n'}, {'answer_id': 78039, 'author': 'mana', 'author_id': 12016, 'author_profile': 'https://Stackoverflow.com/users/12016', 'pm_score': 3, 'selected': False, 'text': '<p>try this shellscript </p>\n\n<pre><code>#!/bin/bash\ni=1\nwhile [ true ]\n    do\n            echo -e -n "\\r $i"\n            i=$((i+1))\n    done\n</code></pre>\n\n<p>the -n options prevents the newline ... and the \\r does the carriage return ... you write again and again into the same line - no scroling or what so ever</p>\n'}, {'answer_id': 78041, 'author': 'danio', 'author_id': 12663, 'author_profile': 'https://Stackoverflow.com/users/12663', 'pm_score': 1, 'selected': False, 'text': '<p>Corporal Touchy has answered how this is done at the lowest level.  For easier development the <a href="http://www.manpagez.com/man/3/ncurses/" rel="nofollow noreferrer">curses library</a> gives a higher level of control than simply sending characters to the terminal. </p>\n'}, {'answer_id': 78050, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 4, 'selected': True, 'text': '<p>Many applications make use of the <a href="http://en.wikipedia.org/wiki/Curses_(programming_library)" rel="noreferrer">curses</a> library, or some language binding to it.</p>\n\n<p>For rewriting on a single line, such as updating progress information, the special character "<a href="http://en.wikipedia.org/wiki/Carriage_return" rel="noreferrer">carriage return</a>", often specified by the escape sequence "\\r", can return the cursor to the start of the current line allowing subsequent output to overwrite what was previously written there.</p>\n'}, {'answer_id': 78051, 'author': 'Jacob Krall', 'author_id': 3140, 'author_profile': 'https://Stackoverflow.com/users/3140', 'pm_score': 1, 'selected': False, 'text': '<p>NCurses is a cross-platform library that lets you draw user interfaces on smart terminals.</p>\n'}, {'answer_id': 78073, 'author': 'Adam Pierce', 'author_id': 5324, 'author_profile': 'https://Stackoverflow.com/users/5324', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with danio, ncurses is the way to go. Here\'s a good tutorial:</p>\n\n<p><a href="http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/" rel="nofollow noreferrer">http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/</a></p>\n'}, {'answer_id': 2222556, 'author': 'Yamodax', 'author_id': 268321, 'author_profile': 'https://Stackoverflow.com/users/268321', 'pm_score': 3, 'selected': False, 'text': '<p>Depending on the terminal you send control seuqences.  Common sequences are for example esc[;H  to send the cursor to a specific position (e.g. on Ansi, Xterm, Linux, VT100).  However, this will vary with the type or terminal the user has ... curses (in conjunction with the terminfo files) will wrap that information for you.</p>\n'}]
['https://Stackoverflow.com/questions/77990', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14210/']