Missed the utils file during previous commit
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
|
import util from "node:util";
|
||||||
|
|
||||||
import type { XOTemplate } from "@xo-cash/types";
|
import type { XOTemplate } from "@xo-cash/types";
|
||||||
|
import { generateTemplateIdentifier } from "@xo-cash/engine";
|
||||||
|
|
||||||
import type { CommandDependencies } from "./commands/types.js";
|
import type { CommandDependencies } from "./commands/types.js";
|
||||||
import { CommandError } from "./commands/types.js";
|
import { CommandError } from "./commands/types.js";
|
||||||
import { generateTemplateIdentifier } from "@xo-cash/engine";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate through the templates, trying to match the id or the name with the given input.
|
* Iterate through the templates, trying to match the id or the name with the given input.
|
||||||
@@ -57,3 +60,47 @@ export const resolveTemplate = async (
|
|||||||
`Template not found: ${query}`,
|
`Template not found: ${query}`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text formatting utilities for the CLI.
|
||||||
|
*
|
||||||
|
* Uses ANSI escape codes to format text.
|
||||||
|
*
|
||||||
|
* AI Generated links:
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Formatting
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Cursor_movement
|
||||||
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Screen_manipulation
|
||||||
|
*/
|
||||||
|
|
||||||
|
const BOLD = "\x1b[1m";
|
||||||
|
export const bold = (text: string) => `${BOLD}${text}${RESET}`;
|
||||||
|
|
||||||
|
const DIM = "\x1b[2m";
|
||||||
|
export const dim = (text: string) => `${DIM}${text}${RESET}`;
|
||||||
|
|
||||||
|
const UNDERLINE = "\x1b[4m";
|
||||||
|
export const underline = (text: string) => `${UNDERLINE}${text}${RESET}`;
|
||||||
|
|
||||||
|
const INVERSE = "\x1b[7m";
|
||||||
|
export const inverse = (text: string) => `${INVERSE}${text}${RESET}`;
|
||||||
|
|
||||||
|
const HIDDEN = "\x1b[8m";
|
||||||
|
export const hidden = (text: string) => `${HIDDEN}${text}${RESET}`;
|
||||||
|
|
||||||
|
const STRIKETHROUGH = "\x1b[9m";
|
||||||
|
export const strikethrough = (text: string) =>
|
||||||
|
`${STRIKETHROUGH}${text}${RESET}`;
|
||||||
|
|
||||||
|
const RESET = "\x1b[0m";
|
||||||
|
export const reset = (text: string) => `${RESET}${text}${RESET}`;
|
||||||
|
|
||||||
|
export const formatObject = (obj: unknown) => {
|
||||||
|
return util.inspect(obj, {
|
||||||
|
depth: null,
|
||||||
|
colors: true,
|
||||||
|
compact: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user