-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod.ts
86 lines (77 loc) · 1.9 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { replacer, tags } from "./utils.ts"
import { toAnsi } from "./htmlToAnsi.ts"
export { drawImage } from "./imageToAnsi.ts"
declare global {
interface String {
toColor(): string
}
}
String.prototype.toColor = function (): string {
return html(this as string);
}
// tslint:disable-next-line
export class terminal {
// @ts-ignore
static log(...args): void {
args = processArgs(args)
console.log(...args)
}
// @ts-ignore
static trace(...args): void {
args = processArgs(args)
console.trace(...args)
}
// @ts-ignore
static warn(...args): void {
args = processArgs(args)
console.warn(...args)
}
// @ts-ignore
static error(...args): void {
args = processArgs(args)
console.error(...args)
}
// @ts-ignore
static debug(...args): void {
args = processArgs(args)
console.debug(...args)
}
}
export const colorize = function (input: string): string {
return replacer(input)
}
export const html = function (htm: string): string {
return toAnsi(htm);
}
export const list = function (): void {
Object.keys(tags).forEach(key => {
if (key.indexOf("/") < 0) {
const tagName = key.replace("<", "").replace(">", "")
const tagStart = `<${tagName}>`
const tagEnd = `</${tagName}>`
let text = `-->${tagStart}tag: ${tagName}${tagEnd}`
text = replacer(text)
console.log(text)
}
})
}
// Extension
// @ts-ignore
function processArgs(args) {
// @ts-ignore
return args.map((value) => {
if (typeof value === "string") {
return replacer(value)
} else {
return value
}
})
}
// CLI
if (Deno.args.length === 1) {
let cmd = Deno.args[0]
cmd = cmd.replace("--", "").replace("-", "")
if (cmd === "list") {
list()
}
}