Comments (5)
Everything written to the console using an IAnsiConsole will already automatically be put above the progress.
from spectre.console.
Hi @patriksvensson, thanks for the reply. That's not exactly what I'm trying to achieve 🙂 I need something like this:
|= Reticulating splines ---------------------------------------- 63% 00:06:181 -
52438428
1870133191
1511040860
494825954
1900287500
1576363183
934959048
1910108725
1465638547
1366240317
|= Folding space ---------------------------------------- 21% 00:06:179 -
52438428
1870133191
1511040860
494825954
1900287500
1576363183
934959048
1910108725
1465638547
1366240317
This is useful to have output of a task near (in this case below) the corresponding progress bar to allow the user to quickly determine which output belongs to which concurrently running task.
Utilizing the new RenderHook
property, I managed to create a sample application that demonstrates the desired behavior. It's just hacked together, so please don't take too close of a look at the code style. The rows
output is shared for both tasks in this example which of course should not be the case in production.
internal static class Program
{
private static async Task Main()
{
var ri = 0;
var rows = Enumerable.Repeat<IRenderable>(new Text(""), 11).ToArray();
var progress = AnsiConsole.Progress()
.AutoRefresh(true)
.AutoClear(false)
.HideCompleted(false)
.Columns(
new TaskDescriptionColumn(),
new ProgressBarColumn(),
new PercentageColumn(),
new ElapsedTimeMilliColumn(),
new SpinnerColumn()
);
progress.RefreshRate = TimeSpan.FromMilliseconds(50);
progress.RenderHook = RenderHook;
IRenderable RenderHook(IRenderable renderable, IReadOnlyList<ProgressTask> tasks)
{
if (renderable is not Grid layout)
{
return renderable;
}
if (layout.Rows[0][0] is not Grid grid)
{
return renderable;
}
var result = new List<IRenderable>();
var i = 0;
foreach (var row in grid.Rows)
{
var g = new Grid();
foreach (var column in grid.Columns)
{
g.AddColumn(column);
}
g.AddRow([.. row]);
result.Add(g);
if (ri != 0 && !tasks[i].IsFinished)
{
result.Add(new Rows(rows[..(ri + 1)]));
}
++i;
}
var l = new Grid { Expand = true };
l.AddColumn();
l.AddRow(new Rows(result));
return l;
}
AnsiConsole.Clear();
AnsiConsole.MarkupLine("[blue]Elasticsearch.NET[/] Client Generator");
AnsiConsole.WriteLine();
progress
.Start(ctx =>
{
// Define tasks
var task1 = ctx.AddTask("[green]|= Reticulating splines[/]");
var task2 = ctx.AddTask("[green]|= Folding space[/]");
while (!ctx.IsFinished)
{
// Simulate some work
Task.Delay(50).Wait();
// Increment
task1.Increment(1.5);
task2.Increment(0.5);
if (ri == 10)
{
for (var i = 1; i < 10; ++i)
{
rows[i - 1] = rows[i];
}
ri = 9;
}
rows[ri++] = new Text($"{new Random((int)DateTime.Now.Ticks).Next()}");
}
ctx.Refresh();
});
// Fixme: Empty lines between the last progress bar and "test"
AnsiConsole.WriteLine("test");
}
}
from spectre.console.
I would as well offer to create a PR, if this functionality is something you would consider adding 🙂
from spectre.console.
Since this is a very niche thing, and nothing that we're really planning the progress bars to support, I think this would make an excellent addition as a external Spectre.Console extension.
from spectre.console.
Hi @patriksvensson, no problem. This will however result in a lot of duplicate code I'm afraid.
Closing this feature request as not planned.
from spectre.console.
Related Issues (20)
- Sixlabors ImageSharp 3.X?
- Add interactive input fields HOT 1
- Built-in parameter `--version` conflicts with existing one HOT 9
- `ExplainCommand+Settings` ctor fails `ServiceProvider.ValidateService` HOT 1
- Bad rendering for table live display / hidden table headers / no border and forced refresh
- Search doesn't work properly in selection prompts HOT 1
- Add paging function to selection prompt
- Fill entire background with custom color
- Unable to redirect output to file HOT 1
- More control over output - padding HOT 2
- Allow for a custom search filtering function for the SelectionPrompt
- Allow for multiple matching search result items with the SelectionPrompt
- Add '-?' as an additional alias for '-h' and '--help', just like 'dotnet -?' HOT 4
- Detecting and handling unicode support HOT 1
- Add public API to display help manually by user code HOT 1
- ValidationResult.Error should accept/support markup string when returing from CommandSettings.Validate method. HOT 1
- Can't find how to render panel to whole screen HOT 2
- Request: ability to display part of table rows
- Display error. HOT 1
- Selection Prompt on Grid
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spectre.console.