java 控制台 重新输出,Java:我如何修改控制台输出?

博主正在尝试创建一个简单的基于终端的文本编辑器,该编辑器需要读取文件内容并允许用户修改。面临的问题是无法改变已打印到控制台的文本,并且需要实现Enter+S快捷键来保存修改回原始文件。Charva是一个类似Curses的Java库,能够通过发送控制代码到终端来实现文本编辑功能。博主计划用这个库来解决在没有GUI的情况下移动光标、修改和保存文本的难题。
摘要由CSDN通过智能技术生成

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!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值