Skip to content

Commit

Permalink
make license identifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
goswinr committed Nov 18, 2024
1 parent 237d962 commit b1851e7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 85 deletions.
7 changes: 2 additions & 5 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
MIT License

AvalonLog Copyright (c) 2021 Goswin Rothenthal
The MIT License (MIT)

AvalonEditB Copyright (c) 2021 Goswin Rothenthal

AvalonEdit Copyright (c) AvalonEdit Contributors
Copyright (c) 2021 Goswin Rothenthal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
57 changes: 0 additions & 57 deletions Src/AvalonLog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,6 @@ 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,writeLine) =
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 ("")
*)




/// <summary>A ReadOnly text AvalonEdit Editor that provides colored appending via printfn like functions. </summary>
/// <remarks>Use the hidden member AvalonEdit if you need to access the underlying TextEditor class from AvalonEdit for styling.
/// Don't append or change the AvalonEdit.Text property directly. This will mess up the coloring.
Expand Down
39 changes: 16 additions & 23 deletions Src/AvalonLog.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<TargetFrameworks>net472;net7.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion>

<NeutralLanguage>en</NeutralLanguage>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <!--to only have the english resources-->
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <!--to only have the english resources-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<RootNamespace>AvalonLog</RootNamespace>
Expand All @@ -16,28 +15,23 @@
<Title>AvalonLog</Title>
<Product>AvalonLog</Product>
<PackageId>AvalonLog</PackageId>

<!-- <Version>0.16.0</Version> done by Ionide.KeepAChangelog.Tasks
<AssemblyVersion>0.16.0</AssemblyVersion>
<FileVersion>0.16.0</FileVersion>
<PackageReleaseNotes></PackageReleaseNotes> -->

<Authors>GoswinR</Authors>
<Copyright>Goswin Rothenthal 2021</Copyright>
<PackageDescription>A fast and thread-safe WPF text viewer for colored text. Including F# printf formatting. Based on AvalonEdit</PackageDescription>
<Description>A fast and thread-safe WPF text viewer for colored text. Including F# printf formatting. Based on AvalonEdit</Description>

<!-- <WarningLevel>5</WarningLevel> -->
<!-- WarningLevel 3 is default , see https://github.com/dsyme/fsharp-presentations/blob/master/design-notes/off-by-default-warnings.md -->
<OtherFlags>$(OtherFlags)--warnon:3390</OtherFlags> <!-- warnon:3390 is to verify xml docstrings https://devblogs.microsoft.com/dotnet/announcing-f-5/#improved-compiler-analysis-for-library-authors -->
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags> <!-- 1182: warn on unused variables -->

<!-- <WarningLevel>5</WarningLevel> --> <!-- WarningLevel 3 is default , see https://github.com/dsyme/fsharp-presentations/blob/master/design-notes/off-by-default-warnings.md -->
<OtherFlags>$(OtherFlags)--warnon:3390</OtherFlags><!-- warnon:3390 is to verify xml docstrings https://devblogs.microsoft.com/dotnet/announcing-f-5/#improved-compiler-analysis-for-library-authors -->
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags><!-- 1182: warn on unused variables -->
<Configuration>Release</Configuration>
</PropertyGroup>

<PropertyGroup>
<PackageTags>WPF Text Console F# AvalonEdit</PackageTags>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<!-- <SymbolPackageFormat>snupkg</SymbolPackageFormat> -->
Expand All @@ -49,37 +43,36 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<RepositoryUrl>https://github.com/goswinr/AvalonLog</RepositoryUrl>
<FsDocsLicenseLink>https://github.com/goswinr/AvalonLog/blob/main//LICENSE.md</FsDocsLicenseLink>
<FsDocsLicenseLink>https://github.com/goswinr/AvalonLog/blob/main/LICENSE.md</FsDocsLicenseLink>
<FsDocsReleaseNotesLink>https://github.com/goswinr/AvalonLog/blob/main/CHANGELOG.md</FsDocsReleaseNotesLink>
<PackageProjectUrl>https://goswinr.github.io/AvalonLog</PackageProjectUrl>

<FsDocsFaviconSource>img/favicon.ico</FsDocsFaviconSource>
<FsDocsFaviconSource>img/favicon.ico</FsDocsFaviconSource> <!-- https://fsprojects.github.io/FSharp.Formatting/styling.html#Customizing-via-Styling-Parameters -->
<FsDocsWarnOnMissingDocs>true</FsDocsWarnOnMissingDocs>

<ChangelogFile>../CHANGELOG.md</ChangelogFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AvalonEditB" Version="2.4.0" />

<!-- <PackageReference Update="FSharp.Core" Version="6.0.7" /> --> <!-- default lower version-->
<PackageReference Update="FSharp.Core" Version="9.0.100" /> <!-- needs to be aligned with Fesh.Revit -->

<PackageReference Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" PrivateAssets="all" />
<!-- <PackageReference Update="FSharp.Core" Version="6.0.7" /> -->
<!-- default lower version-->
<PackageReference Update="FSharp.Core" Version="9.0.100" />
<!-- needs to be aligned with Fesh.Revit -->
<PackageReference Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<!-- https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets -->
</ItemGroup>

<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="" />
<None Include="../Docs/img/logo128.png" Pack="true" PackagePath="" /> <!--PackagePath = "" makes the file available to nuget pack tool-->

<None Include="../Docs/img/logo128.png" Pack="true" PackagePath="" />
<!--PackagePath = "" makes the file available to nuget pack tool-->
<Compile Include="Sync.fs" />
<Compile Include="Brush.fs" />
<Compile Include="Util.fs" />
<Compile Include="TextColor.fs" />
<Compile Include="SelectedTextHighlighter.fs" />
<Compile Include="LogTextWriter.fs" />
<Compile Include="AvalonLog.fs" />
</ItemGroup>
</Project>
</Project>
70 changes: 70 additions & 0 deletions Src/LogTextWriter.fs
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 ("")
*)



0 comments on commit b1851e7

Please sign in to comment.