3

I need to write a simple terminal-based program that should,

  1. Read some text from a file using FileReader wrapped in BufferedReader.
  2. Print this text to console and a user should be able to modify it.
  3. 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.

  1. All the text that is printed by System.out is immutable. How can I change this behaviour?

  2. 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!

4
  • All the text that is printed by System.out is immutable. How can I change this behaviour? What do you mean by that? Commented Jul 15, 2011 at 7:46
  • He means usually after it's printed out you can't just go back and change it. Commented Jul 15, 2011 at 7:48
  • @cularis I mean that once "Hello World" is printed you cannot backspace it to "Hello". Commented Jul 15, 2011 at 7:48
  • people always ask that for some reason:) No, it is actually a real-life program intended for embedded systems with no GUI. Commented Jul 15, 2011 at 8:01

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

that is something interesting....and might fulfill user825089's purpose. Thanks Stephen, I too found it useful.
Thank you, that was indeed very helpful. Will definitely check it out.
1

These kinds of things are done in Unix with the curses library: http://en.wikipedia.org/wiki/Curses_(programming_library).

1 Comment

Thanks, did not even know what these curses are. Have to learn about them in general, first.
1

http://sourceforge.net/projects/javacurses/ you need something like that. Try to find some free java curses library

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.