Chalk class Null safety
Chalk - A Library for printing styled text to the console using ANSI control sequences. Documentation of the ANSI code system: https://en.wikipedia.org/wiki/ANSI_escape_code . References with detailed explainations of the various color models included here: https://en.wikipedia.org/wiki/HSL_and_HSV and https://en.wikipedia.org/wiki/HWB_color_model The complete history of the X11 color names (later used in css/svg also) https://en.wikipedia.org/wiki/X11_color_names .
- Available Extensions
Constructors
- Chalk()
-
Factory function typically used for creating new 'root' instances of Chalk
(root instances start with no style)
factory
Properties
- bgBlack → Chalk
-
Legacy api, provided only for backwards compatability, use onBlack.
read-only
- bgBlackBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightBlack.
read-only
- bgBlue → Chalk
-
Legacy api, provided only for backwards compatability, use onBlue.
read-only
- bgBlueBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightBlue.
read-only
- bgBrightBlack → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightBlack.
read-only
- bgBrightBlue → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightBlue.
read-only
- bgBrightCyan → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightCyan.
read-only
- bgBrightGreen → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightGreen.
read-only
- bgBrightMagenta → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightMagenta.
read-only
- bgBrightRed → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightRed.
read-only
- bgBrightWhite → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightWhite.
read-only
- bgBrightYellow → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightYellow.
read-only
- bgCyan → Chalk
-
Legacy api, provided only for backwards compatability, use onCyan.
read-only
- bgCyanBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightCyan.
read-only
- bgGray → Chalk
-
Legacy api, provided only for backwards compatability, use onGray.
read-only
- bgGreen → Chalk
-
Legacy api, provided only for backwards compatability, use onGreen.
read-only
- bgGreenBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightGreen.
read-only
- bgGrey → Chalk
-
Legacy api, provided only for backwards compatability, use onGrey.
read-only
- bgMagenta → Chalk
-
Legacy api, provided only for backwards compatability, use onMagenta.
read-only
- bgMagentaBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightMagenta.
read-only
- bgRed → Chalk
-
Legacy api, provided only for backwards compatability, use onRed.
read-only
- bgRedBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightRed.
read-only
- bgWhite → Chalk
-
Legacy api, provided only for backwards compatability, use onWhite.
read-only
- bgWhiteBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightWhite.
read-only
- bgYellow → Chalk
-
Legacy api, provided only for backwards compatability, use onYellow.
read-only
- bgYellowBright → Chalk
-
Legacy api, provided only for backwards compatability, use onBrightYellow.
read-only
- black → Chalk
-
Set foreground color to one of the base 16 xterm colors
read-only
- blackBright → Chalk
-
read-only
- blackletter → Chalk
-
blackletter - alternate name for font10, ANSI/ECMA-48 spec refers to font10 specifically as a blackletter or Fraktur (Gothic) font.
(Not widely supported)
read-only
- blink → Chalk
-
blink - Make text blink. (Not widely supported)
read-only
- blue → Chalk
-
read-only
- blueBright → Chalk
-
read-only
- bold → Chalk
-
bold - Make text bold.
read-only
- brightBlack → Chalk
-
8 more 'bright' versions of the lower 8 colors
read-only
- brightBlue → Chalk
-
read-only
- brightCyan → Chalk
-
read-only
- brightGreen → Chalk
-
read-only
- brightMagenta → Chalk
-
read-only
- brightRed → Chalk
-
read-only
- brightWhite → Chalk
-
read-only
- brightYellow → Chalk
-
read-only
- color → dynamic
-
Follow this method with any standard CSS/SVG/X11 color name (remove spaces from name)
The case/capitalizatiom of the color name is not important.
color returns chalk as 'dynamic' so that CSS/SVG/X11 color names can 'dynamically' be
accessed as virtual methods.
ie.
chalk.color.cornflowerblue('works like this')
(this is the equivalent ofchalk.keyword('cornflowerblue')('same things using keyword()'
)read-only - csscolor → dynamic
-
Follow this method with any standard CSS/SVG/X11 color name (remove spaces from name)
The case/capitalizatiom of the color name is not important.
alias for color - alternate method name to use for to get dynamic for virtual color methods
ie.
chalk.csscolor.cornflowerblue('works like this')
(this is the equivalent ofchalk.keyword('cornflowerblue')('same things using keyword()'
)read-only - cyan → Chalk
-
read-only
- cyanBright → Chalk
-
read-only
- dim → Chalk
-
dim - Emitting only a small amount of light.
read-only
- doubleUnderline → Chalk
-
doubleUnderline - alternate for doubleunderline
read-only
- doubleunderline → Chalk
-
doubleunderline - Make text double underlined. (Not widely supported)
read-only
- doubleunderlined → Chalk
-
read-only
- font1 → Chalk
-
Alternative font 1. (Not widely supported)
read-only
- font2 → Chalk
-
Alternative font 2. (Not widely supported)
read-only
- font3 → Chalk
-
Alternative font 3. (Not widely supported)
read-only
- font4 → Chalk
-
Alternative font 4. (Not widely supported)
read-only
- font5 → Chalk
-
Alternative font 5. (Not widely supported)
read-only
- font6 → Chalk
-
Alternative font 6. (Not widely supported)
read-only
- font7 → Chalk
-
Alternative font 7. (Not widely supported)
read-only
- font8 → Chalk
-
Alternative font 8. (Not widely supported)
read-only
- font9 → Chalk
-
Alternative font 9. (Not widely supported)
read-only
- font10 → Chalk
-
Alternative font 10. (Not widely supported)
read-only
- gray → Chalk
-
read-only
- green → Chalk
-
read-only
- greenBright → Chalk
-
read-only
- grey → Chalk
-
read-only
- hashCode → int
-
The hash code for this object.
read-only, inherited
-
hidden - Prints the text, but makes it invisible. (still copy and pasteable)
read-only
- inverse → Chalk
-
inverse- Inverse background and foreground colors.
read-only
- invert → Chalk
-
invert- alternate for inverse() - Inverse background and foreground colors.
read-only
- italic → Chalk
-
italic - Make text italic. (VSCode debug console supports,some other terminals)
read-only
- level ↔ int
-
ANSI Color level support for this chalk instance - this will effect what colors
this chalk instance can use.
read / write
- magenta → Chalk
-
read-only
- magentaBright → Chalk
-
read-only
- normal → Chalk
-
normal - Text with all attributes off
read-only
- onBlack → Chalk
-
chalkdart favors 'onXXXXX' style of specifying background colors because it makes
chained methods list read better as a sentence (
it's the Dart way
). We include original Chalk 'bgXXXX' method names for users that prefer that scheme and for legacy compatability with original JS Chalk.read-only - onBlue → Chalk
-
read-only
- onBrightBlack → Chalk
-
read-only
- onBrightBlue → Chalk
-
read-only
- onBrightCyan → Chalk
-
read-only
- onBrightGreen → Chalk
-
read-only
- onBrightMagenta → Chalk
-
read-only
- onBrightRed → Chalk
-
read-only
- onBrightWhite → Chalk
-
read-only
- onBrightYellow → Chalk
-
read-only
- onCyan → Chalk
-
read-only
- onGray → Chalk
-
read-only
- onGreen → Chalk
-
read-only
- onGrey → Chalk
-
read-only
- onMagenta → Chalk
-
read-only
- onRed → Chalk
-
read-only
- onWhite → Chalk
-
read-only
- onYellow → Chalk
-
read-only
- overline → Chalk
-
overline - Make text overlined. (Not widely supported)
read-only
- overlined → Chalk
-
read-only
- rapidblink → Chalk
-
rapidblink - Make text blink rapidly (>150 times per minute). (Not widely supported)
read-only
- red → Chalk
-
make foreground red
read-only
- redBright → Chalk
-
read-only
- reset → Chalk
-
reset - Resets the current color chain.
read-only
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- strikethrough → Chalk
-
strikethrough - Puts a horizontal line through the center of the text. (Not widely supported)
read-only
- subscript → Chalk
-
subscript - Subscript text. (Not widely supported)
read-only
- superscript → Chalk
-
superscript - Superscript text. (Not widely supported)
read-only
- underline → Chalk
-
underline - Make text underline. (Not widely supported)
read-only
- underlined → Chalk
-
read-only
- visible → Chalk
-
visible - Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
read-only
- white → Chalk
-
read-only
- whiteBright → Chalk
-
read-only
- x11 → dynamic
-
Follow this method with any standard CSS/SVG/X11 color name (remove spaces from name)
The case/capitalizatiom of the color name is not important.
alias for color - alternate method name to use for to get dynamic for virtual color methods
ie.
chalk.x11.cornflowerblue('works like this')
(this is the equivalent ofchalk.keyword('cornflowerblue')('same things using keyword()'
)read-only - yellow → Chalk
-
read-only
- yellowBright → Chalk
-
read-only
Methods
-
ansi(
int ansicode) → Chalk - Creates chalk with the foreground color specified by the ansi color escape code. https://en.wikipedia.org/wiki/ANSI_escape_code
-
ansi256(
int ansicode256) → Chalk - https://en.wikipedia.org/wiki/ANSI_escape_code
-
ansiSgr(
dynamic openCode, dynamic closeCode) → Chalk - https://en.wikipedia.org/wiki/ANSI_escape_code
-
bgAnsi(
int ansicode) → Chalk - Alternate name for onAnsi() (provided for legacy compatibility with JS Chalk)
-
bgAnsi256(
int ansicode256) → Chalk - Alternate name for onAnsi256() (provided for legacy compatibility with JS Chalk)
-
bgGreyscale(
num greyscale) → Chalk - Alternate name for onGreyscale() (provided for legacy compatibility with JS Chalk)
-
bgHex(
dynamic hex) → Chalk - Alternate name for onHex() (provided for legacy compatibility with JS Chalk).
-
bgHsl(
num hue, num saturation, num lightness) → Chalk - Alternate name for onHsl() (provided for legacy compatibility with JS Chalk)
-
bgHsv(
num hue, num saturation, num value) → Chalk - Alternate name for onHsv() (provided for legacy compatibility with JS Chalk)
-
bgHwb(
num hue, num whiteness, num blackness) → Chalk - Alternate name for onHwb() (provided for legacy compatibility with JS Chalk)
-
bgKeyword(
String keyword) → Chalk - Alternate name for onKeyword() (provided for legacy compatibility with JS Chalk).
-
bgLab(
num l, num a, num b) → Chalk - Alternate name for onLab() (provided for legacy compatibility with JS Chalk)
-
bgRgb(
num red, num green, num blue) → Chalk - Alternate name for onRgb() (provided for legacy compatibility with JS Chalk).
-
bgRgb16m(
num red, num green, num blue) → Chalk - Alternate name for onRgb16m() (provided for legacy compatibility with JS Chalk).
-
bgXyz(
num x, num y, num z) → Chalk - Alternate name for onXyz() (provided for legacy compatibility with JS Chalk)
-
call(
dynamic arg0, [dynamic arg1, dynamic arg2, dynamic arg3, dynamic arg4, dynamic arg5, dynamic arg6, dynamic arg7, dynamic arg8, dynamic arg9, dynamic arg10, dynamic arg11, dynamic arg12, dynamic arg13, dynamic arg14, dynamic arg15]) → String - Handles the generic Chalk(....) calls with up to 15 arguements that can be a mixtured of pretty much anything. List<> and Function closures are handled
-
greyscale(
num greyscale) → Chalk -
hex(
dynamic hex) → Chalk - Returns a Chalk with the foreground color set to the passed in RGB Hex code. This dynamically accepts color hex codes as integer codes (0xAABBCC) or (0xABC) or as strings ('#AABBCC') or ('#ABC')
-
hsl(
num hue, num saturation, num lightness) → Chalk - Creates chalk with foreground color defined from HSL (Hue, Saturation and Lightness) color space parameters. https://en.wikipedia.org/wiki/HSL_and_HSV
-
hsv(
num hue, num saturation, num value) → Chalk - Creates chalk with foreground color defined from HSV (Hue, Saturation and Value) color space parameters. https://en.wikipedia.org/wiki/HSL_and_HSV
-
hwb(
num hue, num whiteness, num blackness) → Chalk - Creates chalk with foreground color defined from HWB (Hue, Whiteness and Blackness) color space parameters. https://en.wikipedia.org/wiki/HWB_color_model
-
joinWith(
String joinWith) → Chalk - Specify string to use for joining multiple arguments or Lists. Default is ' ' (single space).
-
keyword(
String colorKeyword) → Chalk - Returns a Chalk with the foreground color set to the color represented by the passed in color keyword. This accepts all of the standard X11/CSS/SVG color names, and the user can extend the list of accepted color keywords using the addColorKeywordRgb() and addColorKeywordHex() methods
-
lab(
num l, num a, num b) → Chalk - Creates chalk with foreground color defined from lab color space parameters. https://en.wikipedia.org/wiki/CIELAB_color_space#CIELAB
-
makeRGBChalk(
num nred, num ngreen, num nblue, {bool bg = false, bool force16M = false}) → Chalk -
noSuchMethod(
Invocation invocation) → dynamic -
This noSuchMethod() handler is called for all unknown methods called
on our Chalk object. Thisd allows using user defined colors and x11
colors as 'pseudo' methods.
dynamic chalk2 = Chalk();
print(chalk2.orange('Yay for red on yellow colored text!'));
print(chalk.csscolor.lightskyblue('Yay for lightskyblue colored text!'));
Background:
https://github.com/dart-lang/sdk/blob/master/docs/language/informal/nosuchmethod-forwarding.md
Good stuff.
override
-
onAnsi(
int ansicode) → Chalk - Creates chalk with the background color specified by the ansi color escape code. https://en.wikipedia.org/wiki/ANSI_escape_code
-
onAnsi256(
int ansicode256) → Chalk - https://en.wikipedia.org/wiki/ANSI_escape_code
-
onGreyscale(
num greyscale) → Chalk -
onHex(
dynamic hex) → Chalk - Returns a Chalk with the background color set to the passed in RGB Hex code. This dynamically accepts color hex codes as integer codes (0xAABBCC) or (0xABC) or as strings ('#AABBCC') or ('#ABC')
-
onHsl(
num hue, num saturation, num lightness) → Chalk - Creates chalk with background color defined from HSL (Hue, Saturation and Lightness) color space parameters. https://en.wikipedia.org/wiki/HSL_and_HSV
-
onHsv(
num hue, num saturation, num value) → Chalk - Creates chalk with background color defined from HSV (Hue, Saturation and Value) color space parameters. https://en.wikipedia.org/wiki/HSL_and_HSV
-
onHwb(
num hue, num whiteness, num blackness) → Chalk - Creates chalk with background color defined from HWB (Hue, Whiteness and Blackness) color space parameters. https://en.wikipedia.org/wiki/HWB_color_model
-
onKeyword(
String colorKeyword) → Chalk - Returns a Chalk with the background color set to the color represented by the passed in color keyword. This accepts all of the standard X11/CSS/SVG color names, and the user can extend the list of accepted color keywords using the addColorKeywordRgb() and addColorKeywordHex() methods
-
onLab(
num l, num a, num b) → Chalk - Creates chalk with background color defined from lab color space parameters. https://en.wikipedia.org/wiki/CIELAB_color_space#CIELAB
-
onRgb(
num red, num green, num blue) → Chalk - Create Chalk with a background color with the specified RGB values.
-
onRgb16m(
num red, num green, num blue) → Chalk - Create Chalk with a background color with the specified RGB values (forces using ANSI 16m SGR codes, even if level is not 3).
-
onXyz(
num x, num y, num z) → Chalk - Creates chalk with background color defined from XYZ color space parameters. https://en.wikipedia.org/wiki/CIE_1931_color_space
-
rgb(
num red, num green, num blue) → Chalk - Create Chalk with a foreground color with the specified RGB values.
-
rgb16m(
num red, num green, num blue) → Chalk - Create Chalk with a foreground color with the specified RGB values (forces using ANSI 16m SGR codes, even if level is not 3).
-
strip(
String target) → String - Strip all ANSI SGR commands from the target string and return the 'stripped' result string.
-
toString(
) → String -
most useful for debugging to dump the guts
override
-
toStringWalkUp(
{int level = 0}) → String - more detailed dump of the guts, following parent links and dumping
-
underlineRgb(
num red, num green, num blue) → Chalk - Create Chalk with an underline of the the specified RGB color WARNING: on some consoles without support for this, such as Android Studio, using this will prevent ALL styles of the Chalk from appearing
-
underlineRgb16m(
num red, num green, num blue) → Chalk - Create Chalk with an underline of the the specified RGB color (forces using ANSI 16m SGR codes, even if level is not 3) WARNING: on some consoles without support for this, such as Android Studio, using this will prevent ALL styles of the Chalk from appearing
-
wrap(
String prefix, String suffix) → Chalk - Wrap this chalk with specified prefix and suffix strings.
-
xyz(
num x, num y, num z) → Chalk - Creates chalk with foreground color defined from XYZ color space parameters. https://en.wikipedia.org/wiki/CIE_1931_color_space
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- ansiColorLevelForNewInstances ↔ int
-
ANSI Color level support for terminal - default to 3 (full color) because
IntelliJ/AndroidStudio and VSCode report NOT having full color support
despite supporting level 3. This is really only here for flexibility.
read / write
- noZeroToOneScaling ↔ bool
-
Set to true to prevent scaling of rgb values when all 3 fall between 0<=r,g,b<=1.0
read / write
- useFullResetToClose ↔ bool
-
Use full resets to close attributes (reset all attributes with SGR 0) ON EACH call to Chalk()
(Not usually desired, this will reset all attributes, but some terminals, like VSCode,
need this because buggy implementations)
(Update: I have fixed and extended the VSCode support for ANSI control sequences to be complete
and bug free. All features of Chalk'Dart are now completely supported.
This is now all available in production version of VSCode - timmaffett)
read / write
Static Methods
-
addColorKeywordHex(
String colorname, dynamic hex) → void - Add Hex color (string or int) to the colorKeywords[] map that is used for dynamic lookup of colors by name. Colors added thid way can be used directly follwing the Chalk color/csscolor/x11 methods. ie. Chalk.addColorKeywordHex('myfavorite', 0x6495ED ); // using hex int chalk.color.myfavorite('This is my favorite color'); Chalk.addColorKeywordHex('my2ndFavorite', '#6A5ACD' ); // or using string chalk.color.my2ndfavorite('This is my 2nd favorite color');
-
addColorKeywordRgb(
String colorname, int red, int green, int blue) → void - Add RGB color to the colorKeywords[] map that is used for dynamic lookup of colors by name. Colors added thid way can be used directly following the Chalk color/csscolor/x11 methods. ie. Chalk.addColorKeywordRgb('myfavorite', 0x64, 0x95, 0xED ); chalk.color.myfavorite('This is my favorite color');
-
Instance(
{int level = -1}) → Chalk -
instance(
{int level = -1}) → Chalk - Use to create a new 'root' instance of Chalk, with the option of setting the ANSI color level (root instances start with no style).
Constants
- ansiBackgroundOffset → const int
-
This offset can be added to the basic 0-15 ansi color numbers to get background
versions of those colors.
10
- ansiUnderlineOffset → const int
-
This offset can be added to the basic 0-15 ansi color numbers to get underline
versions of those colors.
20