diff --git a/CHANGELOG.md b/CHANGELOG.md index 8132960..ae4893f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ Versions before 0.8.0 are in the [git tags](https://github.com/leemour/cli-core/ Every entry says what changed as a caller sees it, why, and what to watch for — the rules are [`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog). +## 0.17.2 — 07.10.2026 + +### Added + +- **`indent(text, spaces)` shifts every line of a block right.** A step's body under its heading, or a + QR code, can sit indented in a setup screen. Empty lines stay empty, so no trailing spaces are printed. + ## 0.17.1 — 04.10.2026 ### Fixed diff --git a/package.json b/package.json index 1da3315..1ff1d6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@leemour/cli-core", - "version": "0.17.1", + "version": "0.17.2", "description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks", "license": "MIT", "author": "Viacheslav Ptsarev", diff --git a/src/index.ts b/src/index.ts index f98b907..1748132 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ export { brokenKeyring, type KeyringStore, memoryKeyring, systemKeyring } from " export { type Logger, noopLogger } from "./logger.js" export { createFileLogger, type FileLogger, type FileLoggerOptions, REDACTED_FIELDS } from "./logging.js" export { configFilePath, type Paths, type PathsOptions, pathsAreOverridden, resolvePaths } from "./paths.js" -export { type PrettyOptions, renderPretty } from "./pretty.js" +export { indent, type PrettyOptions, renderPretty } from "./pretty.js" export { createRenderer, RENDER_FORMATS, diff --git a/src/pretty.test.ts b/src/pretty.test.ts new file mode 100644 index 0000000..0529d38 --- /dev/null +++ b/src/pretty.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from "vitest" +import { indent } from "./pretty.js" + +describe("indent", () => { + it("shifts every line and leaves empty lines empty", () => { + expect(indent("[1/5] Title\n\nbody", 2)).toBe(" [1/5] Title\n\n body") + }) + + it("leaves the text alone at zero", () => { + expect(indent("a\nb", 0)).toBe("a\nb") + }) +}) diff --git a/src/pretty.ts b/src/pretty.ts index bf572d1..5efd60b 100644 --- a/src/pretty.ts +++ b/src/pretty.ts @@ -32,6 +32,13 @@ export const renderPretty = (value: unknown, options: PrettyOptions): string => return renderJson(value) } +/** Shifts every line right; an empty line stays empty, so no trailing spaces reach the terminal. */ +export const indent = (text: string, spaces: number): string => + text + .split("\n") + .map((line) => (line === "" ? line : `${" ".repeat(spaces)}${line}`)) + .join("\n") + type Row = Record const palette = (color: boolean) => ({