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
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in STDOUT
- Running powershell Script from Python (password decryption)
- Reading and writing from pipe after execvp using dup2
- Is it safe to output a NULL char to std::cout?
- Is there any way to recover from a printf()/puts() error?
- Adding a prefix to all output lines of "apt-update && apt-upgrade in BASH?
- Fastest way to select a line of standard out text in iterm2
- How to check if sys.stderr supports colors?
- Disable stdout in popen process
- Python subprocess threading with conole log not immediately updating
- How can I get terraform stdout to stream in a github action?
- How can I send specific messages to stdout from a bash prompt with multiple commands that is run via nohup?
- Can two subprocesses both send messages to stdout inside a Tcl/Expect script?
- How to output and log messages at the same time in python
- Tracing conditionally to stdout
- How to use data streamed to stdout after request to Google API using python SDK and flask
Related Questions in STDIN
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Bun.js: Read a single line user input
- Communicating Java and Python processes freeze after a while when using readline() but not input()
- Redirecting stdout with execvp
- Possible to record user input on GIT UI (IntelliJ Git, Sourceforge)? Specifically in the case of git hooks
- tar extract zip archive from file or STDIN - discrepancy
- Why is STDIN open by default for programs running in SystemD?
- Is it possible to listen for console input from a C# Windows Application?
- Executing sed via execvp makes other pipes blocked
- stdin file descriptor never ready on POLLIN event
- Exit inner loop only when EOF (Ctrl+D) is given via standard input
- Difference to get string with gets and fgets in C
- Calling bash from python subprocess maintaining context, returning results and printing to screen
- Input, left arrow key - Rust
- Read from stdin, but only while socket is connected
Related Questions in NCURSES
- NCURSESW - Unable to use addwstr function to print out unicode characters outside of standard ASCII
- ncurses - form field validation - can't modify "TYPE-INTEGER" value entered and outside range specified with set_field_type()
- Why is gnome-terminal slow when drawing characters with ncurses?
- how to install ncurses library in Android
- Preventing cursor flickering in ncurses applications
- Check for terminal resizing using ncurses under windows
- Libncurses5 installation for Ubuntu 23.1
- Displaying color in NCurses window
- ncurses timeout() is terminating my program
- '\n' Prints extra space in ncurses C++
- windows not showing when the terminal is made smaller (ncurses, c)
- How to use the pattern buffer of an ncurses menu?
- Sending and receiving text using C network sockets and Linux terminal
- Is there a hard limit for set_menu_format row or col arguments? Function is part of menu header file
- ncurses and multiprocessing
Related Questions in ANSI-ESCAPE
- General text wrap program in C
- Prepend a marker string in front of each line of another program's output, while preserving aligned tab-formatted tables
- Is there a way to send colour commands within an <xsl:message> to the console (wt.exe) from Saxon XSLT?
- Stop make shell interpreting arrow up
- Why are my Bash variables getting set late, animate text function
- How to determine terminal cursor visibility?
- How do I use System.Console.ANSI to wrap a String in escape sequences for getting it colored in the terminal?
- How to address ANSI Escape Sequences in sed?
- How to display ANSI colors in VSCode debug console?
- why 8-bit CSI cannot work in Terminal.app of macOS?
- How do I handle ansi escape sequences from a file?
- updating code already written, I need help for triple loops ForEach-Object to varie 3 variables
- Can I Prevent Git from Using XTerm Escape Sequences?
- Use ansi escape sequences to create a border between input and output
- Capture Mouse Events in the Terminal using Ruby
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 # Hahtags
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.