diff --git a/build/Build.cs b/build/Build.cs
index a2ad2e2..82d8096 100644
--- a/build/Build.cs
+++ b/build/Build.cs
@@ -56,7 +56,6 @@ partial class Build : NukeBuild
}
PackagesDirectory.CreateOrCleanDirectory();
- ////await this.UpdateVisualStudio();
await this.InstallDotNetSdk("3.1.x", "5.x.x", "6.x.x", "7.x.x");
});
diff --git a/src/LiveExample/LiveExample.csproj b/src/LiveExample/LiveExample.csproj
index 82384a3..4289849 100644
--- a/src/LiveExample/LiveExample.csproj
+++ b/src/LiveExample/LiveExample.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/src/LiveExample/Program.cs b/src/LiveExample/Program.cs
index aa60567..46f0b06 100644
--- a/src/LiveExample/Program.cs
+++ b/src/LiveExample/Program.cs
@@ -3,7 +3,6 @@
using System;
using System.Reactive.Linq;
-using Spectre.Console;
using Spectre.Console.Rx;
namespace Live;
@@ -24,7 +23,7 @@ public static void Main()
AnsiConsoleRx.Live(table, ld => ld.AutoClear(false).Overflow(VerticalOverflow.Ellipsis).Cropping(VerticalOverflowCropping.Top))
.ObserveOn(AnsiConsoleRx.Scheduler)
.Subscribe(ctx =>
- {
+
// Columns
ctx.Update(230, () => table.AddColumn("Release date"))
.Update(230, () => table.AddColumn("Title"))
@@ -76,9 +75,6 @@ public static void Main()
.Update(230, () => table.SimpleHeavyBorder())
// Caption
- .Update(400, () => table.Caption("[[ [blue]THE END[/] ]]"));
- });
-
- Console.ReadLine();
+ .Update(400, () => table.Caption("[[ [blue]THE END[/] ]]")));
}
}
diff --git a/src/LiveTableExample/LiveTableExample.csproj b/src/LiveTableExample/LiveTableExample.csproj
index 82384a3..4289849 100644
--- a/src/LiveTableExample/LiveTableExample.csproj
+++ b/src/LiveTableExample/LiveTableExample.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/src/LiveTableExample/Program.cs b/src/LiveTableExample/Program.cs
index 27cbf7b..d0b150c 100644
--- a/src/LiveTableExample/Program.cs
+++ b/src/LiveTableExample/Program.cs
@@ -3,8 +3,7 @@
using System;
using System.Linq;
-using System.Threading.Tasks;
-using Spectre.Console;
+using System.Reactive.Linq;
using Spectre.Console.Rx;
namespace LiveTable;
@@ -45,31 +44,31 @@ public static void Main(string[] args)
p.AutoClear(false)
.Overflow(VerticalOverflow.Ellipsis)
.Cropping(VerticalOverflowCropping.Bottom))
- .Subscribe(async ctx =>
+ .ObserveOn(AnsiConsoleRx.Scheduler)
+ .Do(_ =>
{
// Add some initial rows
foreach (var a in Enumerable.Range(0, NumberOfRows))
{
AddExchangeRateRow(table);
}
-
+ })
+ .CombineLatest(Observable.Interval(TimeSpan.FromMilliseconds(400)), (ctx, _) => ctx)
+ .Subscribe(ctx =>
+ {
// Continously update the table
- while (true)
+ // More rows than we want?
+ if (table.Rows.Count > NumberOfRows)
{
- // More rows than we want?
- if (table.Rows.Count > NumberOfRows)
- {
- // Remove the first one
- table.Rows.RemoveAt(0);
- }
+ // Remove the first one
+ table.Rows.RemoveAt(0);
+ }
- // Add a new row
- AddExchangeRateRow(table);
+ // Add a new row
+ AddExchangeRateRow(table);
- // Refresh and wait for a while
- ctx.Refresh();
- await Task.Delay(400);
- }
+ // Refresh and wait for a while
+ ctx.Refresh();
});
Console.ReadLine();
diff --git a/src/ProgressExample/Program.cs b/src/ProgressExample/Program.cs
index 8d482bd..194722e 100644
--- a/src/ProgressExample/Program.cs
+++ b/src/ProgressExample/Program.cs
@@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
-using System.Threading;
-using Spectre.Console;
using Spectre.Console.Rx;
namespace Progress;
@@ -23,7 +21,8 @@ public static void Main()
AnsiConsole.MarkupLine("[yellow]Initializing warp drive[/]...");
// Show progress
- AnsiConsoleRx.Progress(p => p.AutoClear(false)
+ AnsiConsoleRx.Progress(p =>
+ p.AutoClear(false)
.Columns(new ProgressColumn[]
{
new TaskDescriptionColumn(), // Task description
@@ -33,7 +32,7 @@ public static void Main()
new SpinnerColumn(), // Spinner
}))
.ObserveOn(AnsiConsoleRx.Scheduler)
- .Subscribe(ctx =>
+ .Subscribe(async ctx =>
{
var random = new Random(DateTime.Now.Millisecond);
@@ -41,64 +40,56 @@ public static void Main()
var tasks = CreateTasks(ctx, random);
var warpTask = ctx.AddTask("Going to warp", autoStart: false).IsIndeterminate();
- // Wait for all tasks (except the indeterminate one) to complete
- while (!ctx.IsFinished)
- {
- // Increment progress
- foreach (var (task, increment) in tasks)
+ await ctx.Schedule(
+ TimeSpan.FromMilliseconds(100),
+ () => ctx.IsFinished,
+ () =>
{
- task.Increment(random.NextDouble() * increment);
- }
-
- // Write some random things to the terminal
- if (random.NextDouble() < 0.1)
- {
- WriteLogMessage();
- }
-
- ctx.Refresh();
-
- // Simulate some delay
- Thread.Sleep(100);
- }
+ // Increment progress
+ foreach (var (task, increment) in tasks)
+ {
+ task.Increment(random.NextDouble() * increment);
+ }
+
+ // Write some random things to the terminal
+ if (random.NextDouble() < 0.1)
+ {
+ WriteLogMessage();
+ }
+ });
// Now start the "warp" task
- warpTask.StartTask();
- warpTask.IsIndeterminate(false);
- while (!ctx.IsFinished)
- {
- warpTask.Increment(12 * random.NextDouble());
-
- // Simulate some delay
- Thread.Sleep(100);
- }
+ warpTask.StartTask().IsIndeterminate(false);
+ await ctx.Schedule(
+ TimeSpan.FromMilliseconds(100),
+ () => warpTask.Increment(12 * random.NextDouble()));
// Done
- AnsiConsole.MarkupLine("[green]Done![/]");
+ await ctx.Schedule(_ => WriteLogMessage("[green]Done![/]"));
});
-
- Console.ReadLine();
}
- private static List<(ProgressTask Task, int Delay)> CreateTasks(ProgressContext progress, Random random)
+ private static List<(ProgressTask Task, int Delay)> CreateTasks(ProgressContext context, Random random)
{
var tasks = new List<(ProgressTask, int)>();
while (tasks.Count < 5)
{
if (DescriptionGenerator.TryGenerate(out var name))
{
- tasks.Add((progress.AddTask(name), random.Next(2, 10)));
+ tasks.Add((context.AddTask(name), random.Next(2, 10)));
}
}
return tasks;
}
- private static void WriteLogMessage()
- {
- AnsiConsole.MarkupLine(
+ private static void WriteLogMessage() => AnsiConsole.MarkupLine(
"[grey]LOG:[/] " +
DescriptionGenerator.Generate() +
"[grey]...[/]");
- }
+
+ private static void WriteLogMessage(string message) => AnsiConsole.MarkupLine(
+ "[grey]LOG:[/] " +
+ message +
+ "[grey]...[/]");
}
diff --git a/src/ProgressExample/ProgressExample.csproj b/src/ProgressExample/ProgressExample.csproj
index 0e87f93..73df831 100644
--- a/src/ProgressExample/ProgressExample.csproj
+++ b/src/ProgressExample/ProgressExample.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/src/ProgressThreadExample/Program.cs b/src/ProgressThreadExample/Program.cs
index d01b89f..27f9276 100644
--- a/src/ProgressThreadExample/Program.cs
+++ b/src/ProgressThreadExample/Program.cs
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
-using Spectre.Console;
using Spectre.Console.Rx;
namespace Progress;
@@ -33,28 +32,18 @@ public static void Main()
{
ctx.AddTask("Deleting Custom Formats").MaxValue(cfs.Count),
})
+ .ObserveOn(AnsiConsoleRx.Scheduler)
.Subscribe(
ctx =>
{
var rng = new Random();
cfs.ToObservable()
- .Select(x => Observable.FromAsync(async ct =>
- {
- await Task.Delay(TimeSpan.FromSeconds(rng.Next(1, 5)), ct);
- }))
+ .Select(_ => Observable.FromAsync(async ct => await Task.Delay(TimeSpan.FromSeconds(rng.Next(1, 5)), ct), AnsiConsoleRx.Scheduler))
.Merge(8)
- .Subscribe(_ =>
- {
- ctx.tasks[0].Increment(1); // Not thread safe; needs to invoke on the thread that subscribed; not sure if this is ObserveOn or SubscribeOn
- });
+ .ObserveOn(SpectreConsoleScheduler.Instance)
+ .Subscribe(_ => ctx.tasks[0].Increment(1));
},
- () =>
- {
- // Render a message when the sequence completes
- AnsiConsole.MarkupLine("[blue]Done![/]");
- });
-
- Console.ReadLine();
+ () => AnsiConsole.MarkupLine("[blue]Done![/]")); // Render a message when the sequence completes
}
}
diff --git a/src/ProgressThreadExample/ProgressThreadExample.csproj b/src/ProgressThreadExample/ProgressThreadExample.csproj
index 0e87f93..73df831 100644
--- a/src/ProgressThreadExample/ProgressThreadExample.csproj
+++ b/src/ProgressThreadExample/ProgressThreadExample.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/src/Shared/Shared.csproj b/src/Shared/Shared.csproj
deleted file mode 100644
index 3104dc0..0000000
--- a/src/Shared/Shared.csproj
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- net7.0
- enable
- False
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Spectre.Console.Rx.sln b/src/Spectre.Console.Rx.sln
index 5149e32..e276a89 100644
--- a/src/Spectre.Console.Rx.sln
+++ b/src/Spectre.Console.Rx.sln
@@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.Rx", "Spect
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiveExample", "LiveExample\LiveExample.csproj", "{3EBF3829-4483-48ED-AD1E-E057CC7DDFF0}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{725C299C-42CE-405F-85CC-6DEFEA8487B9}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProgressExample", "ProgressExample\ProgressExample.csproj", "{D3195DF3-668F-4BF0-9020-22C6649924EF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{E17E245C-D501-46B4-A804-A68241982088}"
@@ -27,8 +25,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {15A30A6D-9A94-4A7C-A74B-D7A9CB36C216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {15A30A6D-9A94-4A7C-A74B-D7A9CB36C216}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43DC5A6B-B066-4CCF-90A8-680432C139D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43DC5A6B-B066-4CCF-90A8-680432C139D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43DC5A6B-B066-4CCF-90A8-680432C139D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -37,10 +33,6 @@ Global
{3EBF3829-4483-48ED-AD1E-E057CC7DDFF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EBF3829-4483-48ED-AD1E-E057CC7DDFF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EBF3829-4483-48ED-AD1E-E057CC7DDFF0}.Release|Any CPU.Build.0 = Release|Any CPU
- {725C299C-42CE-405F-85CC-6DEFEA8487B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {725C299C-42CE-405F-85CC-6DEFEA8487B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {725C299C-42CE-405F-85CC-6DEFEA8487B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {725C299C-42CE-405F-85CC-6DEFEA8487B9}.Release|Any CPU.Build.0 = Release|Any CPU
{D3195DF3-668F-4BF0-9020-22C6649924EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3195DF3-668F-4BF0-9020-22C6649924EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3195DF3-668F-4BF0-9020-22C6649924EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -57,13 +49,14 @@ Global
{CB209C31-2CD2-4188-A088-18E68DF23788}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB209C31-2CD2-4188-A088-18E68DF23788}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB209C31-2CD2-4188-A088-18E68DF23788}.Release|Any CPU.Build.0 = Release|Any CPU
+ {15A30A6D-9A94-4A7C-A74B-D7A9CB36C216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {15A30A6D-9A94-4A7C-A74B-D7A9CB36C216}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3EBF3829-4483-48ED-AD1E-E057CC7DDFF0} = {E17E245C-D501-46B4-A804-A68241982088}
- {725C299C-42CE-405F-85CC-6DEFEA8487B9} = {E17E245C-D501-46B4-A804-A68241982088}
{D3195DF3-668F-4BF0-9020-22C6649924EF} = {E17E245C-D501-46B4-A804-A68241982088}
{9B8D02EB-C0CB-42B1-B44C-74471D83A8C2} = {E17E245C-D501-46B4-A804-A68241982088}
{51ACCE14-F44D-455B-A5E9-AEC71F7C6F61} = {E17E245C-D501-46B4-A804-A68241982088}
diff --git a/src/Spectre.Console.Rx/AnsiConsoleRx.cs b/src/Spectre.Console.Rx/AnsiConsoleRx.cs
index 90844d7..c76f3d7 100644
--- a/src/Spectre.Console.Rx/AnsiConsoleRx.cs
+++ b/src/Spectre.Console.Rx/AnsiConsoleRx.cs
@@ -1,10 +1,8 @@
// Copyright (c) Chris Pulman. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
-using Spectre.Console.Rendering;
namespace Spectre.Console.Rx;
@@ -22,7 +20,7 @@ public static class AnsiConsoleRx
///
/// The scheduler.
///
- public static IScheduler Scheduler { get; } = new SpectreConsoleScheduler();
+ public static ISpectreConsoleScheduler Scheduler => SpectreConsoleScheduler.Instance;
///
/// Creates a new instance.
@@ -32,30 +30,31 @@ public static class AnsiConsoleRx
/// A instance.
///
public static IObservable Progress(Func