goblinfactory / konsole

Home of the simple console library consisting of ProgressBar, Window, Form, Draw & MockConsole (C# console progress bar with support for single or multithreaded progress updates) Window is a 100%-ish console compatible window, supporting all normal console writing to a windowed section of the screen, supporting scrolling and clipping of console output.
719 stars 62 forks source link

ProgressBar does not expose current #69

Open MihailsKuzmins opened 3 years ago

MihailsKuzmins commented 3 years ago

A class ProgressBar creates a ProgressBarTwoLine or ProgressBarSlim under the hood. Both of them have a field _current, however, for the time being only ProgressBarSlim exposes the current value. Could it be possible that the class ProgressBar exposes it as well? This property could be added a get-only property to IProgressBar. Does not look like a lot-to-do and it would be a handy property :)

goblinfactory commented 3 years ago

Easy enough to add to next relase. I'm sorry I can't bring out a quick fix for this now, ... will be working quite extensively on konsole V7 and will add it for sure when i do that.

I might update the standalone ProgressBar library first, that is a much smaller project : https://github.com/goblinfactory/progress-bar

watch that lib as well, depending what features you need. if you only need progress bar features, then that lib is much simpler.

MihailsKuzmins commented 3 years ago

@goblinfactory if you do not mind I could create a PR for it. Like I said it should not take too much time to do it

goblinfactory commented 3 years ago

Nice! If you submit a PR for https://github.com/goblinfactory/progress-bar I'll review it tomorrow night and create a new nuget.

That project is quite casual and simple.

Unfortunately konsole wont be able to take PR's until I get a bunch of stuff done according to dotnet foundation guidelines, contributor agreements etc and I won't have time to look at that until this weekend when I'm on leave.

goblinfactory commented 3 years ago

Hi @MihailsKuzmins I've merged your PR in https://github.com/goblinfactory/progress-bar and have published a new package to nuget, official progress bar 1.0.0 woot! https://www.nuget.org/packages/Goblinfactory.ProgressBar ping me if there's anything I need to tweak. cheers, Alan

goblinfactory commented 3 years ago

(give Nuget a few minutes to validate the package)

goblinfactory commented 3 years ago

@MihailsKuzmins I've created an alpha release for konsole with some progress bar improvements, including exposing .Current. The package is available for preview. 6.3.0-alpha please let me know if you find any bugs or have any issues and I'll look into that immediately.

https://www.nuget.org/packages/Goblinfactory.Konsole/6.3.0-alpha

I've also added two new progress bar objects,

ProgressCharBar is a (no text) progressbar that automatically fills the width of the parent window to 100%. CharBar is similar to ProgressCharBar but has a fixed width, and x and y co-ordinates. It's intended to be used for small status indicators of various usage.

Here is an example of CharBar

        [Test]
        public void show_percentage_correctly_25_perecent()
        {
            //begin-snippet: ProgressCharBar
            // 'OpenBox' opens to fill the entire parent window.
            // this test runs inside a mock console 22 chars wide, by 3 lines tall.
            // hence the 22x3 box shown in the buffer below.
            // -------------------------------------------
            var box = Window.OpenBox("test progress");

            // default color is green, default char is #
            var pb = new ProgressCharBar(box, max: 4); 
            pb.Refresh(1);
            _console.Buffer.Should().BeEquivalentTo(new[]
            {
                "┌─── test progress ──┐",
                "│#####               │",
                "└────────────────────┘"
            });
            //end-snippet: ProgressCharBar
        }

As soon as you confirm this package is good enough and I have done some further testing, i will release a non alpha 6.3 update, and close this issue.

MihailsKuzmins commented 3 years ago

Hey @goblinfactory (Alan) Thank you for your hard work :pray:

Instead of 6.3 I tested it with the latest version which was release a while ago (namely 7.3.). For my request it was perfect, Current is exposed in the readonly mode, so even bar.Refresh(bar.Curent + 1) was possible in a while loop while (bar.Current <= bar.Max).

I think that my issue has been solved, so you could close it as soon as the new release is published in NuGet. :crossed_fingers:

goblinfactory commented 3 years ago

Glad it works! Please note that version 7 has not been released yet, what you have fetched is an alpha release, so might be unstable. If you experience any issues let me know and i will try to address as quickly as possible.