@@ -113,25 +113,26 @@ module private ConsoleSink =
113113 | Verbose -> Some ( ConsoleColor.Magenta, ConsoleColor.DarkMagenta)
114114 | _ -> None
115115
116+ let fmtTs ( ts : System.TimeSpan ) =
117+ ( if ts.TotalHours >= 1.0 then " h'h'\ mm'm'\ ss's'"
118+ else if ts.TotalMinutes >= 1.0 then " mm'm'\ ss's'"
119+ else " '0m 'ss's'" )
120+ |> ts.ToString
121+
122+ let po = MailboxProcessor.Start( fun mbox ->
116123
117- let po = MailboxProcessor.Start( fun mbox ->
118- let fmtTs ( ts : System.TimeSpan ) =
119- ( if ts.TotalHours >= 1.0 then " h'h'\ mm'm'\ ss's'"
120- else if ts.TotalMinutes >= 1.0 then " mm'm'\ ss's'"
121- else " '0m 'ss's'" )
122- |> ts.ToString
123124 let rec loop ( progressMessage ) =
124- let wipe pos =
125- match progressMessage with
126- | None -> ()
127- | Some x ->
128- let extraChars = ( String.length x ) - pos
129- System.Console.Write ( if extraChars > 0 then ( String.replicate extraChars " " ) else " " )
125+ let wipeProgressMessage () =
126+ let len = progressMessage |> Option.fold ( fun _ -> String.length ) 0
127+ // printfn "cleft: %A len: %d" Console.CursorLeft len
128+ match len - Console.CursorLeft with
129+ | e when e > 0 -> System.Console.Write ( String.replicate e " " )
130+ | _ -> ( )
130131 let renderProgress = function
131132 | Some ( outputString: string) ->
132133 Console.ForegroundColor <- ConsoleColor.White
133134 Console.Write outputString
134- wipe outputString.Length
135+ wipeProgressMessage ()
135136
136137 Console.ResetColor()
137138 | None -> ()
@@ -141,17 +142,17 @@ module private ConsoleSink =
141142 match msg with
142143 | Message( level, text) ->
143144 match level |> levelToColor with
144- | Some ( color, text _ color ) ->
145- let levelStr = sprintf " [ %s ] " ( LevelToString level )
145+ | Some ( color, textColor ) ->
146+ // in case of CRLF in the string make sure we washed out the progress message
146147
147148 Console.ForegroundColor <- color
148- Console.Write levelStr
149+ Console.Write ( sprintf " \r [ %s ] " ( LevelToString level ))
149150
150- Console.ForegroundColor <- text _ color
151+ Console.ForegroundColor <- textColor
151152 text |> System.Console.Write
152153
153- wipe ( levelStr.Length + text.Length )
154- System.Console.WriteLine " "
154+ wipeProgressMessage ( )
155+ System.Console.WriteLine()
155156 renderProgress progressMessage
156157
157158 | _ -> ()
@@ -163,13 +164,14 @@ module private ConsoleSink =
163164 | a when a >= 100 || a < 0 || timeLeft.TotalMilliseconds < 100.0 -> " "
164165 | pct ->
165166 let barlen = pct * ProgressBarLen / 100
166- sprintf " %3d %% [%s%s ] %s \r " pct ( String.replicate barlen " =" ) ( String.replicate ( ProgressBarLen - barlen) " -" ) ( fmtTs timeLeft)
167+ sprintf " \r %3d %% Complete [%s%s ] %s Left" pct ( String.replicate barlen " =" ) ( String.replicate ( ProgressBarLen - barlen) " " ) ( fmtTs timeLeft)
168+ |> Some
167169
168- renderProgress ( Some outputString)
169- return ! loop ( Some outputString)
170+ renderProgress outputString
171+ return ! loop outputString
170172
171173 | Flush ch ->
172- wipe 0
174+ wipeProgressMessage ()
173175 Console.Write " \r "
174176 ch.Reply ()
175177 return ! loop None
@@ -205,7 +207,9 @@ let ConsoleLogger =
205207
206208/// Ensures all logs finished pending output.
207209let FlushLogs () =
208- ConsoleSink.po.PostAndReply ( ConsoleSink.Flush, 100 ) |> ignore
210+ try
211+ ConsoleSink.po.PostAndReply ( ConsoleSink.Flush, 200 ) |> ignore
212+ with _ -> ()
209213
210214/// Draws a progress bar to console log.
211215let WriteConsoleProgress =
0 commit comments