Chalk class

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.
no setter
bgBlackBright Chalk
Legacy api, provided only for backwards compatability, use onBrightBlack.
no setter
bgBlue Chalk
Legacy api, provided only for backwards compatability, use onBlue.
no setter
bgBlueBright Chalk
Legacy api, provided only for backwards compatability, use onBrightBlue.
no setter
bgBrightBlack Chalk
Legacy api, provided only for backwards compatability, use onBrightBlack.
no setter
bgBrightBlue Chalk
Legacy api, provided only for backwards compatability, use onBrightBlue.
no setter
bgBrightCyan Chalk
Legacy api, provided only for backwards compatability, use onBrightCyan.
no setter
bgBrightGreen Chalk
Legacy api, provided only for backwards compatability, use onBrightGreen.
no setter
bgBrightMagenta Chalk
Legacy api, provided only for backwards compatability, use onBrightMagenta.
no setter
bgBrightRed Chalk
Legacy api, provided only for backwards compatability, use onBrightRed.
no setter
bgBrightWhite Chalk
Legacy api, provided only for backwards compatability, use onBrightWhite.
no setter
bgBrightYellow Chalk
Legacy api, provided only for backwards compatability, use onBrightYellow.
no setter
bgCyan Chalk
Legacy api, provided only for backwards compatability, use onCyan.
no setter
bgCyanBright Chalk
Legacy api, provided only for backwards compatability, use onBrightCyan.
no setter
bgGray Chalk
Legacy api, provided only for backwards compatability, use onGray.
no setter
bgGreen Chalk
Legacy api, provided only for backwards compatability, use onGreen.
no setter
bgGreenBright Chalk
Legacy api, provided only for backwards compatability, use onBrightGreen.
no setter
bgGrey Chalk
Legacy api, provided only for backwards compatability, use onGrey.
no setter
bgMagenta Chalk
Legacy api, provided only for backwards compatability, use onMagenta.
no setter
bgMagentaBright Chalk
Legacy api, provided only for backwards compatability, use onBrightMagenta.
no setter
bgRed Chalk
Legacy api, provided only for backwards compatability, use onRed.
no setter
bgRedBright Chalk
Legacy api, provided only for backwards compatability, use onBrightRed.
no setter
bgWhite Chalk
Legacy api, provided only for backwards compatability, use onWhite.
no setter
bgWhiteBright Chalk
Legacy api, provided only for backwards compatability, use onBrightWhite.
no setter
bgYellow Chalk
Legacy api, provided only for backwards compatability, use onYellow.
no setter
bgYellowBright Chalk
Legacy api, provided only for backwards compatability, use onBrightYellow.
no setter
black Chalk
Set foreground color to one of the base 16 xterm colors
no setter
blackBright Chalk
no setter
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)
no setter
blink - Make text blink. (Not widely supported)
no setter
blue Chalk
no setter
blueBright Chalk
no setter
bold Chalk
bold - Make text bold.
no setter
brightBlack Chalk
8 more 'bright' versions of the lower 8 colors
no setter
brightBlue Chalk
no setter
brightCyan Chalk
no setter
brightGreen Chalk
no setter
brightMagenta Chalk
no setter
brightRed Chalk
no setter
brightWhite Chalk
no setter
brightYellow Chalk
no setter
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 of chalk.keyword('cornflowerblue')('same things using keyword()')
no setter
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 of chalk.keyword('cornflowerblue')('same things using keyword()')
no setter
cyan Chalk
no setter
cyanBright Chalk
no setter
dim Chalk
dim - Emitting only a small amount of light.
no setter
doubleUnderline Chalk
doubleUnderline - alternate for doubleunderline
no setter
doubleunderline Chalk
doubleunderline - Make text double underlined. (Not widely supported)
no setter
doubleunderlined Chalk
no setter
font1 Chalk
Alternative font 1. (Not widely supported)
no setter
font2 Chalk
Alternative font 2. (Not widely supported)
no setter
font3 Chalk
Alternative font 3. (Not widely supported)
no setter
font4 Chalk
Alternative font 4. (Not widely supported)
no setter
font5 Chalk
Alternative font 5. (Not widely supported)
no setter
font6 Chalk
Alternative font 6. (Not widely supported)
no setter
font7 Chalk
Alternative font 7. (Not widely supported)
no setter
font8 Chalk
Alternative font 8. (Not widely supported)
no setter
font9 Chalk
Alternative font 9. (Not widely supported)
no setter
font10 Chalk
Alternative font 10. (Not widely supported)
no setter
gray Chalk
no setter
green Chalk
no setter
greenBright Chalk
no setter
grey Chalk
no setter
hashCode int
The hash code for this object.
no setterinherited
hidden Chalk
hidden - Prints the text, but makes it invisible. (still copy and pasteable)
no setter
inverse Chalk
inverse- Inverse background and foreground colors.
no setter
invert Chalk
invert- alternate for inverse() - Inverse background and foreground colors.
no setter
italic Chalk
italic - Make text italic. (VSCode debug console supports,some other terminals)
no setter
level int
ANSI Color level support for this chalk instance - this will effect what colors this chalk instance can use.
getter/setter pair
magenta Chalk
no setter
magentaBright Chalk
no setter
normal Chalk
normal - Text with all attributes off
no setter
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.
no setter
onBlue Chalk
no setter
onBrightBlack Chalk
no setter
onBrightBlue Chalk
no setter
onBrightCyan Chalk
no setter
onBrightGreen Chalk
no setter
onBrightMagenta Chalk
no setter
onBrightRed Chalk
no setter
onBrightWhite Chalk
no setter
onBrightYellow Chalk
no setter
onCyan Chalk
no setter
onGray Chalk
no setter
onGreen Chalk
no setter
onGrey Chalk
no setter
onMagenta Chalk
no setter
onRed Chalk
no setter
onWhite Chalk
no setter
onYellow Chalk
no setter
overline Chalk
overline - Make text overlined. (Not widely supported)
no setter
overlined Chalk
no setter
rapidblink - Make text blink rapidly (>150 times per minute). (Not widely supported)
no setter
red Chalk
make foreground red    
no setter
redBright Chalk
no setter
reset Chalk
reset - Resets the current color chain.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
strikethrough Chalk
strikethrough - Puts a horizontal line through the center of the text. (Not widely supported)
no setter
subscript Chalk
subscript - Subscript text. (Not widely supported)
no setter
superscript Chalk
superscript - Superscript text. (Not widely supported)
no setter
underline Chalk
underline - Make text underline. (Not widely supported)
no setter
underlined Chalk
no setter
visible Chalk
visible - Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
no setter
white Chalk
no setter
whiteBright Chalk
no setter
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 of chalk.keyword('cornflowerblue')('same things using keyword()')
no setter
yellow Chalk
no setter
yellowBright Chalk
no setter

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.
getter/setter pair
noZeroToOneScaling bool
Set to true to prevent scaling of rgb values when all 3 fall between 0<=r,g,b<=1.0
getter/setter pair
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)
getter/setter pair

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
Use to create a new 'root' instance of Chalk, with the option of setting the ANSI color level (root instances start with no style).
Instance({int level = -1}) Chalk

Constants

ansiBackgroundOffset → const int
This offset can be added to the basic 0-15 ansi color numbers to get background versions of those colors.
ansiUnderlineOffset → const int
This offset can be added to the basic 0-15 ansi color numbers to get underline versions of those colors.