Skip to content

Commit

Permalink
new threadsafeWriter and updated sample
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinfactory committed Oct 4, 2018
1 parent 59c3187 commit db3c994
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 279 deletions.
5 changes: 3 additions & 2 deletions Goblinfactory.ProgressBar/Goblinfactory.ProgressBar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>C# (dotnet standard) console progress bar with support for single or multithreaded progress updates.</Description>
<Version>0.1.0</Version>
<Version>0.3.0</Version>
<Copyright>Copyright Goblinfactory Ltd, 2018, all rights reserved.</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/goblinfactory/ProgressBar/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/goblinfactory/ProgressBar/</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/goblinfactory/ProgressBar/master/progress.png</PackageIconUrl>
<Title>Goblinfactory.ProgressBar</Title>
<PackageIconUrl>https://raw.githubusercontent.com/goblinfactory/progress-bar/master/progress.png</PackageIconUrl>
<RepositoryUrl>https://github.com/goblinfactory/ProgressBar/</RepositoryUrl>
<PackageReleaseNotes>C# (dotnet standard) console progress bar with support for single or multithreaded progress updates</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
12 changes: 6 additions & 6 deletions Goblinfactory.ProgressBar/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ProgressBar : IProgressBar
public string Line1 => _bar.Line1;
public string Line2 => _bar.Line2;

public ProgressBar(int max) : this(max, null,'#', PbStyle.SingleLine, new Writer()) { }
public ProgressBar(int max, int textWidth) : this(max, textWidth, '#', PbStyle.SingleLine, new Writer()) { }
public ProgressBar(int max, int textWidth, char character) : this(max, textWidth, character, PbStyle.SingleLine, new Writer()) { }
public ProgressBar(PbStyle style, int max) : this(max, null, '#', style, new Writer()) { }
public ProgressBar(PbStyle style, int max, int textWidth) : this(max, textWidth, '#', style, new Writer()) { }
public ProgressBar(PbStyle style, int max, int textWidth, char character) : this(max, textWidth, character, style, new Writer()) { }
public ProgressBar(int max) : this(max, null,'#', PbStyle.SingleLine, new ThreadsafeWriter()) { }
public ProgressBar(int max, int textWidth) : this(max, textWidth, '#', PbStyle.SingleLine, new ThreadsafeWriter()) { }
public ProgressBar(int max, int textWidth, char character) : this(max, textWidth, character, PbStyle.SingleLine, new ThreadsafeWriter()) { }
public ProgressBar(PbStyle style, int max) : this(max, null, '#', style, new ThreadsafeWriter()) { }
public ProgressBar(PbStyle style, int max, int textWidth) : this(max, textWidth, '#', style, new ThreadsafeWriter()) { }
public ProgressBar(PbStyle style, int max, int textWidth, char character) : this(max, textWidth, character, style, new ThreadsafeWriter()) { }

internal ProgressBar(IConsole console, int max) : this(max, null,'#', PbStyle.SingleLine, console) { }
internal ProgressBar(IConsole console, int max, int textWidth) : this(max, textWidth, '#', PbStyle.SingleLine, console) { }
Expand Down
10 changes: 5 additions & 5 deletions Goblinfactory.ProgressBar/ProgressBarSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public string Item
}
}

public ProgressBarSlim(int max) : this(max, '#', new Writer()) { }
public ProgressBarSlim(int max, int textWidth) : this(max, textWidth,'#', new Writer()) { }
public ProgressBarSlim(int max, int textWidth, char character) : this(max, textWidth, character, new Writer()) { }
public ProgressBarSlim(int max) : this(max, '#', new ThreadsafeWriter()) { }
public ProgressBarSlim(int max, int textWidth) : this(max, textWidth,'#', new ThreadsafeWriter()) { }
public ProgressBarSlim(int max, int textWidth, char character) : this(max, textWidth, character, new ThreadsafeWriter()) { }
public ProgressBarSlim(int max, IConsole console) : this(max, null, '#', console) { }
public ProgressBarSlim(int max, int textWidth, IConsole console) : this(max, textWidth, '#', console) { }

Expand All @@ -67,7 +67,7 @@ internal static int GetTextWidth(IConsole console, int? width)
{
return width.HasValue
? width.Value
: console.WindowWidth/4;
: console.Width/4;
}

public int Max
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Refresh(int current, string itemText)
try
{
float perc = (float) _current/(float) _max;
int barWidth = _console.WindowWidth - (TextWidth+8);
int barWidth = _console.Width - (TextWidth+8);
var bar = _current > 0
? new string(_character, (int) ((float) (barWidth)*perc)).PadRight(barWidth)
: new string(' ', barWidth);
Expand Down
6 changes: 3 additions & 3 deletions Goblinfactory.ProgressBar/ProgressBarTwoLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void Refresh(int current, string item)
try
{
float perc = Max > 0 ? (float) current/(float) _max : 0;
var bar = new string(_character, (int) ((float) (_console.WindowWidth - 30)*perc));
var bar = new string(_character, (int) ((float) (_console.Width - 30)*perc));
var line = string.Format(FORMAT, current, _max, (int) (perc*100));
var barWhitespace = _console.WindowWidth - (bar.Length + line.Length + 1);
var barWhitespace = _console.Width - (bar.Length + line.Length + 1);
_console.CursorTop = _y;
_console.CursorLeft = 0;
_console.ForegroundColor = _c;
Expand All @@ -92,7 +92,7 @@ public void Refresh(int current, string item)
_console.Write(bar);
_console.WriteLine(barWhitespace > 0 ? new String(' ', barWhitespace) : "");
_console.ForegroundColor = _c;
_line2 = itemText.PadRight(_console.WindowWidth - 2);
_line2 = itemText.PadRight(_console.Width - 2);
_console.WriteLine(_line2);
_line1 = $"{line} {bar}";
}
Expand Down
4 changes: 2 additions & 2 deletions Konsole/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface IConsole : IWrite
/// </summary>
int AbsoluteY { get; }

int WindowWidth { get; }
int WindowHeight { get; }
int Width { get; }
int Height { get; }
int CursorTop { get; set; }
int CursorLeft { get; set; }
Colors Colors { get; set; }
Expand Down
Loading

0 comments on commit db3c994

Please sign in to comment.