|
8 | 8 | // Get a terminal instance |
9 | 9 | ITerminal terminal = TimeWarpTerminal.Default; |
10 | 10 |
|
11 | | -terminal.WriteLine(); |
12 | | -terminal.WriteLine("OSC 8 Hyperlink Demo".Cyan().Bold()); |
13 | | -terminal.WriteLine("Demonstrates clickable hyperlinks in supported terminals"); |
14 | | -terminal.WriteLine(); |
15 | | - |
16 | | -// Check terminal support |
17 | | -terminal.WriteLine($"Terminal hyperlink support: {(terminal.SupportsHyperlinks ? "✓ Yes".Green() : "✗ No".Yellow())}"); |
18 | | -terminal.WriteLine(); |
| 11 | +terminal |
| 12 | + .WriteLine() |
| 13 | + .WriteLine("OSC 8 Hyperlink Demo".Cyan().Bold()) |
| 14 | + .WriteLine("Demonstrates clickable hyperlinks in supported terminals") |
| 15 | + .WriteLine() |
| 16 | + .WriteLine($"Terminal hyperlink support: {(terminal.SupportsHyperlinks ? "✓ Yes".Green() : "✗ No".Yellow())}") |
| 17 | + .WriteLine(); |
19 | 18 |
|
20 | 19 | // 1. Simple hyperlink using string extension |
21 | | -terminal.WriteLine("1. String extension - Link():"); |
22 | | -terminal.WriteLine($" Visit {"Ardalis.com".Link("https://ardalis.com")}"); |
23 | | -terminal.WriteLine(); |
| 20 | +terminal |
| 21 | + .WriteLine("1. String extension - Link():") |
| 22 | + .WriteLine($" Visit {"Ardalis.com".Link("https://ardalis.com")}") |
| 23 | + .WriteLine(); |
24 | 24 |
|
25 | 25 | // 2. Terminal extension methods |
26 | | -terminal.WriteLine("2. Terminal extension - WriteLink():"); |
27 | | -terminal.Write(" Check out: "); |
28 | | -terminal.WriteLink("https://github.com", "GitHub"); |
29 | | -terminal.WriteLine(); |
30 | | -terminal.WriteLine(); |
| 26 | +terminal |
| 27 | + .WriteLine("2. Terminal extension - WriteLink():") |
| 28 | + .Write(" Check out: ") |
| 29 | + .WriteLink("https://github.com", "GitHub") |
| 30 | + .WriteLine() |
| 31 | + .WriteLine(); |
31 | 32 |
|
32 | 33 | // 3. WriteLinkLine with just URL (URL as display text) |
33 | | -terminal.WriteLine("3. URL as display text:"); |
34 | | -terminal.Write(" "); |
35 | | -terminal.WriteLinkLine("https://docs.microsoft.com/dotnet"); |
36 | | -terminal.WriteLine(); |
| 34 | +terminal |
| 35 | + .WriteLine("3. URL as display text:") |
| 36 | + .Write(" ") |
| 37 | + .WriteLinkLine("https://docs.microsoft.com/dotnet") |
| 38 | + .WriteLine(); |
37 | 39 |
|
38 | 40 | // 4. Chaining with color extensions |
39 | | -terminal.WriteLine("4. Hyperlinks with styling:"); |
40 | | -terminal.WriteLine($" {"Download here".Link("https://example.com/download").Blue().Underline()}"); |
41 | | -terminal.WriteLine($" {"Read the docs".Link("https://docs.example.com").Cyan().Bold()}"); |
42 | | -terminal.WriteLine($" {"Report a bug".Link("https://github.com/issues").Yellow()}"); |
43 | | -terminal.WriteLine(); |
| 41 | +terminal |
| 42 | + .WriteLine("4. Hyperlinks with styling:") |
| 43 | + .WriteLine($" {"Download here".Link("https://example.com/download").Blue().Underline()}") |
| 44 | + .WriteLine($" {"Read the docs".Link("https://docs.example.com").Cyan().Bold()}") |
| 45 | + .WriteLine($" {"Report a bug".Link("https://github.com/issues").Yellow()}") |
| 46 | + .WriteLine(); |
44 | 47 |
|
45 | 48 | // 5. Multiple links in one line |
46 | | -terminal.WriteLine("5. Multiple links in one line:"); |
47 | | -terminal.WriteLine($" {"Home".Link("https://example.com")} | {"About".Link("https://example.com/about")} | {"Contact".Link("https://example.com/contact")}"); |
48 | | -terminal.WriteLine(); |
| 49 | +terminal |
| 50 | + .WriteLine("5. Multiple links in one line:") |
| 51 | + .WriteLine($" {"Home".Link("https://example.com")} | {"About".Link("https://example.com/about")} | {"Contact".Link("https://example.com/contact")}") |
| 52 | + .WriteLine(); |
49 | 53 |
|
50 | 54 | // 6. Links in formatted text |
51 | | -terminal.WriteLine("6. Links in formatted output:"); |
52 | | -terminal.WriteLine($" For more information, see the {"documentation".Link("https://docs.example.com").Cyan()}"); |
53 | | -terminal.WriteLine($" or visit our {"community forum".Link("https://forum.example.com").Green()}."); |
54 | | -terminal.WriteLine(); |
| 55 | +terminal |
| 56 | + .WriteLine("6. Links in formatted output:") |
| 57 | + .WriteLine($" For more information, see the {"documentation".Link("https://docs.example.com").Cyan()}") |
| 58 | + .WriteLine($" or visit our {"community forum".Link("https://forum.example.com").Green()}.") |
| 59 | + .WriteLine(); |
55 | 60 |
|
56 | 61 | // 7. Practical example - CLI help with links |
57 | | -terminal.WriteLine("7. Practical example - Help text with links:"); |
58 | | -terminal.WriteLine(); |
59 | | -terminal.WritePanel(panel => panel |
60 | | - .Header("TimeWarp.Nuru".Cyan().Bold()) |
| 62 | +terminal |
| 63 | + .WriteLine("7. Practical example - Help text with links:") |
| 64 | + .WriteLine() |
| 65 | + .WritePanel(panel => panel |
| 66 | + .Header("TimeWarp.Terminal".Cyan().Bold()) |
61 | 67 | .Content( |
62 | | - "A fluent CLI framework for .NET 10\n\n" + |
63 | | - $"Documentation: {"https://timewarp.dev/nuru".Link("https://timewarp.dev/nuru").Cyan()}\n" + |
64 | | - $"Source: {"GitHub".Link("https://github.com/TimeWarpEngineering/timewarp-nuru").Cyan()}\n" + |
65 | | - $"Issues: {"Report bugs".Link("https://github.com/TimeWarpEngineering/timewarp-nuru/issues").Yellow()}") |
| 68 | + "Terminal abstractions and widgets for .NET 10\n\n" + |
| 69 | + $"Documentation: {"https://timewarp.dev/terminal".Link("https://timewarp.dev/terminal").Cyan()}\n" + |
| 70 | + $"Source: {"GitHub".Link("https://github.com/TimeWarpEngineering/timewarp-terminal").Cyan()}\n" + |
| 71 | + $"Issues: {"Report bugs".Link("https://github.com/TimeWarpEngineering/timewarp-terminal/issues").Yellow()}") |
66 | 72 | .Border(BorderStyle.Rounded) |
67 | 73 | .BorderColor(AnsiColors.Cyan) |
68 | | - .Padding(2, 1)); |
69 | | -terminal.WriteLine(); |
| 74 | + .Padding(2, 1)) |
| 75 | + .WriteLine(); |
70 | 76 |
|
71 | 77 | // 8. Conditional hyperlinks |
72 | 78 | terminal.WriteLine("8. Graceful degradation:"); |
|
76 | 82 | } |
77 | 83 | else |
78 | 84 | { |
79 | | - terminal.WriteLine(" Your terminal doesn't support OSC 8 hyperlinks."); |
80 | | - terminal.WriteLine(" The text still displays, but won't be clickable."); |
81 | | - terminal.WriteLine(" Supported terminals: Windows Terminal, iTerm2, VS Code, Hyper, Konsole, GNOME Terminal 3.26+"); |
| 85 | + terminal |
| 86 | + .WriteLine(" Your terminal doesn't support OSC 8 hyperlinks.") |
| 87 | + .WriteLine(" The text still displays, but won't be clickable.") |
| 88 | + .WriteLine(" Supported terminals: Windows Terminal, iTerm2, VS Code, Hyper, Konsole, GNOME Terminal 3.26+"); |
82 | 89 | } |
83 | | -terminal.WriteLine(); |
84 | 90 |
|
85 | | -// 9. Technical details |
86 | | -terminal.WriteLine("9. OSC 8 escape sequence format:"); |
87 | | -terminal.WriteLine(" \\e]8;;URL\\e\\\\DISPLAY_TEXT\\e]8;;\\e\\\\".Gray()); |
88 | 91 | terminal.WriteLine(); |
89 | 92 |
|
90 | | -terminal.WriteLine("Demo complete! Try running this in different terminals to see hyperlink support.".Gray()); |
91 | | -terminal.WriteLine(); |
| 93 | +// 9. Technical details |
| 94 | +terminal |
| 95 | + .WriteLine("9. OSC 8 escape sequence format:") |
| 96 | + .WriteLine(" \\e]8;;URL\\e\\\\DISPLAY_TEXT\\e]8;;\\e\\\\".Gray()) |
| 97 | + .WriteLine() |
| 98 | + .WriteLine("Demo complete! Try running this in different terminals to see hyperlink support.".Gray()) |
| 99 | + .WriteLine(); |
92 | 100 |
|
93 | 101 | return 0; |
0 commit comments