-
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
0 parents
commit a11757a
Showing
10 changed files
with
436 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Files and directories created by pub. | ||
.dart_tool/ | ||
.packages | ||
|
||
# Conventional directory for build outputs. | ||
build/ | ||
|
||
# Omit committing pubspec.lock for library packages; see | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
pubspec.lock |
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,3 @@ | ||
## 1.0.0 | ||
|
||
- Support colors via extensions on String. |
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,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2022, Akash Pattanaik | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,114 @@ | ||
# colorx.dart | ||
|
||
Please open Issues to provide feedback, and check the `dev` branch for the latest bleeding-edge updates. | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [All Available Methods](#all-available-methods) | ||
- [Important](#important) | ||
- [Donate](#donate) | ||
|
||
## Installation | ||
|
||
```powershell | ||
dart pub get colorx | ||
``` | ||
|
||
OR | ||
|
||
```powershell | ||
flutter pub get colorx | ||
``` | ||
|
||
<details> | ||
<summary><h2>All Available Methods</h2></summary> | ||
|
||
### text colors | ||
|
||
- black | ||
- red | ||
- green | ||
- yellow | ||
- blue | ||
- magenta | ||
- cyan | ||
- white | ||
- gray | ||
- grey | ||
|
||
### bright text colors | ||
|
||
- brightRed | ||
- brightGreen | ||
- brightYellow | ||
- brightBlue | ||
- brightMagenta | ||
- brightCyan | ||
- brightWhite | ||
|
||
### background colors | ||
|
||
- bgBlack | ||
- bgRed | ||
- bgGreen | ||
- bgYellow | ||
- bgBlue | ||
- bgMagenta | ||
- bgCyan | ||
- bgWhite | ||
- bgGray | ||
- bgGrey | ||
|
||
### bright background colors | ||
|
||
- bgBrightRed | ||
- bgBrightGreen | ||
- bgBrightYellow | ||
- bgBrightBlue | ||
- bgBrightMagenta | ||
- bgBrightCyan | ||
- bgBrightWhite | ||
|
||
### styles | ||
|
||
- reset | ||
- bold | ||
- dim | ||
- italic | ||
- underline | ||
- inverse | ||
- hidden | ||
- strikethrough | ||
|
||
### extras | ||
|
||
- rainbow() | ||
- zebra() | ||
- indianFlag() | ||
|
||
</details> | ||
|
||
## Usage | ||
|
||
```dart | ||
import 'package:colorx/colorx.dart'; | ||
void main(List<String> args) { | ||
print(Colors('Red, Bold and with Blue background').red.bold.bgBlue); | ||
print('Red, Bold and with Blue background'.red.bold.bgBlue); | ||
print('This is a raindow text'.rainbow()); | ||
print('This is the INDIAN Flag'.indianFlag()); | ||
} | ||
``` | ||
|
||
## Important | ||
|
||
This is a dart implementation of [colors.js](https://github.com/Marak/colors.js). After recent events about [Marka](https://github.com/Marak/), I would like you all to donate to me if you want me to keep maintaing this library. Open Source is a place for all and if you want to keep using libraries like this for free, seriously consider donating to open source developer. | ||
|
||
## Donate | ||
|
||
- **UPI** - `akashpattnaik.github@ybl` | ||
- **Bitcoin** - `1CtRtERW75oBNk6qmXSfYgQVqxt6NFwvLM` (Blockchain - `Bitcoin`) | ||
- **Bitcoin** - `0x67243756d4144d6d3e132baa0660e0bc0cddf59b` (Blockchain - `BEP.20`) | ||
- **Ethereum** - `0x67243756d4144d6d3e132baa0660e0bc0cddf59b` (Blockchain - `Ethereum`) | ||
- **TetherUS** - `0x67243756d4144d6d3e132baa0660e0bc0cddf59b` (Blockchain - `BEP.20`) |
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 @@ | ||
include: package:lints/recommended.yaml | ||
|
||
linter: | ||
rules: | ||
- camel_case_types |
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,55 @@ | ||
import 'package:colorx/colorx.dart'; | ||
|
||
void main() { | ||
print('reset'.reset); | ||
|
||
print('bold'.bold); | ||
print('dim'.dim); | ||
print('italic'.italic); | ||
print('underline'.underline); | ||
print('inverse'.inverse); | ||
print('hidden'.hidden); | ||
print('strikethrough'.strikethrough); | ||
|
||
print('black'.black); | ||
print('red'.red); | ||
print('green'.green); | ||
print('yellow'.yellow); | ||
print('blue'.blue); | ||
print('magenta'.magenta); | ||
print('cyan'.cyan); | ||
print('white'.white); | ||
print('gray'.gray); | ||
print('grey'.grey); | ||
|
||
print('brightRed'.brightRed); | ||
print('brightGreen'.brightGreen); | ||
print('brightYellow'.brightYellow); | ||
print('brightBlue'.brightBlue); | ||
print('brightMagenta'.brightMagenta); | ||
print('brightCyan'.brightCyan); | ||
print('brightWhite'.brightWhite); | ||
|
||
print('bgBlack'.bgBlack); | ||
print('bgRed'.bgRed); | ||
print('bgGreen'.bgGreen); | ||
print('bgYellow'.bgYellow); | ||
print('bgBlue'.bgBlue); | ||
print('bgMagenta'.bgMagenta); | ||
print('bgCyan'.bgCyan); | ||
print('bgWhite'.bgWhite); | ||
print('bgGray'.bgGray); | ||
print('bgGrey'.bgGrey); | ||
|
||
print('bgBrightRed'.bgBrightRed); | ||
print('bgBrightGreen'.bgBrightGreen); | ||
print('bgBrightYellow'.bgBrightYellow); | ||
print('bgBrightBlue'.bgBrightBlue); | ||
print('bgBrightMagenta'.bgBrightMagenta); | ||
print('bgBrightCyan'.bgBrightCyan); | ||
print('bgBrightWhite'.bgBrightWhite); | ||
|
||
print('This is a Rainbow !'.rainbow()); | ||
print('Zeebra\'s are fun too !'.zebra()); | ||
print('And here is the Indian Flag !'.indianFlag()); | ||
} |
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,3 @@ | ||
library colorx; | ||
|
||
export 'src/colorx_base.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
final Map<String, List<int>> _colorCodes = { | ||
'reset': [0, 0], | ||
|
||
'bold': [1, 22], | ||
'dim': [2, 22], | ||
'italic': [3, 23], | ||
'underline': [4, 24], | ||
'inverse': [7, 27], | ||
'hidden': [8, 28], | ||
'strikethrough': [9, 29], | ||
|
||
'black': [30, 39], | ||
'red': [31, 39], | ||
'green': [32, 39], | ||
'yellow': [33, 39], | ||
'blue': [34, 39], | ||
'magenta': [35, 39], | ||
'cyan': [36, 39], | ||
'white': [37, 39], | ||
'gray': [90, 39], | ||
'grey': [90, 39], | ||
|
||
'brightRed': [91, 39], | ||
'brightGreen': [92, 39], | ||
'brightYellow': [93, 39], | ||
'brightBlue': [94, 39], | ||
'brightMagenta': [95, 39], | ||
'brightCyan': [96, 39], | ||
'brightWhite': [97, 39], | ||
|
||
'bgBlack': [40, 49], | ||
'bgRed': [41, 49], | ||
'bgGreen': [42, 49], | ||
'bgYellow': [43, 49], | ||
'bgBlue': [44, 49], | ||
'bgMagenta': [45, 49], | ||
'bgCyan': [46, 49], | ||
'bgWhite': [47, 49], | ||
'bgGray': [100, 49], | ||
'bgGrey': [100, 49], | ||
|
||
'bgBrightRed': [101, 49], | ||
'bgBrightGreen': [102, 49], | ||
'bgBrightYellow': [103, 49], | ||
'bgBrightBlue': [104, 49], | ||
'bgBrightMagenta': [105, 49], | ||
'bgBrightCyan': [106, 49], | ||
'bgBrightWhite': [107, 49], | ||
}; | ||
|
||
String _applyColor(String text, String color) { | ||
final List<int>? codes = _colorCodes[color]; | ||
return '\u001b[${codes![0]}m$text\u001b[${codes[1]}m'; | ||
} | ||
|
||
extension Colors on String { | ||
String get reset => _applyColor(this, 'reset'); | ||
|
||
String get bold => _applyColor(this, 'bold'); | ||
String get dim => _applyColor(this, 'dim'); | ||
String get italic => _applyColor(this, 'italic'); | ||
String get underline => _applyColor(this, 'underline'); | ||
String get inverse => _applyColor(this, 'inverse'); | ||
String get hidden => _applyColor(this, 'hidden'); | ||
String get strikethrough => _applyColor(this, 'strikethrough'); | ||
|
||
String get black => _applyColor(this, 'black'); | ||
String get red => _applyColor(this, 'red'); | ||
String get green => _applyColor(this, 'green'); | ||
String get yellow => _applyColor(this, 'yellow'); | ||
String get blue => _applyColor(this, 'blue'); | ||
String get magenta => _applyColor(this, 'magenta'); | ||
String get cyan => _applyColor(this, 'cyan'); | ||
String get white => _applyColor(this, 'white'); | ||
String get gray => _applyColor(this, 'gray'); | ||
String get grey => _applyColor(this, 'grey'); | ||
|
||
String get brightRed => _applyColor(this, 'brightRed'); | ||
String get brightGreen => _applyColor(this, 'brightGreen'); | ||
String get brightYellow => _applyColor(this, 'brightYellow'); | ||
String get brightBlue => _applyColor(this, 'brightBlue'); | ||
String get brightMagenta => _applyColor(this, 'brightMagenta'); | ||
String get brightCyan => _applyColor(this, 'brightCyan'); | ||
String get brightWhite => _applyColor(this, 'brightWhite'); | ||
|
||
String get bgBlack => _applyColor(this, 'bgBlack'); | ||
String get bgRed => _applyColor(this, 'bgRed'); | ||
String get bgGreen => _applyColor(this, 'bgGreen'); | ||
String get bgYellow => _applyColor(this, 'bgYellow'); | ||
String get bgBlue => _applyColor(this, 'bgBlue'); | ||
String get bgMagenta => _applyColor(this, 'bgMagenta'); | ||
String get bgCyan => _applyColor(this, 'bgCyan'); | ||
String get bgWhite => _applyColor(this, 'bgWhite'); | ||
String get bgGray => _applyColor(this, 'bgGray'); | ||
String get bgGrey => _applyColor(this, 'bgGrey'); | ||
|
||
String get bgBrightRed => _applyColor(this, 'bgBrightRed'); | ||
String get bgBrightGreen => _applyColor(this, 'bgBrightGreen'); | ||
String get bgBrightYellow => _applyColor(this, 'bgBrightYellow'); | ||
String get bgBrightBlue => _applyColor(this, 'bgBrightBlue'); | ||
String get bgBrightMagenta => _applyColor(this, 'bgBrightMagenta'); | ||
String get bgBrightCyan => _applyColor(this, 'bgBrightCyan'); | ||
String get bgBrightWhite => _applyColor(this, 'bgBrightWhite'); | ||
|
||
String rainbow() { | ||
final List<String> _colors = [ | ||
'red', // R | ||
// orange (O, doesn't exist) | ||
'yellow', // Y | ||
'green', // G | ||
'cyan', // B | ||
'blue', // I | ||
'magenta', // V | ||
]; | ||
final List<String> _rainbow = []; | ||
for (int i = 0; i < length; i++) { | ||
_rainbow.add(_applyColor(this[i], _colors[i % _colors.length])); | ||
} | ||
return _rainbow.join(); | ||
} | ||
|
||
String zebra() { | ||
final List<String> _zebra = []; | ||
for (int i = 0; i < length; i++) { | ||
_zebra.add(i % 2 == 0 ? this[i] : this[i].inverse); | ||
} | ||
return _zebra.join(); | ||
} | ||
|
||
String indianFlag() { | ||
final List<String> _colors = [ | ||
'red', // R | ||
'white', // W | ||
'green', // G | ||
]; | ||
final List<String> _indianFlag = []; | ||
for (int i = 0; i < length; i++) { | ||
if (this[i] == ' ') { | ||
_indianFlag.add(' '); | ||
} else { | ||
_indianFlag.add(_applyColor(this[i], _colors[i % _colors.length])); | ||
} | ||
} | ||
return _indianFlag.join(); | ||
} | ||
} |
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,11 @@ | ||
name: colorx | ||
description: Colors.JS implementation in dartlang. | ||
version: 1.0.0 | ||
homepage: https://github.com/BLUE-DEVIL1134/colorx.dart | ||
|
||
environment: | ||
sdk: '>=2.15.1 <3.0.0' | ||
|
||
dev_dependencies: | ||
lints: ^1.0.0 | ||
test: ^1.16.0 |
Oops, something went wrong.