generated from EluciusFTW/fsharp-spectre-console-template
/
Output.fs
117 lines (98 loc) · 4.46 KB
/
Output.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
namespace SpectreCoff.Cli.Commands
open Spectre.Console
open Spectre.Console.Cli
open SpectreCoff
type OutputSettings() =
inherit CommandSettings()
type OutputExample() =
inherit Command<OutputSettings>()
interface ICommandLimiter<OutputSettings>
override _.Execute(_context, _) =
pumpedLook <- { pumpedLook with Color = Some Color.Fuchsia }
edgyLook <- { edgyLook with Color = Some Color.BlueViolet }
calmLook <- { calmLook with Color = Some Color.Green }
NL |> toConsole
// There are several ways to print a single line.
// The generic way
MCD (Color.Red, [ Decoration.Underline ], "This is underline red") |> toConsole
MD ([ Decoration.Underline; Decoration.Dim ], "This is underline.") |> toConsole
MC (Color.Red, "This is red") |> toConsole
MC (Color(100uy, 200uy, 233uy), "This is RGB color") |> toConsole
NL |> toConsole
[V; C; E; P]
|> List.map (fun payload -> payload "Let's test text with illegal c[h]aractes as [well].")
|> Many
|> toConsole
// The convenience way
Calm "This utilizes the calm style. " |> toConsole
C "C is a short for Calm." |> toConsole
NL |> toConsole
Pumped "This let's you use an alternate style for the line." |> toConsole
P "P is a short for Pumped." |> toConsole
NL |> toConsole
Edgy "This let's you use yet another alternate style for the line." |> toConsole
E "E is a short for Edgy." |> toConsole
NL |> toConsole
// Using Vanilla, Raw and composite styles
Vanilla "This let's you pass through without providing any styling." |> toConsole
V "V is a short for Vanilla." |> toConsole
V "Vanilla will ignore any markup in the string - it is escaped." |> toConsole
V "If you want to provide a marked up a string, you have to use Raw (or short, R)." |> toConsole
NL |> toConsole
Raw $"""You can use {markupString (Some Color.Purple) [ Decoration.Bold ] "the markup"} function,""" |> toConsole
R $"""or {calm "the calm"}, {pumped "the pumped"} {edgy "or the edgy"} functions""" |> toConsole
R "to utilize the same styles as defined in the current theme." |> toConsole
R $"""As you can see, {pumped "Raw"} is especially useful for styles in {edgy "one line!"} (more on that below).""" |> toConsole
R $"""Beware however, that using the Raw payload you must [[escape illegal characters]] yourself.""" |> toConsole
NL |> toConsole
C "As hinted above, " |> toConsoleInline
P "there is also " |> toConsoleInline
E "another way " |> toConsoleInline
C "to change styles on the same line!" |> toConsole
NL |> toConsole
Many [ C "And ..."; P "yet"; E "another!"; C "(more on"; P "Many"; C "below)"] |> toConsole
// Multiple lines at once
[
"Sometimes you"
"Just want to"
"Write a decent text"
"Without being bothered by"
"Symbols, types and other things ... "
]
|> List.map Calm
|> Many
|> toConsole
// Compose different kinds of payloads
Many [
NL
C "If you want to list a few items you can use BulletItems: "
BulletItems [
C "listing"
P "several"
E "items"
]
rule "Links and Emojis"
Many [
C "You can easily render clickable links:"
Link "https://www.spectreconsole.net/markup"
]
Many [
C "Even with a dedicated display text:"
LinkWithLabel ("See documentation!", "https://www.spectreconsole.net/markup")
]
NL
Many [
C "You can use emojis by their string literals"
Emoji "alien_monster"
]
C $"""or use the constants provided by Spectre {Emoji.Known.Ghost} inline."""
NL
] |> toConsole
// Use extensions on the payload
let payload = Many [ NL; P "Printed"; E "using"; NL; C "... the Extension!"]
payload.toConsole
// or, if you need to map the payload to a marked up string or renderable
let asMarkedUpString = payload.toMarkedUpString
// Let's test the round-trip. You can use Raw to wrap it in an Outputpayload.
Raw asMarkedUpString |> toConsole
0