-
Notifications
You must be signed in to change notification settings - Fork 8
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
12 changed files
with
299 additions
and
24 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,153 @@ | ||
module Chalk | ||
|
||
#nowarn "3390" // disable warnings for invalid XML comments | ||
|
||
open System | ||
open Fable.Core | ||
open Fable.Core.JS | ||
|
||
type ColorSupportLevel = | ||
| L0 = 0 | ||
| L1 = 1 | ||
| L2 = 2 | ||
| L3 = 3 | ||
|
||
type ColorInfo = U2<ColorSupportLevel, bool> | ||
|
||
type [<AllowNullLiteral>] ChalkInstance = | ||
[<Emit("$0($1...)")>] abstract draw: [<ParamArray>] text: obj[] -> string | ||
[<Emit("$0($1...)")>] abstract Item: [<ParamArray>] text: obj[] -> string | ||
/// <summary> | ||
/// The color support for Chalk. | ||
/// | ||
/// By default, color support is automatically detected based on the environment. | ||
/// | ||
/// Levels: | ||
/// - <c>0</c> - All colors disabled. | ||
/// - <c>1</c> - Basic 16 colors support. | ||
/// - <c>2</c> - ANSI 256 colors support. | ||
/// - <c>3</c> - Truecolor 16 million colors support. | ||
/// </summary> | ||
abstract level: ColorSupportLevel with get, set | ||
/// <summary>Use RGB values to set text color.</summary> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.rgb(222, 173, 237); | ||
/// </code> | ||
/// </example> | ||
abstract rgb: float * float * float -> ChalkInstance | ||
/// <summary>Use HEX value to set text color.</summary> | ||
/// <param name="color">Hexadecimal value representing the desired color.</param> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.hex('#DEADED'); | ||
/// </code> | ||
/// </example> | ||
abstract hex: string -> ChalkInstance | ||
/// <summary>Use an <see href="https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit">8-bit unsigned number</see> to set text color.</summary> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.ansi256(201); | ||
/// </code> | ||
/// </example> | ||
abstract ansi256: float -> ChalkInstance | ||
/// <summary>Use RGB values to set background color.</summary> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.bgRgb(222, 173, 237); | ||
/// </code> | ||
/// </example> | ||
abstract bgRgb: float * float * float -> ChalkInstance | ||
/// <summary>Use HEX value to set background color.</summary> | ||
/// <param name="color">Hexadecimal value representing the desired color.</param> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.bgHex('#DEADED'); | ||
/// </code> | ||
/// </example> | ||
abstract bgHex: string -> ChalkInstance | ||
/// <summary>Use a <see href="https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit">8-bit unsigned number</see> to set background color.</summary> | ||
/// <example> | ||
/// <code> | ||
/// import chalk from 'chalk'; | ||
/// chalk.bgAnsi256(201); | ||
/// </code> | ||
/// </example> | ||
abstract bgAnsi256: float -> ChalkInstance | ||
/// Modifier: Reset the current style. | ||
abstract reset: ChalkInstance | ||
/// Modifier: Make the text bold. | ||
abstract bold: ChalkInstance | ||
/// Modifier: Make the text have lower opacity. | ||
abstract dim: ChalkInstance | ||
/// Modifier: Make the text italic. *(Not widely supported)* | ||
abstract italic: ChalkInstance | ||
/// Modifier: Put a horizontal line below the text. *(Not widely supported)* | ||
abstract underline: ChalkInstance | ||
/// Modifier: Put a horizontal line above the text. *(Not widely supported)* | ||
abstract overline: ChalkInstance | ||
/// Modifier: Invert background and foreground colors. | ||
abstract inverse: ChalkInstance | ||
/// Modifier: Print the text but make it invisible. | ||
abstract hidden: ChalkInstance | ||
/// Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)* | ||
abstract strikethrough: ChalkInstance | ||
/// Modifier: Print the text only when Chalk has a color level above zero. | ||
/// | ||
/// Can be useful for things that are purely cosmetic. | ||
abstract visible: ChalkInstance | ||
abstract black: ChalkInstance | ||
abstract red: ChalkInstance | ||
abstract green: ChalkInstance | ||
abstract yellow: ChalkInstance | ||
abstract blue: ChalkInstance | ||
abstract magenta: ChalkInstance | ||
abstract cyan: ChalkInstance | ||
abstract white: ChalkInstance | ||
abstract gray: ChalkInstance | ||
abstract grey: ChalkInstance | ||
abstract blackBright: ChalkInstance | ||
abstract redBright: ChalkInstance | ||
abstract greenBright: ChalkInstance | ||
abstract yellowBright: ChalkInstance | ||
abstract blueBright: ChalkInstance | ||
abstract magentaBright: ChalkInstance | ||
abstract cyanBright: ChalkInstance | ||
abstract whiteBright: ChalkInstance | ||
abstract bgBlack: ChalkInstance | ||
abstract bgRed: ChalkInstance | ||
abstract bgGreen: ChalkInstance | ||
abstract bgYellow: ChalkInstance | ||
abstract bgBlue: ChalkInstance | ||
abstract bgMagenta: ChalkInstance | ||
abstract bgCyan: ChalkInstance | ||
abstract bgWhite: ChalkInstance | ||
abstract bgGray: ChalkInstance | ||
abstract bgGrey: ChalkInstance | ||
abstract bgBlackBright: ChalkInstance | ||
abstract bgRedBright: ChalkInstance | ||
abstract bgGreenBright: ChalkInstance | ||
abstract bgYellowBright: ChalkInstance | ||
abstract bgBlueBright: ChalkInstance | ||
abstract bgMagentaBright: ChalkInstance | ||
abstract bgCyanBright: ChalkInstance | ||
abstract bgWhiteBright: ChalkInstance | ||
|
||
/// <summary> | ||
/// Main Chalk object that allows to chain styles together. | ||
/// | ||
/// Call the last one as a method with a string argument. | ||
/// | ||
/// Order doesn't matter, and later styles take precedent in case of a conflict. | ||
/// | ||
/// This simply means that <c>chalk.red.yellow.green</c> is equivalent to <c>chalk.green</c>. | ||
/// </summary> | ||
let [<ImportDefault("chalk")>] chalk: ChalkInstance = jsNative | ||
let [<Import("chalkStderr","chalk")>] chalkStderr: ChalkInstance = jsNative | ||
let [<Import("supportsColor","chalk")>] supportsColor: ColorInfo = jsNative | ||
let [<Import("supportsColorStderr","chalk")>] supportsColorStderr: ColorInfo = jsNative |
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,68 @@ | ||
module Codeframe | ||
|
||
#nowarn "3390" // disable warnings for invalid XML comments | ||
|
||
open System | ||
open Fable.Core | ||
open Fable.Core.JS | ||
|
||
type Position = {| line: int; column: int option |} | ||
|
||
type [<AllowNullLiteral>] SourceLocation = | ||
abstract start: Position with get, set | ||
abstract ``end``: Position option with get, set | ||
|
||
type [<AllowNullLiteral>] BabelCodeFrameOptions = | ||
/// Syntax highlight the code as JavaScript for terminals. default: false | ||
abstract highlightCode: bool option with get, set | ||
/// The number of lines to show above the error. default: 2 | ||
abstract linesAbove: int option with get, set | ||
/// The number of lines to show below the error. default: 3 | ||
abstract linesBelow: int option with get, set | ||
/// Forcibly syntax highlight the code as JavaScript (for non-terminals); | ||
/// overrides highlightCode. | ||
/// default: false | ||
abstract forceColor: bool option with get, set | ||
/// Pass in a string to be displayed inline (if possible) next to the | ||
/// highlighted location in the code. If it can't be positioned inline, | ||
/// it will be placed above the code frame. | ||
/// default: nothing | ||
abstract message: string option with get, set | ||
|
||
type [<AllowNullLiteral>] ICodeframe = | ||
[<Emit("$0($1...)")>] | ||
abstract Invoke: rawLines: string * lineNumber: int * colNumber: int * ?options: BabelCodeFrameOptions -> string | ||
|
||
type [<AllowNullLiteral>] ICodeframeColumns = | ||
[<Emit("$0($1...)")>] | ||
abstract Invoke: rawLines: string * location: SourceLocation * ?options: BabelCodeFrameOptions -> string | ||
|
||
let [<ImportDefault("@babel/code-frame")>] codeFrame: ICodeframe = jsNative | ||
|
||
let [<Import("codeFrameColumns", "@babel/code-frame")>] codeFrameColumns: ICodeframeColumns = jsNative | ||
|
||
type Codeframe = | ||
static member CreateColumns(rawLines, startLine, ?startCol, ?endLine, ?endCol, ?highlightCode, ?linesAbove, ?linesBelow, ?forceColor, ?message) = | ||
let options : BabelCodeFrameOptions = JsInterop.createEmpty | ||
options.highlightCode <- highlightCode | ||
options.linesAbove <- linesAbove | ||
options.linesBelow <- linesBelow | ||
options.forceColor <- forceColor | ||
options.message <- message | ||
let startPos = {| line = startLine; column = startCol |} | ||
let endPos = | ||
match endLine with | ||
| Some x -> Some {| line = x; column = endCol |} | ||
| None -> None | ||
let loc : SourceLocation = JsInterop.createEmpty | ||
loc.start <- startPos | ||
loc.``end`` <- endPos | ||
codeFrameColumns.Invoke(rawLines, loc, options) | ||
static member Create(rawLines, line, col, ?highlightCode, ?linesAbove, ?linesBelow, ?forceColor, ?message) = | ||
let options : BabelCodeFrameOptions = JsInterop.createEmpty | ||
options.highlightCode <- highlightCode | ||
options.linesAbove <- linesAbove | ||
options.linesBelow <- linesBelow | ||
options.forceColor <- forceColor | ||
options.message <- message | ||
codeFrame.Invoke(rawLines, line, col, options) |
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
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
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
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
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
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
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
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
Oops, something went wrong.