Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Console.Write() or option to suppress newline in print.it()
#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;
}


Messages In This Thread
RE: Console.Write() or option to suppress newline in print.it() - by Gintaras - 09-27-2022, 04:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)