-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace AvalonLog | ||
|
||
open AvalonLog.Util | ||
open AvalonLog.Brush | ||
open System | ||
open System.IO | ||
open System.Threading | ||
open AvalonEditB | ||
open System.Windows.Media // for color brushes | ||
open System.Text | ||
open System.Diagnostics | ||
open System.Windows.Controls | ||
open AvalonEditB.Document | ||
|
||
|
||
/// A TextWriter that writes using a function. | ||
/// To set Console.Out to a text writer get one via AvalonLog.GetTextWriter(red,green,blue) | ||
type LogTextWriter(write:string->unit, writeLine:string->unit) = | ||
inherit TextWriter() | ||
override _.Encoding = Text.Encoding.Default // ( UTF-16 ) | ||
|
||
override _.Write (s:string) = | ||
//if s.Contains "\u001b" then write ("esc"+s) else write ("?"+s) //debugging for using spectre ?? https://github.com/spectreconsole/spectre.console/discussions/573 | ||
write (s) | ||
|
||
override _.WriteLine (s:string) = // actually never used in F# printfn, but maybe buy other too using the console or error out , see https://github.com/dotnet/fsharp/issues/3712 | ||
//if s.Contains "\u001b" then writeLine ("eSc"+s) else writeLine ("?"+s) | ||
writeLine (s) | ||
|
||
override _.WriteLine () = | ||
writeLine ("") | ||
|
||
|
||
(* | ||
trying to enable ANSI Control sequences for https://github.com/spectreconsole/spectre.console | ||
but doesn't work yet ESC char seams to be swallowed by Console.SetOut to textWriter. see: | ||
//https://stackoverflow.com/a/34078058/969070 | ||
//let stdout = Console.OpenStandardOutput() | ||
//let con = new StreamWriter(stdout, Encoding.ASCII) | ||
The .Net Console.WriteLine uses an internal __ConsoleStream that checks if the Console.Out is as file handle or a console handle. | ||
By default it uses a console handle and therefor writes to the console by calling WriteConsoleW. In the remarks you find: | ||
Although an application can use WriteConsole in ANSI mode to write ANSI characters, consoles do not support ANSI escape sequences. | ||
However, some functions provide equivalent functionality. For more information, see SetCursorPos, SetConsoleTextAttribute, and GetConsoleCursorInfo. | ||
To write the bytes directly to the console without WriteConsoleW interfering a simple file-handle/stream will do which is achieved by calling OpenStandardOutput. | ||
By wrapping that stream in a StreamWriter so we can set it again with Console.SetOut we are done. The byte sequences are send to the OutputStream and picked up by AnsiCon. | ||
let strWriter = l.AvalonLog.GetStreamWriter( LogColors.consoleOut) // Encoding.ASCII ?? | ||
Console.SetOut(strWriter) | ||
// A TextWriter that writes using a function. | ||
// To set Console.Out to a text writer get one via AvalonLog.GetTextWriter(red,green,blue) | ||
type LogStreamWriter(ms:MemoryStream,write,writeLine) = | ||
inherit StreamWriter(ms) | ||
override _.Encoding = Text.Encoding.Default // ( UTF-16 ) | ||
override _.Write (s:string) : unit = | ||
if s.Contains "\u001b" then write ("esc"+s) else write ("?"+s) //use specter ?? https://github.com/spectreconsole/spectre.console/discussions/573 | ||
//write (s) | ||
override _.WriteLine (s:string) : unit = // actually never used in F# printfn, but maybe buy other too using the console or error out , see https://github.com/dotnet/fsharp/issues/3712 | ||
if s.Contains "\u001b" then writeLine ("eSc"+s) else writeLine ("?"+s) | ||
//writeLine (s) | ||
override _.WriteLine () = writeLine ("") | ||
*) | ||
|
||
|
||
|