Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey committed Jun 24, 2024
0 parents commit 893399e
Show file tree
Hide file tree
Showing 51 changed files with 7,859 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
# Post-submit.
push:
branches: [ main ]

# Pre-submit.
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1
- uses: dart-lang/setup-dart@v1.6.4
- run: dart pub get
- run: dart format --output none --set-exit-if-changed .
- run: dart analyze
- run: dart run tool/coverage.dart
- name: Upload coverage
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info
- run: dart run tool/dartdoc.dart
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/api
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dart_tool/
coverage/
doc/api/

pubspec.lock
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dart-code.dart-code"
]
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Change Log

## 0.1.0

🎉 Initial release 🎉
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Matan Lurey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Mansion

A stately library for crafting and deciphering ANSI escape codes.

[![CI](https://github.com/matanlurey/mansion/actions/workflows/ci.yaml/badge.svg)](https://github.com/matanlurey/mansion/actions/workflows/ci.yaml)
[![Coverage Status](https://coveralls.io/repos/github/matanlurey/mansion/badge.svg?branch=main)](https://coveralls.io/github/matanlurey/mansion?branch=main)
[![Pub Package](https://img.shields.io/pub/v/mansion.svg)](https://pub.dev/packages/mansion)
[![Dartdoc reference](https://img.shields.io/badge/dartdoc-reference-blue.svg)](https://pub.dev/documentation/mansion/latest/)

![Demo](https://github.com/asciinema/agg/assets/168174/6832d773-22f9-47b9-a83c-0e6f260da849)

Styling text is ~1-line with lots of possibilities:

```dart
print('Hello World'.style(Style.foreground(Color.red), Style.bold));
```

When you're ready, graduate to a full-featured package for more control:

```dart
stdout.writeAnsiAll([
// Sets the cursor position to the top-left corner.
CursorPosition.reset,
// Clear the screen.
Clear.all,
// Set a bunch of styles.
SetStyles(
Style.bold,
Style.underline,
Style.italic,
Style.foreground(Color.red),
Style.background(Color.green),
),
// Print some text.
Print('Hello, World!'),
// Reset all styles.
SetStyles.reset,
// Move the cursor to the next line.
AsciiControl.lineFeed,
]);
```

Includes a full-featured ANSI escape _decoder_ for writing terminal emulators!

## Features

- Cross-platform support for most popular ANSI escape codes.
- Fully tested and documented with examples and explanations.
- Walkthroughs for common use-cases and best practices.
- Intuitive API using the latest Dart features.
- Practically _zero_ dependencies (only `meta` for annotations).

Importantly, `mansion` is _not_ a general purpose terminal library; it does not
provide terminal emulation, any real input handling other than event code
parsing, anything to do with FFI or native code, or any other terminal-related
functionality.

Build on top of `mansion` to create your own terminal libraries, or use it to
style text in your command-line applications.

## Contributing

To run the tests, run:

```shell
dart test
```

To check code coverage locally, run:

```shell
dart tool/coverage.dart
```

To preview `dartdoc` output locally, run:

```shell
dart tool/dartdoc.dart
```
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Format: https://dart.dev/tools/analysis#the-analysis-options-file.
include: package:oath/strict.yaml
67 changes: 67 additions & 0 deletions benchmark/new_uint8_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'dart:io' as io;
import 'dart:typed_data';

import 'package:benchmark_harness/benchmark_harness.dart';

/// Benchmark for creating a [Uint8List] from a list of bytes.
///
/// Shows that [Uint8List.new] is ~10x faster than [Uint8List.fromList].
void main() {
_Uint8ListFromList().report();
_Uint8ListWithLength().report();
}

final class _Uint8ListFromList extends BenchmarkBase {
_Uint8ListFromList() : super('Uint8List.fromList');

late Uint8List _list;

@override
void run() {
_list = Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
}

@override
void teardown() {
// Use the list so it is not optimized away.
_writeBytesAvoidDeopt(_list);
}
}

final class _Uint8ListWithLength extends BenchmarkBase {
_Uint8ListWithLength() : super('Uint8List.withLength');

late Uint8List _list;

@override
void run() {
final list = Uint8List(10);
list[0] = 0;
list[1] = 1;
list[2] = 2;
list[3] = 3;
list[4] = 4;
list[5] = 5;
list[6] = 6;
list[7] = 7;
list[8] = 8;
list[9] = 9;
_list = list;
}

@override
void teardown() {
// Use the list so it is not optimized away.
_writeBytesAvoidDeopt(_list);
}
}

void _writeBytesAvoidDeopt(Uint8List list) {
final tmpDir = io.Directory.systemTemp.createTempSync('nox.benchmark');
final file = io.File(
'${tmpDir.path}${io.Platform.pathSeparator}nox.benchmark',
);
file.writeAsBytesSync(list);
file.deleteSync();
tmpDir.deleteSync();
}
9 changes: 9 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md

presets:
# Runs VM-specific tests and captures coverage.
coverage:
reporter: github

platforms:
- vm
24 changes: 24 additions & 0 deletions dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dartdoc:
categories:
"Introduction":
markdown: doc/intro.md
"Cursors and Positioning":
markdown: doc/cursor.md
"Event Handling":
markdown: doc/events.md
"Screen Manipulation":
markdown: doc/screen.md
"Styles and Colors":
markdown: doc/styles.md
"Parsing ANSI Text":
markdown: doc/parsing.md
"Best Practices":
markdown: doc/best_practices.md
categoryOrder:
- "Introduction"
- "Styles and Colors"
- "Cursors and Positioning"
- "Screen Manipulation"
- "Event Handling"
- "Parsing ANSI Text"
- "Best Practices"
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 893399e

Please sign in to comment.