Spectre.Console with F# style.
FsSpectre is a small library that extends Spectre.Console and allow to write beautiful console applications in a declarative and more F#-friendly way. It leverages Computation Expressions to create the widgets in a declarative style.
If you want to add this package to your project, execute the following command:
dotnet add package FsSpectreIf you want to build this library on your machine, execute the following commands:
git clone [email protected]:galassie/fs-spectre.git
cd fs-spectre
dotnet buildWith C# + Spectre.Console:
var table = new Table();
table.AddColumn("Foo");
table.AddColumn(new TableColumn("Bar").Centered());
table.AddRow("Baz", "[green]Qux[/]");
table.AddRow(new Markup("[blue]Corgi[/]"), new Panel("Waldo"));
AnsiConsole.Write(table);With F# + FsSpectre:
table {
column_text ""
column (tableColumn { header "Feature"; centerd })
row_text [| "Baz"; "[green]Qux[/]" |]
row [| markup { text "[blue]Corgi[/]" }; panel { content "Waldo" } |]
} |> AnsiConsole.WriteWith C# + Spectre.Console:
AnsiConsole.Write(new BarChart()
.Width(60)
.Label("[green bold underline]Number of fruits[/]")
.CenterLabel()
.AddItem("Apple", 12, Color.Yellow)
.AddItem("Orange", 54, Color.Green)
.AddItem("Banana", 33, Color.Red));With F# + FsSpectre:
barChart {
width 60
label "[green bold underline]Number of fruits[/]"
center_label
item "Apple" 12 Color.Yellow
item "Oranges" 54 Color.Green
item "Bananas" 33 Color.Red
} |> AnsiConsole.WriteTo see an example, execute the Showcase.fsx with the following command (you need to build the library first):
dotnet fsi Showcase.fsxIf you don't like this style of using Spectre.Console with Computation Expressions, check out these amazing projects:
Code contributions are more than welcome! 😻
Please commit any pull requests against the main branch.
If you find any issue, please report it!
This project is licensed under The MIT License (MIT).
Author: Enrico Galassi