• in command line program, how to output the progress in the same line

    From luocl@21:1/5 to All on Fri May 27 14:53:50 2022
    #!/usr/bin/env -S tclsh
    proc relay fd {
    set out [read $fd]
    if {{} ne $out} {
    puts -nonewline $out
    flush stdout
    }
    if {[eof $fd]} {
    close $fd
    set ::forever 1
    }
    }
    set fd [open "| fossil clone https://chiselapp.com/user/LuoChunlei/repository/luocl luocl.fossil 2>@1" r] chan configure $fd -blocking 0 -buffering none
    fileevent $fd readable [list relay $fd]
    vwait ::forever
    return

    run the tcl script of the above, can not obtain the following [fossil
    clone] output, the [script] output in the last. how can I output the
    progress in the same line???

    [fossil clone https://chiselapp.com/user/LuoChunlei/repository/luocl luocl.fossil 2>@1] output:
    Round-trips: 2 Artifacts sent: 0 received: 146
    Clone done, sent: 584 received: 79948 ip: 74.208.146.128
    Rebuilding repository meta-data...
    100.0% complete...
    Extra delta compression...
    Vacuuming the database...
    project-id: 2d2b2705f0290a1ad6d74e67624da7be0f311728
    server-id: bc6f8571ca049ec687520d9a762d154560fa7438
    admin-user: luocl (password is "2SrHjLvRFP")

    [script] output:
    Round-trips: 1 Artifacts sent: 0 received: 0
    Round-trips: 1 Artifacts sent: 0 received: 143
    Round-trips: 2 Artifacts sent: 0 received: 143
    Round-trips: 2 Artifacts sent: 0 received: 146
    Clone done, sent: 582 received: 79948 ip: 74.208.146.128
    Rebuilding repository meta-data...
    0.0% complete...
    0.6% complete...
    1.3% complete...
    .
    .
    .
    99.3% complete...
    100.0% complete...
    Extra delta compression...
    Vacuuming the database...
    project-id: 2d2b2705f0290a1ad6d74e67624da7be0f311728
    server-id: 2c8b2e79dcce66c9f4aaeff964ce51660f9e1788
    admin-user: luocl (password is "Mf3AVgedCu")

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From apn@21:1/5 to luocl on Fri May 27 13:28:57 2022
    On 5/27/2022 12:23 PM, luocl wrote:
    run the tcl script of the above, can not obtain the following [fossil
    clone] output, the [script] output in the last. how can I output the
    progress in the same line???

    Either use [puts -nonewline] in combination with ANSI terminal sequences
    or with \r to back to the start of the line.

    % puts -nonewline "Wait a bit ..." ; flush stdout; after 1000 ; puts
    "\rAll done. "

    Note if you use \r, you'll need trailing blanks to overwrite the
    previous output unless all lines are the same length. ANSI terminal
    sequences are better in that respect but I'm not sure if all Windows
    consoles support them.

    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to luocl on Fri May 27 09:52:19 2022
    On 27/05/2022 08:53, luocl wrote:
    how can I output the progress in the same line???

    My guess, without actually trying the code: The progress output is
    probably generated using \r to overwrite a previous line. By default Tcl
    will treat all of \n, \r, and \r\n as a newline and translate it to \n.
    You don't want that in this case. So narrow down the newline translation:

    chan configure $fd -translation lf


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luocl@21:1/5 to All on Fri May 27 17:04:22 2022
    #!/usr/bin/env -S tclsh
    proc relay fd {
    set out [read $fd]
    if {{} ne $out} {
    puts -nonewline $out
    flush stdout
    update
    }
    if {[eof $fd]} {
    close $fd
    set ::forever 1
    }
    }
    set fd [open "| fossil clone https://chiselapp.com/user/LuoChunlei/repository/luocl luocl.fossil 2>@1" r] chan configure $fd -blocking 0 -buffering none -translation lf
    fileevent $fd readable [list relay $fd]
    vwait ::forever
    return


    now the [script]'s output is exactly the [fossil clone]'s output. Thank
    you all!!!, from Schelte's reply I add "-translation lf" to the [chan configure], from apn's reply I add [update] after [puts]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Fri May 27 10:02:01 2022
    At Fri, 27 May 2022 14:53:50 +0800 luocl <[email protected]> wrote:


    #!/usr/bin/env -S tclsh
    proc relay fd {
    set CR "\r"
    set NLPatttern "\n$"
    set out [read $fd]
    if {{} ne $out} {
    puts -nonewline $out

    set out [regsub -all $NLPattern $out ""];# Remove trailing newlines
    puts -nonewline "${CR}$out";# Prefix output with a Carriage return

    flush stdout
    }
    if {[eof $fd]} {
    close $fd
    set ::forever 1
    }
    }
    set fd [open "| fossil clone https://chiselapp.com/user/LuoChunlei/repository/luocl luocl.fossil 2>@1" r] chan configure $fd -blocking 0 -buffering none
    fileevent $fd readable [list relay $fd]
    vwait ::forever
    return

    run the tcl script of the above, can not obtain the following [fossil
    clone] output, the [script] output in the last. how can I output the
    progress in the same line???

    [fossil clone https://chiselapp.com/user/LuoChunlei/repository/luocl luocl.fossil 2>@1] output:
    Round-trips: 2 Artifacts sent: 0 received: 146
    Clone done, sent: 584 received: 79948 ip: 74.208.146.128
    Rebuilding repository meta-data...
    100.0% complete...
    Extra delta compression...
    Vacuuming the database...
    project-id: 2d2b2705f0290a1ad6d74e67624da7be0f311728
    server-id: bc6f8571ca049ec687520d9a762d154560fa7438
    admin-user: luocl (password is "2SrHjLvRFP")

    [script] output:
    Round-trips: 1 Artifacts sent: 0 received: 0
    Round-trips: 1 Artifacts sent: 0 received: 143
    Round-trips: 2 Artifacts sent: 0 received: 143
    Round-trips: 2 Artifacts sent: 0 received: 146
    Clone done, sent: 582 received: 79948 ip: 74.208.146.128
    Rebuilding repository meta-data...
    0.0% complete...
    0.6% complete...
    1.3% complete...
    .
    .
    .
    99.3% complete...
    100.0% complete...
    Extra delta compression...
    Vacuuming the database...
    project-id: 2d2b2705f0290a1ad6d74e67624da7be0f311728
    server-id: 2c8b2e79dcce66c9f4aaeff964ce51660f9e1788
    admin-user: luocl (password is "Mf3AVgedCu")



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luocl@21:1/5 to All on Sat May 28 08:22:02 2022
    IMO, for the script, Schelte's solution is better.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luocl@21:1/5 to Schelte on Sat May 28 08:49:31 2022
    On 5/27/22 3:52 PM, Schelte wrote:

        chan configure $fd -translation lf
    I just suddenly thought, maybe "-translation binary" is the same, so I
    test it, as expected it is ok.

    Thank you again, for remarkable package {tee timestamp www mqtt fsdialog fswatch etc.}


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)