Is it possible to print text that can be edited by the user (for console programs)?

前端 未结 3 1310
小蘑菇
小蘑菇 2020-12-21 06:39

Say I allow the user to edit something, like the phone number in an Address Book (actually, that\'s exactly what I\'m doing). Is there something that I can add to println th

3条回答
  •  鱼传尺愫
    2020-12-21 07:04

    There are various options for this, in order of simplicity and portability to features and complexity:

    1. Simply prompt for the information, reading a complete (return-terminated) line of response, and allow the normal terminal input facilities to be used for basic editing.

    2. Use something like the gnu readline library to allow more advanced editing. You still won't have widgets (text input boxes at specific places on screen) as such though. There's a java implementation here: http://java-readline.sourceforge.net/

    3. Use something like ncurses to specifically position the cursor, print text labels, handle keypresses, and implement your own text input box. Not fun.

    4. Use a textual user interface library (TUI), like this one: http://www.bmsi.com/tuipeer/

提交回复
热议问题