I'm developing a CLI program, in C, for my systems class project, and it needs to display incoming text while maintaining a command prompt. Left alone, the incoming text will saw through whatever one tries to type. In other applications I've seen the incoming text print above(or below) the prompt itself. Is there any way to implement this in ANSI escapes? ncurses seems like overkill.
Isolating stdin and stdout within a terminal
308 Views Asked by Matthew At
2
There are 2 best solutions below
0
neuro
On
For one thing, if you want to maintain a prompt, while printing, you can not use things like scanf. You have to intercept keyboard events or use a non waiting method to get input. Then you can get the terminal number of lines (n) and print the last n-1 lines of your output, and then a prompt.
my2c
Related Questions in C
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in STDOUT
- linux stdin, stdout pipe
- Python Fabric won't comment beginning of line
- Sys.stdout in python cause cmd to hang when used more than 1000 times
- Redirect output from file to stdout
- Garbage char returned by Shell.StdOut.ReadAll
- Redirecting stdout/stderr on Windows
- Suppress stdout Python SIGSTOP
- how do i test subprocess's stdout, stderr in python on windows
- How to obtain the file descriptor of the current terminal in python?
- Unclear about stdin input issue
- IO Redirection in Linux Bash shell scripts not recreating moved/deleted file?
- Copy *unbuffered* stdout to file from within bash script itself
- How to block writes to standard output in java (System.out.println())
- Threading script not printing to console
- Command output to a file with batch scripting
Related Questions in STDIN
- Create a string array with length determined by user input
- Read next line when loading file in Common Lisp
- linux stdin, stdout pipe
- How to prevent child from interfering with parent's stdin after fork()
- Can I use STDIN for IPC?
- Windows/Linux child process STDIN differences
- Using raw_input causes problems with PyQt page loading
- Unable to setRawMode in a nodejs script
- Python: 'q)+' is not recognized as an internal or external command
- Unclear about stdin input issue
- Command line tool to get binary data as String in Windows like Cat?
- Force C to readin stdin as binary using MINGW
- Why is this code giving unexpected results?
- Python Paramiko SSH run command
- qt5 catch input from qtextedit
Related Questions in NCURSES
- What's a way to implement backspace working in field in ncurses
- addstr delay in Python Curses
- Moving Arc Mutex Ncurses window down thread still doesn't implement send
- Python testing ncurses
- Attributes for UTF-8 characters
- Using ncurses in c language
- how to print a matrix on c++ using ncurses?
- ncurses in C prints more than it should and prints colour codes
- Bug with refresh in python curses
- Compiler gives error: "Does not name a type" immediately after declared
- Best approach for building text based data entry app
- Python curses mouse event on Mac OS X
- How could I implement a scrolling window inside another?
- I'm getting an implicit declaration error only when using -std=c99
- Simple string assignment causing a segmentation fault?
Related Questions in ANSI-ESCAPE
- Behave test runner has no colored output on Jenkins
- why escape sequence can't be represented as unicodeEscape in java?
- Escape sequence to set cursor hollow?
- Adding colour to prompt stops updating current directory
- emacs: M-x shell and color codes (^[[0G[1])
- Can I force cygwin to show colors like dos prompt when running GoogleTest?
- Python print on lines that are not visible anymore on the terminal with ANSI escape codes
- Internals of ncurses: console input
- Meanings of terminal codes \033[E and \033[07, which appear in printf() statements?
- Golang test stdout
- How to query the character under the current cursor position or anywhere on the screen in bash
- Adding an array into another array (for a Java Battleship program)
- Are the escape sequences imported by ansicon nativly supported by Linux?
- Reading ESC on Linux during unbuffered input in C
- How do I convert linux pseudo terminal output in Java?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can print
\rto erase the prompt: It will return the cursor to the beginning of the current line. You can then print your output followed by some spaces to clear out any remaining input characters, newline, and reprint the prompt.With ANSI sequences or terminal-specific libraries you can do even more, but this I think is all you can do reliably using only ASCII. Apart from printing 242 blank lines to redraw the whole screen, of course.
Edit: Sorry, I didn't answer the ANSI part properly. With cursor movement control codes and printing space over existing characters, you can pretty much do anything, and there are some convenience actions to help you, such as "delete line". But keep in mind that Windows doesn't play nice w/ ANSI post XP, and neither are other systems guaranteed to.