Is it possible to edit content already written to the command prompt using Ruby?
So for example, lets say I've written 10 lines to STDOUT, can I move the cursor to, say, lime five and overwrite just that line?
Thanks.
Is it possible to edit content already written to the command prompt using Ruby?
So for example, lets say I've written 10 lines to STDOUT, can I move the cursor to, say, lime five and overwrite just that line?
Thanks.
Yes you can, on a Windows Vista, 7 and probably 8 and also in some third-party extended command-interpreters like 4NT and Take Command you can recall previous commands by using the up-key, edit the line and re-execute the line. I don't see what Ruby has got to do with this. If you want to let Ruby type keystrokes in a console that is possible using the auto-it Active-X control.
EDIT: here a sample using Autoit to edit the console, downlaod and install it first and then run the following script. To make sure the script doesn't interact with other open consoles i copied mu cmd.exe to a cmd2.exe which is started up first.
require 'win32ole'
title = "C:\\Windows\\System32\\cmd2.exe"
STDOUT.sync = true
ai = WIN32OLE.new("AutoItX3.Control")
ai.winwait(title)
ai.WinActivate(title, "")
ai.Send "cls{ENTER}"
1.upto(4) do |i|
ai.Send "line#{i}{ENTER}"
end
1.upto(4) do |i|
ai.Send "{UP}"
sleep 1
end
ai.Send "line one {ENTER}"