Skip to content

Commit 317fdd1

Browse files
committed
README: add a note on structured terminal sequence generation
Indicate the secondary value of the library as an abstraction over escape sequences for terminal applications. Even without the high performance rendering, the library is useful to provide semantic control sequence generation.
1 parent 945085c commit 317fdd1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ let style = VTStyle(foreground: .rgb(red: 255, green: 100, blue: 50),
8282
buffer.write("Styled text", at: position, style: style)
8383
```
8484

85+
### Structured Terminal Control Sequences
86+
87+
Beyond high-level UI rendering, VirtualTerminal provides a structured, type-safe API for formulating terminal escape sequences. Rather than hardcoding string literals like `"\033[31;1m"`, you express terminal commands using semantic Swift types.
88+
89+
The `ControlSequence` enum covers ISO 6429/ECMA-48 compliant terminal operations:
90+
91+
```swift
92+
import VirtualTerminal
93+
94+
// Type-safe cursor positioning and styling
95+
await terminal <<< .CursorPosition(10, 20)
96+
await terminal <<< .SelectGraphicRendition([.bold, .foreground(.red)])
97+
await terminal <<< "Important text"
98+
await terminal <<< .SelectGraphicRendition([.reset])
99+
100+
// Structured screen manipulation
101+
await terminal <<< .EraseDisplay(.EntireDisplay)
102+
await terminal <<< .SetMode([.DEC(.UseAlternateScreenBuffer)])
103+
```
104+
105+
This approach offers:
106+
- **Semantic clarity**: Express intent with Swift types, not escape code memorization
107+
- **Compile-time validation**: Prevents malformed sequences and parameter errors
108+
- **Encoding abstraction**: Handles 7-bit vs 8-bit encoding automatically
109+
- **Composability**: Chain operations with fluent syntax using the `<<<` operator
110+
111+
The library generates correct ANSI/VT100 escape sequences from these structured commands, making it both a UI toolkit and a robust terminal control sequence generator.
112+
85113
## Installation
86114

87115
Add to your `Package.swift`:

0 commit comments

Comments
 (0)