Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Console.Write() or option to suppress newline in print.it()
#1
Hi there!

I am writing a program that does a whole bunch of background websocket calls to a device.  There may be a several to a few hundred calls per "step" and I'd like to log a single dot "." as a sort of progress indicator to the output window.  In a console app I would just do Console.Write("."); on each of my websocket read or write calls.  That way I get an output like:

Getting Network Interface Statistics and LLDP Neighbors
. . . . . . . . . . . . . . . 

That way I know I'm not hung up on some sort of websocket timeout and just waiting for an Exception.

It doesn't seem there's a way to suppress newlines in the print class.  I tried using Console.Write.  It seems the entire line gets buffered until a newline is added at the end.  Is there a way to output a single character to the "output" window inside the editor?

In a WPF application I've had to call something like:
System.Windows.Forms.Application.DoEvents();

to process the rendering of a scrolling textbox.  But I'm not sure that's the right approach here?

Thanks!
#2
The easy way.
C# code:
// script ""
/*/ console true; /*/

print.it("Getting Network Interface Statistics and LLDP Neighbors");
for (int i = 0; i < 10; i++) {
    300.ms();
    Console.Write(".");
}
print.it("\nDONE");
1.s();
#3
C# code:
// script ""
print.it("Getting Network Interface Statistics and LLDP Neighbors");
for (int i = 0; i < 10; i++) {
    300.ms();
    print2.it(".");
}
print.it("\nDONE");

/// <summary>
/// Alternative print functions.
/// </summary>
public unsafe class print2 {
    /// <summary>
    /// Adds text to the output pane like <b>print.it</b> but without newline.
    /// Does not support print tags (formatting, links, etc).
    /// </summary>
    /// <param name="s">Text.</param>
    public static void it(string s) {
        var w = wnd.findFast("LibreAutomate"); if (w.Is0) return;
        var c = w.ChildFast("Output_text", "Scintilla");
        if (c.Is0) {
            w = wnd.findFast("Au.Editor - Output"); if (w.Is0) return;
            c = w.ChildFast("Output_text", "Scintilla");
        }
        
        c.Send(SCI_GOTOPOS, c.Send(SCI_GETTEXTLENGTH));
        try {
            c.Send(SCI_SETREADONLY);
            for (int i = 0; i < s.Length; i++) {
                var k = s[ i ];
                if (k is '\r' or '\n') {
                    if (k is '\r' && s.Eq(i + 1, '\n')) continue;
                    c.Send(SCI_NEWLINE, k);
                } else if (k is '\t') {
                    c.Send(SCI_TAB, k);
                } else {
                    c.Send(WM_CHAR, k);
                }
            }
        }
        finally { c.Send(SCI_SETREADONLY, 1); }
    }
    
    const int SCI_SETREADONLY = 2171;
    const int SCI_GOTOPOS = 2025;
    const int SCI_GETTEXTLENGTH = 2183;
    const int SCI_NEWLINE = 2329;
    const int SCI_TAB = 2327;
    const int WM_CHAR = 0x102;
}
#4
I'll try implementing the print2 approach.  I tried the first approach before I posted here... I just copied your code and took a screen video... Check this out...

The dots don't actually get output to the window until the "\nDONE" does.

Like there's a buffer that's waiting to be written or something weird.  I've seen it before with other text boxes though as I said...

https://www.dropbox.com/s/nof1qhtgek300d...1.mp4?dl=0

No worries on that not working... It isn't a big deal and ideally in the final app it'll be outputting to a scrolling text block and I already have that working for another app Smile
#5
In the first code this is important:
Code:
Copy      Help
/*/ console true; /*/
#6
In next program version:
C# code:
print.it("<>.<nonl>");


Forum Jump:


Users browsing this thread: 1 Guest(s)