-
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
9 changed files
with
112 additions
and
23 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,21 +0,0 @@ | ||
import { Confirm, MultiSelect, Password, Select, SelectOption } from "~/lib/prompts/" | ||
|
||
// const p = await <Text message="Test" /> | ||
// const p2 = await <Password message="Password" /> | ||
// const p3 = await <Confirm message="R u sure?" /> | ||
|
||
// const p4 = await ( | ||
// <Select message="Choose"> | ||
// <SelectOption value="1" hint="One" /> | ||
// <SelectOption value={{ key: "val" }} label="Empty" /> | ||
// <SelectOption value="3" label="Three" hint="Woops" /> | ||
// </Select> | ||
// ) | ||
|
||
// const p5 = ( | ||
// <MultiSelect message="Choose" required> | ||
// <SelectOption value="1" hint="One" /> | ||
// <SelectOption value="2" label="Two" hint="Test" /> | ||
// <SelectOption value="3" label="Three" hint="Woops" /> | ||
// </MultiSelect> | ||
// ) | ||
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,6 @@ | ||
import c from "picocolors" | ||
import { S } from "./symbols" | ||
|
||
export function Cancel({ message = "" }: { message?: string }) { | ||
process.stdout.write(`${c.gray(S.BAR_END)} ${c.red(message)}\n\n`) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import c from "picocolors" | ||
import { S } from "./symbols" | ||
|
||
export function Intro({ title = "" }: { title?: string }) { | ||
process.stdout.write(`${c.gray(S.BAR_START)} ${title}\n`) | ||
} |
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,43 @@ | ||
import c from "picocolors" | ||
import { S } from "./symbols" | ||
import type { LogMessageOptions } from "./types" | ||
|
||
function Message({ message, symbol }: LogMessageOptions = {}) { | ||
const parts = [`${c.gray(S.BAR)}`] | ||
|
||
if (message) { | ||
const [firstLine, ...lines] = message.split("\n") | ||
parts.push(`${symbol} ${firstLine}`, ...lines.map(ln => `${c.gray(S.BAR)} ${ln}`)) | ||
} | ||
|
||
process.stdout.write(`${parts.join("\n")}\n`) | ||
} | ||
|
||
function Info({ message }: { message: string }) { | ||
Message({ message, symbol: c.blue(S.INFO) }) | ||
} | ||
|
||
function Success({ message }: { message: string }) { | ||
Message({ message, symbol: c.green(S.SUCCESS) }) | ||
} | ||
|
||
function Step({ message }: { message: string }) { | ||
Message({ message, symbol: c.green(S.STEP_SUBMIT) }) | ||
} | ||
|
||
function Warning({ message }: { message: string }) { | ||
Message({ message, symbol: c.yellow(S.WARN) }) | ||
} | ||
|
||
function error({ message }: { message: string }) { | ||
Message({ message, symbol: c.red(S.ERROR) }) | ||
} | ||
|
||
export const Log = { | ||
Message, | ||
Info, | ||
Success, | ||
Step, | ||
Warning, | ||
Error: error, | ||
} |
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,39 @@ | ||
import c from "picocolors" | ||
import { S } from "./symbols" | ||
|
||
const strip = (str: string) => str.replace(ansiRegex(), "") | ||
|
||
export function Note({ message = "", title ="" }: { message?: string; title?: string }) { | ||
const lines = `\n${message}\n`.split("\n") | ||
const titleLen = strip(title).length | ||
|
||
const len = | ||
Math.max( | ||
lines.reduce((sum, ln) => { | ||
const line = strip(ln) | ||
return line.length > sum ? line.length : sum | ||
}, 0), | ||
titleLen | ||
) + 2 | ||
|
||
const msg = lines | ||
.map(ln => `${c.gray(S.BAR)} ${c.dim(ln)}${" ".repeat(len - strip(ln).length)}${c.gray(S.BAR)}`) | ||
.join("\n") | ||
|
||
process.stdout.write( | ||
`${c.gray(S.BAR)}\n${c.green(S.STEP_SUBMIT)} ${c.reset(title)} ${c.gray( | ||
S.BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S.CORNER_TOP_RIGHT | ||
)}\n${msg}\n${c.gray(S.CONNECT_LEFT + S.BAR_H.repeat(len + 2) + S.CORNER_BOTTOM_RIGHT)}\n` | ||
) | ||
} | ||
|
||
// Adapted from https://github.com/chalk/ansi-regex | ||
// @see LICENSE | ||
function ansiRegex() { | ||
const pattern = [ | ||
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", | ||
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", | ||
].join("|") | ||
|
||
return new RegExp(pattern, "g") | ||
} |
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,6 @@ | ||
import c from "picocolors" | ||
import { S } from "./symbols" | ||
|
||
export function Outro({ message = "" }: { message?: string }) { | ||
process.stdout.write(`${c.gray(S.BAR)}\n${c.gray(S.BAR_END)} ${message}\n\n`) | ||
} |
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,5 +1,5 @@ | ||
import type { Option } from "./types"; | ||
import type { Option } from "./types" | ||
|
||
export function SelectOption<Value>({ value, label, hint }: Option<Value>) { | ||
return { value, label, hint } | ||
} | ||
} |
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