Skip to content

Instantly share code, notes, and snippets.

View patriksvensson's full-sized avatar

Patrik Svensson patriksvensson

View GitHub Profile
@patriksvensson
patriksvensson / DownloadedColumn.cs
Created January 12, 2021 03:44
A progress column for Spectre.Console that shows download progress
/// <summary>
/// A column showing download progress.
/// </summary>
public sealed class DownloadedColumn : ProgressColumn
{
private static readonly string[] _suffixes = new[] { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
private static readonly int _base = 1024;
/// <summary>
/// Gets or sets the <see cref="CultureInfo"/> to use.
@patriksvensson
patriksvensson / Spectre.Console.xml
Created July 4, 2022 10:13
Spectre.Console SBOM
<?xml version="1.0" encoding="utf-8"?>
<bom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://cyclonedx.org/schema/bom/1.4">
<metadata>
<tools>
<tool>
<vendor>Spectre Systems AB</vendor>
<name>Hades CLI</name>
<version>1.0.0.0</version>
</tool>
</tools>
@patriksvensson
patriksvensson / Program.cs
Created May 29, 2023 18:46
How to create a Spectre.Console console that doesn't use Console.Out and similar
using Spectre.Console;
using System.Text;
// Create the output
var output = new StringWriter();
// Create the console
var console = AnsiConsole.Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.Yes,
@patriksvensson
patriksvensson / Program.cs
Created May 29, 2023 19:16
Implementation of a IAnsiConsole that writes to a StringBuffer
using Spectre.Console;
using Spectre.Console.Rendering;
using System.Text;
namespace SpectreVirtual;
public static class Program
{
public static void Main(string[] args)
{
@patriksvensson
patriksvensson / TypeWriter.cs
Last active August 31, 2024 18:53
Spectre.Console typewriter
using Spectre.Console;
using Spectre.Console.Rendering;
var renderable = new Markup("[yellow]H[/]ello [blue]W[/]orld");
foreach (var segment in SplitSegments(renderable))
{
AnsiConsole.Write(new SegmentRenderable(segment));
Thread.Sleep(Random.Shared.Next(100, 500));
}