Jump to content

Output to console at the same line continuously


Go to solution Solved by UEZ,

Recommended Posts

Posted

Hi. Quick question:

How can I avoid such thing:

Processing 1 of 10 (10%)...
Processing 2 of 10 (20%)...
Processing 3 of 10 (30%)...
Processing 4 of 10 (40%)...

when using ConsoleWrite, in favor of only one line being rewritten/erased multiple times?

Posted

Thank you, that works great when run from cmd.exe. But do you know if it's also possible to achieve this in Scite? Or maybe it was designed like so on purpose?

Posted (edited)

This example works with SciTE's output pane..

For $i = 1 To 5
    _ConsoleWriteSameLine("Line #" & $i)
    Sleep(1000)
Next

ConsoleWrite("The End" & @LF)


Func _ConsoleWriteSameLine($sMessage)
    ControlSend("[Class:SciTEWindow]", "", "Scintilla2","+{HOME}{DEL}{BS}+{HOME}{DEL}")
    ConsoleWrite($sMessage & @LF)
EndFunc   ;==>ConsoleWriteSameLine

Edit: Replaced Chr(8) & "+{HOME}{DEL}") ; Chr(8) = backspace character, in the case where characters already exist on the line being written to. The first "+{HOME}{DEL}" deletes that line, if it exists. Then, the "{BS}" makes the cursor jump to the line above where the second "+{HOME}{DEL}" deletes that line also.

Edited by Malkey
  • Moderators
Posted (edited)

That just looks like a horrible idea... but interesting to see how it turns out.

Edit:

I happened to pause the script at an opportune time:

For $i = 1 To 500
    _ConsoleWriteSameLine("Line #" & $i)
    Sleep(100)
Next

ConsoleWrite("The End" & @LF)


Func _ConsoleWriteSameLine($sMessage)
    ControlSend("[Class:SciTEWindow]", "", "Scintilla2","+{HOME}{DEL}{BS}+{HOME}{DEL}")
    ConsoleWrite($sMessage & @LF)
EndFunc   ;==>ConsoleWriteSameLine 

Scite->Output:

ine #139Line #140

 

Other times I saw the BS char.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...