This repository has been archived by the owner on Feb 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
195 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.1.0 | ||
|
||
- Support foreground and background decorations. | ||
|
||
## 0.0.0 | ||
|
||
- Support basic font style decorations. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'standard_example.dart'; | ||
|
||
void main() { | ||
standardExample(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:terminal_decorate/terminal_decorate.dart'; | ||
|
||
void standardExample() { | ||
for (final item in fontStyleDecorations) print(item); | ||
for (final item in foregroundDecorations) print(item); | ||
for (final item in backgroundDecorations) print(item); | ||
} | ||
|
||
final fontStyleDecorations = [ | ||
'\nfont style decorations:', | ||
'(${Escape.bold.code}:${Escape.cancelBoldOrFaint.code}) ${'bold'.bold} style', | ||
'(${Escape.faint.code}:${Escape.cancelBoldOrFaint.code}) ' | ||
'${'faint/dim'.faint} style', | ||
'(${Escape.italic.code}:${Escape.cancelItalic.code}) ' | ||
'${'italic'.italic} style', | ||
'(${Escape.underline.code}:${Escape.cancelUnderline.code}) ' | ||
'${'underline'.underline} style', | ||
'(${Escape.blink.code}:${Escape.cancelBlink.code}) ' | ||
'${'blink'.blink} style ' | ||
'(usually unsupported)', | ||
'(${Escape.rapidBlink.code}:${Escape.cancelBlink.code}) ' | ||
'${'rapid blink'.rapidBlink} style ' | ||
'(usually unsupported)', | ||
'(${Escape.negative.code}:${Escape.cancelNegative.code}) ' | ||
'${'negative'.negative} style', | ||
'(${Escape.conceal.code}:${Escape.cancelConceal.code}) ' | ||
'${'conceal'.conceal} (conceal/hide) style', | ||
'(${Escape.crossLine.code}:${Escape.cancelCrossLine.code}) ' | ||
'${'cross line'.crossLine} style', | ||
'(${Escape.doubleUnderline.code}:${Escape.cancelUnderline.code}) ' | ||
'${'double underline'.doubleUnderline} style ' | ||
'(usually unsupported)', | ||
]; | ||
|
||
final foregroundDecorations = [ | ||
'(${Escape.black.code}:${Escape.cancelFg.code}) ' | ||
'${'black'.black} (black) style (sometimes deep gray)', | ||
'(${Escape.red.code}:${Escape.cancelFg.code}) ${'red'.red} style', | ||
'(${Escape.yellow.code}:${Escape.cancelFg.code}) ${'yellow'.yellow} style', | ||
'(${Escape.green.code}:${Escape.cancelFg.code}) ${'green'.green} style', | ||
'(${Escape.cyan.code}:${Escape.cancelFg.code}) ${'cyan'.cyan} style', | ||
'(${Escape.blue.code}:${Escape.cancelFg.code}) ${'blue'.blue} style', | ||
'(${Escape.magenta.code}:${Escape.cancelFg.code}) ${'magenta'.magenta} style', | ||
'(${Escape.white.code}:${Escape.cancelFg.code}) ' | ||
'${'white'.white} (white) style', | ||
]; | ||
|
||
final backgroundDecorations = [ | ||
'(${Escape.bgBlack.code}:${Escape.cancelBg.code}) ' | ||
'${'black background'.bgBlack} (black) style', | ||
'(${Escape.bgRed.code}:${Escape.cancelBg.code}) ' | ||
'${'red background'.bgRed} style', | ||
'(${Escape.bgYellow.code}:${Escape.cancelBg.code}) ' | ||
'${'yellow background'.bgYellow} style', | ||
'(${Escape.bgGreen.code}:${Escape.cancelBg.code}) ' | ||
'${'green background'.bgGreen} style', | ||
'(${Escape.bgCyan.code}:${Escape.cancelBg.code}) ' | ||
'${'cyan background'.bgCyan} style', | ||
'(${Escape.bgBlue.code}:${Escape.cancelBg.code}) ' | ||
'${'blue background'.bgBlue} style', | ||
'(${Escape.bgMagenta.code}:${Escape.cancelBg.code}) ' | ||
'${'magenta background'.bgMagenta} style', | ||
'(${Escape.bgWhite.code}:${Escape.cancelBg.code}) ' | ||
'${'white background'.bgWhite} (white) style', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
enum Escape { | ||
cancelAll(0), | ||
bold(1), | ||
|
||
/// Also called "dim". | ||
faint(2), | ||
italic(3), | ||
underline(4), | ||
|
||
/// Usually unsupported. | ||
blink(5), | ||
|
||
/// Usually unsupported. | ||
rapidBlink(6), | ||
negative(7), | ||
|
||
/// Also called "hide". | ||
conceal(8), | ||
|
||
/// Usually unsupported. | ||
crossLine(9), | ||
|
||
/// Usually unsupported. | ||
doubleUnderline(21), | ||
|
||
// Cancel font decorations. | ||
cancelBoldOrFaint(22), | ||
cancelItalic(23), | ||
cancelUnderline(24), | ||
cancelBlink(25), | ||
cancelNegative(27), | ||
cancelConceal(28), | ||
cancelCrossLine(29), | ||
|
||
// Foreground decorations. | ||
black(30), | ||
red(31), | ||
green(32), | ||
yellow(33), | ||
blue(34), | ||
magenta(35), | ||
cyan(36), | ||
white(37), | ||
customizeFg(38), | ||
cancelFg(39), | ||
|
||
// Bg decoration. | ||
bgBlack(40), | ||
bgRed(41), | ||
bgGreen(42), | ||
bgYellow(43), | ||
bgBlue(44), | ||
bgMagenta(45), | ||
bgCyan(46), | ||
bgWhite(47), | ||
customizeBg(48), | ||
cancelBg(49); | ||
|
||
const Escape(this.code) | ||
: assert(code >= 0 && code <= 0xff, 'invalid code: $code (0~255)'); | ||
|
||
final int code; | ||
|
||
String get format => '\x1b[${code}m'; | ||
|
||
@override | ||
String toString() => format; | ||
} | ||
|
||
extension TerminalFontStyleDecorations on String { | ||
String get bold => '${Escape.bold}$this${Escape.cancelBoldOrFaint}'; | ||
String get faint => '${Escape.faint}$this${Escape.cancelBoldOrFaint}'; | ||
String get italic => '${Escape.italic}$this${Escape.cancelItalic}'; | ||
String get underline => '${Escape.underline}$this${Escape.cancelUnderline}'; | ||
String get blink => '${Escape.blink}$this${Escape.cancelBlink}'; | ||
String get rapidBlink => '${Escape.rapidBlink}$this${Escape.cancelBlink}'; | ||
String get negative => '${Escape.negative}$this${Escape.cancelNegative}'; | ||
String get conceal => '${Escape.conceal}$this${Escape.cancelConceal}'; | ||
String get crossLine => '${Escape.crossLine}$this${Escape.cancelCrossLine}'; | ||
String get doubleUnderline => | ||
'${Escape.doubleUnderline}$this${Escape.cancelUnderline}'; | ||
|
||
// Syntax sugars. | ||
String get dim => faint; | ||
String get hide => conceal; | ||
} | ||
|
||
extension TerminalColorDecorations on String { | ||
// Foreground. | ||
String get black => '${Escape.black}$this${Escape.cancelFg}'; | ||
String get red => '${Escape.red}$this${Escape.cancelFg}'; | ||
String get green => '${Escape.green}$this${Escape.cancelFg}'; | ||
String get yellow => '${Escape.yellow}$this${Escape.cancelFg}'; | ||
String get blue => '${Escape.blue}$this${Escape.cancelFg}'; | ||
String get magenta => '${Escape.magenta}$this${Escape.cancelFg}'; | ||
String get cyan => '${Escape.cyan}$this${Escape.cancelFg}'; | ||
String get white => '${Escape.white}$this${Escape.cancelFg}'; | ||
|
||
// Background. | ||
String get bgBlack => '${Escape.bgBlack}$this${Escape.cancelBg}'; | ||
String get bgRed => '${Escape.bgRed}$this${Escape.cancelBg}'; | ||
String get bgGreen => '${Escape.bgGreen}$this${Escape.cancelBg}'; | ||
String get bgYellow => '${Escape.bgYellow}$this${Escape.cancelBg}'; | ||
String get bgBlue => '${Escape.bgBlue}$this${Escape.cancelBg}'; | ||
String get bgMagenta => '${Escape.bgMagenta}$this${Escape.cancelBg}'; | ||
String get bgCyan => '${Escape.bgCyan}$this${Escape.cancelBg}'; | ||
String get bgWhite => '${Escape.bgWhite}$this${Escape.cancelBg}'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export 'src/standart.dart'; | ||
export 'src/standard.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters