@reliverse/relinka 1.2.9 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { re } from "@reliverse/relico";
2
+ import { isUnicodeSupported } from "@reliverse/runtime";
2
3
  import wrapAnsi from "wrap-ansi";
3
4
  import { colorMap, typographyMap } from "./mapping.js";
4
- import { isUnicodeSupported } from "./platforms.js";
5
5
  import {
6
6
  deleteLastLines,
7
7
  getExactTerminalWidth,
@@ -1,6 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export * from "./terminal.js";
3
- export * from "./platforms.js";
4
3
  export * from "./mapping.js";
5
4
  export * from "./variants.js";
6
5
  export * from "./messages.js";
@@ -1,6 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export * from "./terminal.js";
3
- export * from "./platforms.js";
4
3
  export * from "./mapping.js";
5
4
  export * from "./variants.js";
6
5
  export * from "./messages.js";
@@ -1,4 +1,4 @@
1
- import isUnicodeSupported from "is-unicode-supported";
1
+ import { isUnicodeSupported } from "@reliverse/runtime";
2
2
  import stringWidth from "string-width";
3
3
  import { BasicReporter } from "../../components/reporters/basic.js";
4
4
  import { box } from "../../utils/box.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reliverse/relinka",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "author": "blefnk",
5
5
  "type": "module",
6
6
  "description": "@reliverse/relinka is a powerful logger for your terminal.",
@@ -57,6 +57,7 @@
57
57
  "dependencies": {
58
58
  "@figliolia/chalk-animation": "^1.0.4",
59
59
  "@reliverse/relico": "^1.0.0",
60
+ "@reliverse/runtime": "^1.0.1",
60
61
  "@sinclair/typebox": "^0.34.14",
61
62
  "ansi-diff-stream": "^1.2.1",
62
63
  "ansi-escapes": "^7.0.0",
@@ -75,7 +76,6 @@
75
76
  "get-pixels": "^3.3.3",
76
77
  "globby": "^14.0.2",
77
78
  "gradient-string": "^3.0.0",
78
- "is-unicode-supported": "^2.1.0",
79
79
  "kleur": "^4.1.5",
80
80
  "log-update": "^6.1.0",
81
81
  "mri": "^1.2.0",
@@ -100,29 +100,29 @@
100
100
  "@arethetypeswrong/cli": "^0.17.3",
101
101
  "@biomejs/biome": "1.9.4",
102
102
  "@cspell/dict-npm": "^5.1.23",
103
- "@eslint/js": "^9.18.0",
104
- "@eslint/json": "^0.9.1",
105
- "@eslint/markdown": "^6.2.1",
103
+ "@eslint/js": "^9.19.0",
104
+ "@eslint/json": "^0.10.0",
105
+ "@eslint/markdown": "^6.2.2",
106
106
  "@stylistic/eslint-plugin": "^2.13.0",
107
107
  "@types/ansi-diff-stream": "^1.2.3",
108
- "@types/bun": "^1.1.18",
108
+ "@types/bun": "^1.2.0",
109
109
  "@types/chalk-animation": "^1.6.3",
110
110
  "@types/eslint__js": "^8.42.3",
111
111
  "@types/figlet": "^1.7.0",
112
112
  "@types/fs-extra": "^11.0.4",
113
113
  "@types/mute-stream": "^0.0.4",
114
- "@types/node": "^22.10.7",
114
+ "@types/node": "^22.10.10",
115
115
  "@types/sentencer": "^0.2.3",
116
116
  "@types/signal-exit": "^3.0.4",
117
117
  "@types/strip-comments": "^2.0.4",
118
118
  "@types/window-size": "^1.1.4",
119
119
  "c12": "^2.0.1",
120
120
  "citty": "^0.1.6",
121
- "eslint": "^9.18.0",
121
+ "eslint": "^9.19.0",
122
122
  "eslint-plugin-perfectionist": "^4.7.0",
123
123
  "execa": "^9.5.2",
124
124
  "jiti": "^2.4.2",
125
- "knip": "^5.42.3",
125
+ "knip": "^5.43.3",
126
126
  "mock-stdin": "^1.0.0",
127
127
  "printj": "^1.3.1",
128
128
  "sentencer": "^0.2.1",
@@ -131,6 +131,6 @@
131
131
  "typescript": "^5.7.3",
132
132
  "typescript-eslint": "^8.21.0",
133
133
  "unbuild": "^3.3.1",
134
- "vitest": "^3.0.3"
134
+ "vitest": "^3.0.4"
135
135
  }
136
136
  }
@@ -1,10 +0,0 @@
1
- /**
2
- * Determines if Unicode is supported in the current terminal.
3
- * @returns {boolean} True if Unicode is supported, false otherwise.
4
- */
5
- export declare function isUnicodeSupported(): boolean;
6
- /**
7
- * Determines the current terminal name based on environment variables.
8
- * @returns {string} The name of the current terminal or "Unknown" if it cannot be determined.
9
- */
10
- export declare function getCurrentTerminalName(): string;
@@ -1,67 +0,0 @@
1
- import { env, isWindows, isLinux, isMacOS } from "std-env";
2
- export function isUnicodeSupported() {
3
- if (isLinux) {
4
- return env["TERM"] !== "linux";
5
- }
6
- return env["WT_SESSION"] !== void 0 || env["TERMINUS_SUBLIME"] !== void 0 || env["ConEmuTask"] === "{cmd::Cmder}" || env["TERM_PROGRAM"] === "Terminus-Sublime" || env["TERM_PROGRAM"] === "vscode" || env["TERM"] === "xterm-256color" || env["TERM"] === "alacritty" || env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
7
- }
8
- export function getCurrentTerminalName() {
9
- const termProgram = env["TERM_PROGRAM"];
10
- const term = env["TERM"];
11
- const terminalEmulator = env["TERMINAL_EMULATOR"];
12
- if (termProgram) {
13
- switch (termProgram.toLowerCase()) {
14
- case "vscode":
15
- return "VSCode Terminal";
16
- case "terminus-sublime":
17
- return "Terminus Sublime";
18
- case "hyper":
19
- return "Hyper";
20
- case "iterm.app":
21
- case "iterm":
22
- return "iTerm2";
23
- case "alacritty":
24
- return "Alacritty";
25
- case "wezterm":
26
- return "WezTerm";
27
- case "terminus":
28
- return "Terminus";
29
- default:
30
- return `TERM_PROGRAM: ${termProgram}`;
31
- }
32
- }
33
- if (terminalEmulator) {
34
- switch (terminalEmulator.toLowerCase()) {
35
- case "jetbrains-jediterm":
36
- return "JetBrains JediTerm";
37
- case "cmder":
38
- return "Cmder";
39
- case "conemu":
40
- return "ConEmu";
41
- default:
42
- return `TERMINAL_EMULATOR: ${terminalEmulator}`;
43
- }
44
- }
45
- if (term) {
46
- switch (term.toLowerCase()) {
47
- case "xterm-256color":
48
- return "Xterm 256 Color";
49
- case "alacritty":
50
- return "Alacritty";
51
- case "xterm":
52
- return "Xterm";
53
- case "linux":
54
- return "Linux Console Kernel";
55
- default:
56
- return `TERM: ${term}`;
57
- }
58
- }
59
- if (isWindows) {
60
- return "Windows Terminal";
61
- } else if (isMacOS) {
62
- return "macOS Terminal";
63
- } else if (isLinux) {
64
- return "Linux Terminal";
65
- }
66
- return "Unknown Terminal";
67
- }
@@ -1,80 +0,0 @@
1
- import type { Static } from "@sinclair/typebox";
2
- /** The entire relico config */
3
- declare const RelicoConfigSchema: import("@sinclair/typebox").TObject<{
4
- colorLevel: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<0>, import("@sinclair/typebox").TLiteral<1>, import("@sinclair/typebox").TLiteral<2>, import("@sinclair/typebox").TLiteral<3>]>>;
5
- customColors: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TTuple<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString, import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>]>>>;
6
- }>;
7
- export type RelicoConfig = Static<typeof RelicoConfigSchema>;
8
- type BaseColorMap = {
9
- reset: [string, string];
10
- bold: [string, string, string];
11
- dim: [string, string, string];
12
- italic: [string, string];
13
- underline: [string, string];
14
- inverse: [string, string];
15
- hidden: [string, string];
16
- strikethrough: [string, string];
17
- black: [string, string];
18
- red: [string, string];
19
- green: [string, string];
20
- yellow: [string, string];
21
- blue: [string, string];
22
- magenta: [string, string];
23
- cyan: [string, string];
24
- white: [string, string];
25
- gray: [string, string];
26
- bgBlack: [string, string];
27
- bgRed: [string, string];
28
- bgGreen: [string, string];
29
- bgYellow: [string, string];
30
- bgBlue: [string, string];
31
- bgMagenta: [string, string];
32
- bgCyan: [string, string];
33
- bgWhite: [string, string];
34
- blackBright: [string, string];
35
- redBright: [string, string];
36
- greenBright: [string, string];
37
- yellowBright: [string, string];
38
- blueBright: [string, string];
39
- magentaBright: [string, string];
40
- cyanBright: [string, string];
41
- whiteBright: [string, string];
42
- bgBlackBright: [string, string];
43
- bgRedBright: [string, string];
44
- bgGreenBright: [string, string];
45
- bgYellowBright: [string, string];
46
- bgBlueBright: [string, string];
47
- bgMagentaBright: [string, string];
48
- bgCyanBright: [string, string];
49
- bgWhiteBright: [string, string];
50
- };
51
- /**
52
- * Allows user to update the relico config at runtime.
53
- */
54
- export declare function configure(userInput: unknown): void;
55
- /** Return a read-only copy of current config */
56
- export declare function getConfig(): RelicoConfig;
57
- /** Retrieve a specific color function by name (or fallback to reset) */
58
- export declare function getColor(name: string): (text: string | number) => string;
59
- /** Colorize text with a named color function */
60
- export declare function colorize(name: string, text: string | number): string;
61
- /** Force-set the color level (0=none,1=basic,2=256,3=truecolor) */
62
- export declare function setColorLevel(level: 0 | 1 | 2 | 3): void;
63
- /**
64
- * If truecolor is available (and level=3),
65
- * return a custom rgb(...) color function. Otherwise identity.
66
- */
67
- export declare function rgb(r: number, g: number, b: number): (input: string | number) => string;
68
- /** Type for the re object with explicit color properties */
69
- type ReObject = {
70
- [K in keyof BaseColorMap]: (text: string | number) => string;
71
- };
72
- /** Just a small proxy object returning the dynamic color functions */
73
- export declare const re: ReObject;
74
- export declare const colorSupport: {
75
- isColorSupported: boolean;
76
- isForced: boolean;
77
- isDisabled: boolean;
78
- terminalName: string;
79
- };
80
- export {};
@@ -1,213 +0,0 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { Value } from "@sinclair/typebox/value";
3
- import { env, isWindows } from "std-env";
4
- import { getCurrentTerminalName } from "./platforms.js";
5
- const ColorDefinitionSchema = Type.Tuple([
6
- Type.String(),
7
- Type.String(),
8
- Type.Optional(Type.String())
9
- ]);
10
- const ColorMapSchema = Type.Record(Type.String(), ColorDefinitionSchema);
11
- const RelicoConfigSchema = Type.Object(
12
- {
13
- // The level of color support (0=none, 1=basic, 2=256, 3=truecolor)
14
- colorLevel: Type.Optional(
15
- Type.Union([
16
- Type.Literal(0),
17
- Type.Literal(1),
18
- Type.Literal(2),
19
- Type.Literal(3)
20
- ])
21
- ),
22
- // An optional set of overrides or new color definitions
23
- customColors: Type.Optional(ColorMapSchema)
24
- },
25
- { additionalProperties: false }
26
- );
27
- const defaultConfig = {
28
- colorLevel: void 0,
29
- customColors: void 0
30
- };
31
- const { argv = [] } = typeof process === "undefined" ? {} : process;
32
- const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
33
- const isForced = "FORCE_COLOR" in env || argv.includes("--color");
34
- const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
35
- const isCompatibleTerminal = typeof process !== "undefined" && process.stdout && process.stdout.isTTY && env["TERM"] !== "dumb";
36
- const colorterm = (env["COLORTERM"] || "").toLowerCase();
37
- const supportsTrueColor = colorterm === "truecolor" || colorterm === "24bit";
38
- function detectColorLevel() {
39
- if (isDisabled) return 0;
40
- if (isForced) return 3;
41
- if (supportsTrueColor) return 3;
42
- if (isWindows) return 2;
43
- if (isCI) return 2;
44
- if (isCompatibleTerminal) {
45
- return 2;
46
- }
47
- return 0;
48
- }
49
- const baseColors = {
50
- // Reset
51
- reset: ["\x1B[0m", "\x1B[0m"],
52
- // Styles
53
- bold: ["\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"],
54
- dim: ["\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"],
55
- italic: ["\x1B[3m", "\x1B[23m"],
56
- underline: ["\x1B[4m", "\x1B[24m"],
57
- inverse: ["\x1B[7m", "\x1B[27m"],
58
- hidden: ["\x1B[8m", "\x1B[28m"],
59
- strikethrough: ["\x1B[9m", "\x1B[29m"],
60
- // Basic
61
- black: ["\x1B[30m", "\x1B[39m"],
62
- red: ["\x1B[31m", "\x1B[39m"],
63
- green: ["\x1B[32m", "\x1B[39m"],
64
- yellow: ["\x1B[33m", "\x1B[39m"],
65
- blue: ["\x1B[34m", "\x1B[39m"],
66
- magenta: ["\x1B[35m", "\x1B[39m"],
67
- cyan: ["\x1B[36m", "\x1B[39m"],
68
- white: ["\x1B[37m", "\x1B[39m"],
69
- gray: ["\x1B[90m", "\x1B[39m"],
70
- // Background
71
- bgBlack: ["\x1B[40m", "\x1B[49m"],
72
- bgRed: ["\x1B[41m", "\x1B[49m"],
73
- bgGreen: ["\x1B[42m", "\x1B[49m"],
74
- bgYellow: ["\x1B[43m", "\x1B[49m"],
75
- bgBlue: ["\x1B[44m", "\x1B[49m"],
76
- bgMagenta: ["\x1B[45m", "\x1B[49m"],
77
- bgCyan: ["\x1B[46m", "\x1B[49m"],
78
- bgWhite: ["\x1B[47m", "\x1B[49m"],
79
- // Bright
80
- blackBright: ["\x1B[90m", "\x1B[39m"],
81
- redBright: ["\x1B[91m", "\x1B[39m"],
82
- greenBright: ["\x1B[92m", "\x1B[39m"],
83
- yellowBright: ["\x1B[93m", "\x1B[39m"],
84
- blueBright: ["\x1B[94m", "\x1B[39m"],
85
- magentaBright: ["\x1B[95m", "\x1B[39m"],
86
- cyanBright: ["\x1B[96m", "\x1B[39m"],
87
- whiteBright: ["\x1B[97m", "\x1B[39m"],
88
- // Bright background
89
- bgBlackBright: ["\x1B[100m", "\x1B[49m"],
90
- bgRedBright: ["\x1B[101m", "\x1B[49m"],
91
- bgGreenBright: ["\x1B[102m", "\x1B[49m"],
92
- bgYellowBright: ["\x1B[103m", "\x1B[49m"],
93
- bgBlueBright: ["\x1B[104m", "\x1B[49m"],
94
- bgMagentaBright: ["\x1B[105m", "\x1B[49m"],
95
- bgCyanBright: ["\x1B[106m", "\x1B[49m"],
96
- bgWhiteBright: ["\x1B[107m", "\x1B[49m"]
97
- };
98
- const windowsTerminalColors = {
99
- ...baseColors,
100
- red: ["\x1B[38;2;255;85;85m", "\x1B[39m"],
101
- green: ["\x1B[38;2;80;250;123m", "\x1B[39m"],
102
- yellow: ["\x1B[38;2;241;250;140m", "\x1B[39m"],
103
- blue: ["\x1B[38;2;98;114;164m", "\x1B[39m"],
104
- magenta: ["\x1B[38;2;255;121;198m", "\x1B[39m"],
105
- cyan: ["\x1B[38;2;139;233;253m", "\x1B[39m"]
106
- };
107
- function replaceClose(str, close, replace, index) {
108
- let result = "", cursor = 0;
109
- do {
110
- result += str.substring(cursor, index) + replace;
111
- cursor = index + close.length;
112
- index = str.indexOf(close, cursor);
113
- } while (~index);
114
- return result + str.substring(cursor);
115
- }
116
- function createFormatter(open, close, replace = open) {
117
- return (input) => {
118
- const string = String(input);
119
- const idx = string.indexOf(close, open.length);
120
- return ~idx ? open + replaceClose(string, close, replace, idx) + close : open + string + close;
121
- };
122
- }
123
- let _config = {
124
- ...defaultConfig,
125
- colorLevel: detectColorLevel()
126
- // initial detect
127
- };
128
- let _colorMap = {};
129
- let _colorFunctions = {};
130
- function buildColorMap(cfg) {
131
- const terminalName = getCurrentTerminalName();
132
- const isWinTerm = terminalName === "Windows Terminal";
133
- if (cfg.colorLevel === 0) {
134
- const map = {};
135
- Object.keys(baseColors).forEach((k) => {
136
- map[k] = ["", "", ""];
137
- });
138
- return map;
139
- }
140
- const builtIn = isWinTerm && cfg.colorLevel === 3 ? { ...windowsTerminalColors } : { ...baseColors };
141
- if (cfg.customColors) {
142
- for (const [k, v] of Object.entries(cfg.customColors)) {
143
- builtIn[k] = v;
144
- }
145
- }
146
- return builtIn;
147
- }
148
- function initColorFunctions() {
149
- _colorFunctions = {};
150
- if (_config.colorLevel === 0) {
151
- for (const k of Object.keys(baseColors)) {
152
- _colorFunctions[k] = (text) => String(text);
153
- }
154
- return;
155
- }
156
- for (const [key, [open, close, replace]] of Object.entries(_colorMap)) {
157
- _colorFunctions[key] = createFormatter(open, close, replace);
158
- }
159
- }
160
- function rebuild() {
161
- _colorMap = buildColorMap(_config);
162
- initColorFunctions();
163
- }
164
- rebuild();
165
- export function configure(userInput) {
166
- const newObj = typeof userInput === "object" && userInput !== null ? { ..._config, ...userInput } : { ..._config };
167
- try {
168
- const parsed = Value.Cast(RelicoConfigSchema, newObj);
169
- _config = parsed;
170
- } catch (err) {
171
- console.warn("Invalid relico config:", err);
172
- return;
173
- }
174
- rebuild();
175
- }
176
- export function getConfig() {
177
- return { ..._config };
178
- }
179
- function identityColor(text) {
180
- return String(text);
181
- }
182
- export function getColor(name) {
183
- return _colorFunctions[name] || _colorFunctions["reset"] || identityColor;
184
- }
185
- export function colorize(name, text) {
186
- const fn = getColor(name);
187
- return fn(text);
188
- }
189
- export function setColorLevel(level) {
190
- configure({ colorLevel: level });
191
- }
192
- export function rgb(r, g, b) {
193
- if (_config.colorLevel === 3) {
194
- const open = `\x1B[38;2;${r};${g};${b}m`;
195
- const close = "\x1B[39m";
196
- return createFormatter(open, close);
197
- }
198
- return identityColor;
199
- }
200
- export const re = new Proxy(
201
- {},
202
- {
203
- get(_target, prop) {
204
- return getColor(prop);
205
- }
206
- }
207
- );
208
- export const colorSupport = {
209
- isColorSupported: getConfig().colorLevel !== 0,
210
- isForced,
211
- isDisabled,
212
- terminalName: getCurrentTerminalName()
213
- };