Skip to content

Commit

Permalink
Code Style previous PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Sep 24, 2019
1 parent 6bd61f2 commit 74d92b1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/Swan.Lite/Logging/FileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class FileLogger : ILogger
private readonly ManualResetEventSlim _doneEvent = new ManualResetEventSlim(true);
private readonly ConcurrentQueue<string> _logQueue = new ConcurrentQueue<string>();
private readonly ExclusiveTimer _timer;

private string _filePath;
private readonly string _filePath;

private bool _disposedValue; // To detect redundant calls

Expand Down
2 changes: 1 addition & 1 deletion src/Swan.Lite/Swan.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Swan.Lite</AssemblyName>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<Version>2.2.3</Version>
<Version>2.2.6</Version>
<Authors>Unosquare</Authors>
<PackageIconUrl>https://github.com/unosquare/swan/raw/master/swan-logo-32.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/unosquare/swan</PackageProjectUrl>
Expand Down
50 changes: 21 additions & 29 deletions src/Swan.Lite/Terminal.Output.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;

namespace Swan
{
Expand All @@ -9,22 +8,23 @@ namespace Swan
/// </summary>
public static partial class Terminal
{
#region Helper Methods

/// <summary>
/// Prints all characters in the current code page.
/// This is provided for debugging purposes only.
/// </summary>
[Obsolete("This method will be remove in future version")]
public static void PrintCurrentCodePage()
{
if (!IsConsolePresent) return;

lock (SyncLock)
{
Terminal.WriteLine($"Output Encoding: {OutputEncoding}");
for (char charValue = char.MinValue; charValue < 2000; charValue++)
WriteLine($"Output Encoding: {OutputEncoding}");

for (var charValue = char.MinValue; charValue < 2000; charValue++)
{
int value = (int)charValue;
var value = (int)charValue;

switch (charValue)
{
case '\b': // Backspace
Expand All @@ -35,30 +35,26 @@ public static void PrintCurrentCodePage()
break;
}

if (!(Char.IsLetterOrDigit(charValue) || Char.IsPunctuation(charValue) || Char.IsSymbol(charValue)))
if (!(char.IsLetterOrDigit(charValue) || char.IsPunctuation(charValue) || char.IsSymbol(charValue)))
{
continue;
}

Terminal.Write($"{value:000} {charValue} ");
Write($"{value:000} {charValue} ");

// 7 is a beep -- Console.Beep() also works
if (value == 7) Write(" ");

if ((value + 1) % 8 == 0)
{
Terminal.WriteLine();
WriteLine();
}
}

WriteLine();
}
}

#endregion

#region Write Methods

/// <summary>
/// Writes a character a number of times, optionally adding a new line at the end.
/// </summary>
Expand All @@ -71,13 +67,15 @@ public static void Write(char charCode, ConsoleColor? color = null, int count =
{
lock (SyncLock)
{
string text = new string(charCode, count);
if (newLine)
{
text += Environment.NewLine;
}
var buffer = OutputEncoding.GetBytes(text);
var context = new OutputContext
var text = new string(charCode, count);

if (newLine)
{
text += Environment.NewLine;
}

var buffer = OutputEncoding.GetBytes(text);
var context = new OutputContext
{
OutputColor = color ?? Settings.DefaultColor,
OutputText = OutputEncoding.GetChars(buffer),
Expand All @@ -97,7 +95,7 @@ public static void Write(char charCode, ConsoleColor? color = null, int count =
public static void Write(string text, ConsoleColor? color = null, TerminalWriters writerFlags = TerminalWriters.StandardOutput)
{
if (text == null) return;

lock (SyncLock)
{
var buffer = OutputEncoding.GetBytes(text);
Expand All @@ -112,15 +110,11 @@ public static void Write(string text, ConsoleColor? color = null, TerminalWriter
}
}

#endregion

#region WriteLine Methods

/// <summary>
/// Writes a New Line Sequence to the standard output.
/// </summary>
/// <param name="writerFlags">The writer flags.</param>
public static void WriteLine(TerminalWriters writerFlags = TerminalWriters.StandardOutput)
public static void WriteLine(TerminalWriters writerFlags = TerminalWriters.StandardOutput)
=> Write(Environment.NewLine, Settings.DefaultColor, writerFlags);

/// <summary>
Expand All @@ -130,7 +124,7 @@ public static void WriteLine(TerminalWriters writerFlags = TerminalWriters.Stand
/// <param name="text">The text.</param>
/// <param name="color">The color.</param>
/// <param name="writerFlags">The writer flags.</param>
public static void WriteLine(string text, ConsoleColor? color = null, TerminalWriters writerFlags = TerminalWriters.StandardOutput)
public static void WriteLine(string text, ConsoleColor? color = null, TerminalWriters writerFlags = TerminalWriters.StandardOutput)
=> Write($"{text ?? string.Empty}{Environment.NewLine}", color, writerFlags);

/// <summary>
Expand All @@ -146,7 +140,5 @@ public static void OverwriteLine(string text, ConsoleColor? color = null, Termin
Flush();
CursorLeft = 0;
}

#endregion
}
}
11 changes: 2 additions & 9 deletions src/Swan.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
using Formatters;
using Logging;
using Messaging;
using Net;
using Net.Dns;
using System;
using System.Collections.Generic;
using System.IO;
using Net;
using System.Linq;
using System.Threading.Tasks;
using System.Text;

public static partial class Program
{
Expand Down Expand Up @@ -167,12 +166,6 @@ private static async Task TestTerminalOutputs()
Terminal.OverwriteLine($"Current Progress: {(i + "%"),-10}");
}

if (Terminal.ReadKey("Press a key to output the current codepage. (X) will exit.").Key == ConsoleKey.X) return;
// Although .NET is by default Unicode, this explicit instruction causes Linux to print mostly garbage
// Terminal.OutputEncoding = Encoding.Unicode;
Terminal.WriteLine("CODEPAGE TEST", ConsoleColor.Blue);
Terminal.PrintCurrentCodePage();

if (Terminal.ReadKey("Press a key to test logging output. (X) will exit.").Key == ConsoleKey.X) return;
Terminal.WriteLine("OUTPUT LOGGING TEST", ConsoleColor.Blue);
"This is some error".Error(typeof(Program));
Expand Down Expand Up @@ -237,4 +230,4 @@ private static void TestCsvFormatters()
$"Elapsed: {Math.Round(elapsed.TotalMilliseconds, 3)} milliseconds".Trace();
}
}
}
}

0 comments on commit 74d92b1

Please sign in to comment.