forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
85 lines (77 loc) · 1.97 KB
/
Copy pathlogger.ts
File metadata and controls
85 lines (77 loc) · 1.97 KB
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
import { sprintf } from "std/fmt/printf.ts";
import * as color from "std/fmt/colors.ts";
import core from "@actions/core";
export type LoggerProps = core.AnnotationProperties & { content?: string };
const prettyPrint = (
message: string,
props: LoggerProps,
severity: "error" | "warning" = "warning",
) => {
const { file, startColumn, startLine } = props;
if (!startLine) return console.log(message);
const lines = (props.content ?? "").split("\n");
const error = [
color[severity === "error" ? "red" : "yellow"](severity),
message,
].join(" ");
const line = lines[startLine - 1].split("").map((char, i) => {
const startCol = (props.startColumn ?? 0) - 1;
const endCol = (props.endColumn ?? Infinity) - 1;
if (i >= startCol && i <= endCol) {
return color[severity === "error" ? "red" : "yellow"](char);
} else {
return char;
}
}).join("");
const pad = startLine.toString().length;
console.log(
[
color.underline(
sprintf(
"%s%s%s",
file,
startLine ? ":" + startLine : "",
startColumn ? ":" + startColumn : "",
),
),
sprintf(
"%*s│ %s",
pad,
color.dim(String(startLine - 1)),
color.dim(lines[startLine - 2]),
),
sprintf("%*s│ %s", pad, color.bold(String(startLine)), line),
sprintf(
"%*s│ %s",
pad,
color.dim(String(startLine + 1)),
color.dim(lines[startLine]),
),
sprintf(
"%*s╰─► %s",
pad,
"",
error,
),
undefined,
].join("\n"),
);
};
export const log = (
message: string,
props: LoggerProps,
severity: "error" | "warning" = "warning",
) => {
if (Deno.env.has("CI")) {
switch (severity) {
case "error":
core.error(message, props);
break;
case "warning":
core.warning(message, props);
break;
}
} else {
prettyPrint(message, props, severity);
}
};