Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
76 lines (63 loc) · 1.91 KB

File metadata and controls

76 lines (63 loc) · 1.91 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import { LoggerPriority } from "jacdac-ts"
export interface CmdOptions {
noVerify?: boolean
}
export const GENDIR = ".devicescript"
export const LIBDIR = `${GENDIR}/lib`
export const BINDIR = `${GENDIR}/bin`
export const log = console.log
export function debug(...args: any[]) {
console.debug(...wrapArgs(34, args))
}
export function error(...args: any[]) {
console.error(...wrapArgs(91, args))
}
export function fatal(msg: string): never {
error("fatal error: " + msg)
process.exit(1)
}
export let consoleColors = true
export function setConsoleColors(enabled: boolean) {
consoleColors = !!enabled
}
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
export function wrapColor(n: number | string, message: string) {
if (consoleColors) return `\x1B[${n}m${message}\x1B[0m`
else return message
}
function wrapArgs(color: number, args: any[]) {
if (
consoleColors &&
args.every(e => typeof e == "string" || typeof e == "number")
) {
// if it's just strings & numbers use the coloring
const msg = args.join(" ")
return [wrapColor(color, msg)]
} else {
// otherwise use the console.log() etc built-in formatting
return args
}
}
export function logToConsole(priority: LoggerPriority, message: string) {
switch (priority) {
case LoggerPriority.Debug:
console.debug(wrapColor(34, message))
break
case LoggerPriority.Log:
console.log(wrapColor(96, message))
break
case LoggerPriority.Warning:
console.warn(wrapColor(93, message))
break
case LoggerPriority.Error:
console.error(wrapColor(91, message))
break
}
}
export let isVerbose = false
export function setVerbose(v: boolean) {
isVerbose = v
}
export function verboseLog(msg: string) {
if (isVerbose) console.debug(wrapColor(90, msg))
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.