I need to write a simple terminal-based program that should,
- Read some text from a file using FileReader wrapped in BufferedReader.
- Print this text to console and a user should be able to modify it.
- Upon Enter + S, the program should read the modified text and save it back to the original file.
To sum up, the idea is to write a text editor for Unix-like environments with no GUI.
However, I have problems with steps 2 and 3.
All the text that is printed by System.out is immutable. How can I change this behaviour?
How do I implement a key listener for Enter + S. I can easily do it with GUI, but what do I add a listener to in a console-based program? And on Enter the program should simply add a new line to the modified text. Also, how can I read text that has already been printed to the terminal?
P.S. I have to use JDK 1.4 so no access to Scanner and Console classes if it is any relevant. I also think that such a task would be impossible to do in Java, so you could suggest a solution in C/C++ After all, they did it somehow back in MS-DOS era.
Thank you!
http://sourceforge.net/projects/javacurses/ you need something like that. Try to find some free java curses library
What you need is something like charva. It is a Java library that does what the old termcap / termio / curses / ncurses libraries did in the days of 24 x 80 terminals.
Charva (and curses, etc) work by sending control codes and/or escape sequences to the terminal or terminal emulator to move the cursor around, write and erase characters and so on. On a modern system, they depend on the console providing ANSI or VT100 terminal emulation ... or something like that.
These kinds of things are done in Unix with the curses library: http://en.wikipedia.org/wiki/Curses_(programming_library).