Question

Je développe un programme CLI, en C, pour mon projet systèmes de classe, et il a besoin d'afficher du texte entrant tout en maintenant une invite de commande. Resté seul, le texte entrant scieront par quoi que l'on essaie de taper. Dans d'autres applications que j'ai vu l'impression de texte entrant ci-dessus (ou ci-dessous) l'invite lui-même. Est-il possible de mettre en œuvre ce en échappe ANSI? ncurses semble overkill.

Était-ce utile?

La solution

You can print \r to 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.

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top