https://github.com/daar/termstyle
Colorful and styled terminal output for Free Pascal
https://github.com/daar/termstyle
Last synced: 4 months ago
JSON representation
Colorful and styled terminal output for Free Pascal
- Host: GitHub
- URL: https://github.com/daar/termstyle
- Owner: daar
- License: mit
- Created: 2025-09-16T20:47:02.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2026-02-04T17:42:00.000Z (4 months ago)
- Last Synced: 2026-02-05T04:43:01.498Z (4 months ago)
- Language: Pascal
- Homepage:
- Size: 536 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TermStyle
**TermStyle** brings **colorful, styled output** to your CLI applications with the familiar **[Tailwind CSS](https://tailwindcss.com/) API**. It allows building a **beautiful and expressive terminal** with ease.
> TermStyle is inspired by [Termwind](https://github.com/nunomaduro/termwind).
## Installation
Install using [Nova](https://github.com/nova-packager/nova).
```bash
nova require daar/termstyle
```
## Usage
**TermStyle** accepts valid HTML and Tailwind formatting classes.
```pascal
uses
TermStyle;
writeln(render('
Important!'));
writeln(render('Green text on dark background'));
```
## Interactive Prompts
The `TermStyle.Prompts` unit provides beautiful, interactive command-line prompts.
```pascal
uses
TermStyle.Prompts;
```
### `text()`
Text input with placeholder, default value, and hint support.
```pascal
name := text(
'What is your name?',
'John Doe', // placeholder
'', // default value
'Enter your full name' // hint
);
```
### `suggest()`
Text input with autocomplete suggestions. Use TAB to complete, arrow keys to cycle suggestions.
```pascal
country := suggest(
'What country are you from?',
['Australia', 'Austria', 'Belgium', 'Brazil', 'Canada'],
'Start typing...'
);
```
### `password()`
Password input with hidden characters (displayed as asterisks).
```pascal
pwd := password(
'Enter your password',
'Min 8 characters',
'Your password will be encrypted'
);
```
### `confirm()`
Yes/No confirmation prompt.
```pascal
if confirm('Do you want to continue?', true) then
// proceed...
```
### `select()`
Single selection from a list of options. Navigate with arrow keys or TAB, confirm with Enter.
```pascal
choice := select(
'Choose a framework',
['Option A', 'Option B', 'Option C'],
0, // default selection index
'Use arrow keys to navigate'
);
```
### `multiselect()`
Multiple selection from a list. Navigate with arrow keys, toggle with Space, confirm with Enter.
```pascal
features := multiselect(
'Select features to enable',
['Auth', 'API', 'Queue', 'Scheduler'],
'Space to toggle, Enter to confirm',
true // required (at least one)
);
```
### `pause()`
Wait for user to press Enter.
```pascal
pause('Press ENTER to continue...');
```
### Informational Output
```pascal
intro('My CLI Application'); // Section header: ┌─ My CLI Application
outro('Goodbye!'); // Section footer: └─ Goodbye!
note('Additional information'); // Note line
alert('Important warning!'); // Yellow alert box
```
### Progress Indicators
```pascal
// Spinner
spin('Loading...');
Sleep(1000);
spinStop(true, 'Done!'); // true = success, false = failure
// Progress bar
bar := progress('Downloading', 100);
for i := 1 to 100 do
begin
Sleep(20);
bar.Advance(1);
end;
bar.Finish;
bar.Free;
```
### `table()`
Display data in a formatted table.
```pascal
table(
['Name', 'Email'],
[
['John', 'john@example.com'],
['Jane', 'jane@example.com']
]
);
```
## Message Helpers
TermStyle comes with ready-to-use helpers that print messages styled by their severity.
```pascal
error('Something went wrong!');
success('Operation completed!');
warning('Disk space is low');
info('Processing...');
banner('Welcome', 'text-white bg-blue-400 font-bold');
```
### `banner()`
The `banner()` function may be used to show a banner on screen with a custom HTML formatting.
```pascal
banner('TERMSTYLE DEMO CLI', 'text-white bg-blue-400 font-bold');
```
### Diff Output
TermStyle provides functions for rendering colored diff output, similar to `git diff`.
```pascal
// Render a complete unified diff
diff_file(UnifiedDiffString);
// Or build diff output manually
diff_header('diff --git a/file.pas b/file.pas');
diff_hunk('@@ -1,6 +1,6 @@');
diff_del(1, 'old line');
diff_add(1, 'new line');
diff_context(2, 'unchanged line');
```
**Available functions:**
| Function | Description |
|----------|-------------|
| `diff_header(FileName)` | Renders file header (gray background) |
| `diff_hunk(Range)` | Renders hunk header like `@@ -1,6 +1,6 @@` (cyan) |
| `diff_add(LineNum, Text)` | Renders added line (green background, `+` prefix) |
| `diff_del(LineNum, Text)` | Renders deleted line (red background, `-` prefix) |
| `diff_context(LineNum, Text)` | Renders context/unchanged line (gray text) |
| `diff_file(UnifiedDiff)` | Parses and renders a complete unified diff string |
**Example output:**
```
diff --git a/example.pas b/example.pas
@@ -1,3 +1,3 @@
1 program example;
2 - writeln('Hello');
2 + writeln('Hello, World!');
3 end.
```
## Classes Supported
All the classes supported use exactly the same logic that is available on [tailwindcss.com/docs](https://tailwindcss.com/docs).
* **[Background Color](https://tailwindcss.com/docs/background-color):** `bg-{color}-{shade}`.
* **[Text Color](https://tailwindcss.com/docs/text-color):** `text-{color}-{shade}`.
* **[Font Weight](https://tailwindcss.com/docs/font-weight#class-reference):** `font-bold`, `font-normal`.
* **[Font Style](https://tailwindcss.com/docs/font-style#italics):** `italic`.
* **[Text Decoration](https://tailwindcss.com/docs/text-decoration):** `underline`, `line-through`.
* **[Text Transform](https://tailwindcss.com/docs/text-transform):** `uppercase`, `lowercase`, `capitalize`, `snakecase`, `normal-case`.
* **[Margin](https://tailwindcss.com/docs/margin):** `m-{margin}`, `ml-{leftMargin}`, `mr-{rightMargin}`, `mt-{topMargin}`, `mb-{bottomMargin}`, `mx-{horizontalMargin}`, `my-{verticalMargin}`.
* **[Padding](https://tailwindcss.com/docs/padding):** `p-{padding}`, `pl-{leftPadding}`, `pr-{rightPadding}`, `pt-{topPadding}`, `pb-{bottomPadding}`, `px-{horizontalPadding}`, `py-{verticalPadding}`.
* **[List Style](https://tailwindcss.com/docs/list-style-type):** `list-disc`, `list-decimal`, `list-square`, `list-none`.
## HTML Elements Supported
All the elements have the capability to use the `class` attribute.
### `
`
The `
` element can be used as a block type element.
```pascal
render('
This is a div element.');
```
### `
`
The `
` element can be used as a paragraph.
```pascal
render('
This is a paragraph.
');
```
### ``
The `` element can be used as an inline text container.
```pascal
render(
'
' +
'This is a CLI app built with TermStyle.' +
'
'
);
```
### ``
**Default Styles**: `text-blue-500`
```pascal
render(
'
' +
'This is a CLI app built with TermStyle. Click here to open' +
'
'
);
```
### `` and ``
The ``and `` elements can be used to mark the text as **bold**.
**Default Styles**: `font-bold`
```pascal
render(
'
' +
'This is a CLI app built with TermStyle' +
'
'
);
```
### `` and ``
The `` and `` elements can be used to mark the text as *italic*.
**Default Styles**: `italic`
```pascal
render(
'
' +
'This is a CLI app built with TermStyle.' +
'
'
);
```
### ``
The `` element can be used to add a ~~line through~~ the text.
**Default Styles**: `line-through`
```pascal
render(
'
' +
'This is a CLI app built with TermStyle.' +
'
'
);
```
### ``
The `
` element can be used for an unordered list. It can only accept `- ` elements as childs, if there is another element provided it will throw an `InvalidChild` exception.
**Default Styles**: `list-disc`
```pascal
render(
'
' +
' - Item 1
' +
' - Item 2
' +
'
'
);
```
### `
`
The `
` element can be used for an ordered list. It can only accept `- ` elements as childs, if there is another element provided it will throw an `InvalidChild` exception.
**Default Styles**: `list-decimal`
```pascal
render(
'
' +
' - Item 1
' +
' - Item 2
' +
'
'
);
```
### `
- `
The `
- ` element can be used as a list item. It should only be used as a child of `
` and `` elements.
```pascal
render(
'
' +
' - Item 1
' +
'
'
);
```