@dunkinfrunkin/mdcat 0.1.13 → 0.1.14
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.
- package/README.md +5 -2
- package/package.json +2 -2
- package/src/cli.js +7 -2
- package/src/tui.js +23 -7
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@dunkinfrunkin/mdcat)
|
|
4
4
|
[](LICENSE)
|
|
5
|
-
[](package.json)
|
|
6
|
+
[](https://github.com/dunkinfrunkin/mdcat/actions/workflows/ci.yml)
|
|
6
7
|
[](https://mdcat.frankchan.dev)
|
|
7
8
|
|
|
8
9
|
**Terminal pager for Markdown.** Full colour, syntax highlighting, incremental search, mouse support — zero config.
|
|
@@ -33,6 +34,7 @@ npx @dunkinfrunkin/mdcat README.md
|
|
|
33
34
|
```sh
|
|
34
35
|
mdcat README.md # open a file
|
|
35
36
|
mdcat --web README.md # render and open in browser
|
|
37
|
+
mdcat -n README.md # show line numbers
|
|
36
38
|
mdcat --light README.md # force light theme
|
|
37
39
|
mdcat --dark README.md # force dark theme
|
|
38
40
|
cat CHANGELOG.md | mdcat # pipe from stdin
|
|
@@ -47,6 +49,7 @@ mdcat --version # show version
|
|
|
47
49
|
|-----|--------|
|
|
48
50
|
| `q` | Quit |
|
|
49
51
|
| `y` | Copy visible page to clipboard |
|
|
52
|
+
| `L` | Toggle line numbers |
|
|
50
53
|
| `M` | Toggle mouse (off = free text selection) |
|
|
51
54
|
| `j` / `k` | Scroll down / up |
|
|
52
55
|
| `Space` / `b` | Page down / up |
|
|
@@ -105,7 +108,7 @@ npm install
|
|
|
105
108
|
npm test
|
|
106
109
|
```
|
|
107
110
|
|
|
108
|
-
All PRs must pass `npm test` (
|
|
111
|
+
All PRs must pass `npm test` (85 tests).
|
|
109
112
|
|
|
110
113
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
111
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dunkinfrunkin/mdcat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "View markdown files beautifully in your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"wrap-ansi": "^10.0.0"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=20"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"markdown",
|
package/src/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ if (args[0] === "--help" || args[0] === "-h") {
|
|
|
32
32
|
console.log(` mdcat ${dim("--doc <file.md>")} ${dim("# export to .docx")}`);
|
|
33
33
|
console.log(` mdcat ${dim("--light")} ${dim("# force light theme")}`);
|
|
34
34
|
console.log(` mdcat ${dim("--dark")} ${dim("# force dark theme")}`);
|
|
35
|
+
console.log(` mdcat ${dim("-n, --number")} ${dim("# show line numbers")}`);
|
|
35
36
|
console.log(` cat file.md ${dim("|")} mdcat\n`);
|
|
36
37
|
console.log(`${bold("Theme:")}`);
|
|
37
38
|
console.log(` Auto-detects terminal theme. Override with ${blue("--light")} / ${blue("--dark")}`);
|
|
@@ -40,7 +41,7 @@ if (args[0] === "--help" || args[0] === "-h") {
|
|
|
40
41
|
console.log(` ${blue("/")} search ${blue("n/N")} next/prev match`);
|
|
41
42
|
console.log(` ${blue("j/k")} ${dim("↑↓")} scroll line ${blue("space/b")} page down/up`);
|
|
42
43
|
console.log(` ${blue("d/u")} half page ${blue("g/G")} top/bottom`);
|
|
43
|
-
console.log(` ${blue("q")}
|
|
44
|
+
console.log(` ${blue("L")} line numbers ${blue("q")} quit\n`);
|
|
44
45
|
process.exit(0);
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -49,6 +50,10 @@ const activeTheme = themeFromArgs(args) ?? detectTheme();
|
|
|
49
50
|
args = stripThemeArgs(args);
|
|
50
51
|
setTheme(activeTheme);
|
|
51
52
|
|
|
53
|
+
// Line numbers flag
|
|
54
|
+
const showLineNumbers = args.includes("-n") || args.includes("--number");
|
|
55
|
+
args = args.filter(a => a !== "-n" && a !== "--number");
|
|
56
|
+
|
|
52
57
|
if (args[0] === "--version" || args[0] === "-v") {
|
|
53
58
|
console.log(`${CAT} ${bold("mdcat")} ${dim(`v${pkg.version}`)}`);
|
|
54
59
|
process.exit(0);
|
|
@@ -128,7 +133,7 @@ function runTUI(title, content) {
|
|
|
128
133
|
const cols = Math.min(termCols, MAX_COLS);
|
|
129
134
|
const tokens = marked.lexer(content);
|
|
130
135
|
const lines = renderTokens(tokens, cols, termCols > MAX_COLS ? termCols : undefined);
|
|
131
|
-
launch(title, lines, activeTheme);
|
|
136
|
+
launch(title, lines, activeTheme, { lineNumbers: showLineNumbers });
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
// --web / --doc flags
|
package/src/tui.js
CHANGED
|
@@ -129,7 +129,7 @@ function copyText(text) {
|
|
|
129
129
|
catch { /* not on macOS or pbcopy unavailable */ }
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export function launch(title, lines, theme) {
|
|
132
|
+
export function launch(title, lines, theme, opts = {}) {
|
|
133
133
|
// Apply theme to TUI chrome
|
|
134
134
|
if (theme === "light") {
|
|
135
135
|
const pal = LIGHT;
|
|
@@ -137,6 +137,12 @@ export function launch(title, lines, theme) {
|
|
|
137
137
|
HL_MATCH = pal.hlMatch;
|
|
138
138
|
HL_CURRENT = pal.hlCurrent;
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// Line numbers
|
|
142
|
+
let lineNumbers = opts.lineNumbers ?? false;
|
|
143
|
+
const totalDigits = String(lines.length).length;
|
|
144
|
+
const gutterW = totalDigits + 2; // " N " width
|
|
145
|
+
|
|
140
146
|
// Viewport state
|
|
141
147
|
let offset = 0;
|
|
142
148
|
|
|
@@ -225,10 +231,16 @@ export function launch(title, lines, theme) {
|
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
function gutterFor(absLine) {
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
let prefix = "";
|
|
235
|
+
if (lineNumbers) {
|
|
236
|
+
const num = String(absLine + 1).padStart(totalDigits);
|
|
237
|
+
prefix = `${C.dimFg}${num}${RESET} `;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (mode === "normal" || !searchQuery) return prefix || " ";
|
|
241
|
+
if (matchLines[matchIdx] === absLine) return `${prefix}${C.matchFg}▶${RESET} `;
|
|
242
|
+
if (matchSet.has(absLine)) return `${prefix}${C.otherMatchFg}›${RESET} `;
|
|
243
|
+
return prefix || " ";
|
|
232
244
|
}
|
|
233
245
|
|
|
234
246
|
function statusBar(w) {
|
|
@@ -274,9 +286,9 @@ export function launch(title, lines, theme) {
|
|
|
274
286
|
|
|
275
287
|
const mouseHint = mouseEnabled ? "" : `${C.matchFg} [select mode]${RESET}`;
|
|
276
288
|
const mouseW = mouseEnabled ? 0 : " [select mode]".length;
|
|
277
|
-
const hints = `${C.dim} q y / j k ↑↓ space g G M${RESET}`;
|
|
289
|
+
const hints = `${C.dim} q y / j k ↑↓ space g G L M${RESET}`;
|
|
278
290
|
const right = `${C.dimFg} ${pct} ${RESET}`;
|
|
279
|
-
const hintsW = " q y / j k ↑↓ space g G M".length;
|
|
291
|
+
const hintsW = " q y / j k ↑↓ space g G L M".length;
|
|
280
292
|
const rightW = ` ${pct} `.length;
|
|
281
293
|
const gap = Math.max(0, w - hintsW - mouseW - rightW);
|
|
282
294
|
return `${C.chromeBg}${hints}${mouseHint}${" ".repeat(gap)}${right}${RESET}`;
|
|
@@ -368,6 +380,10 @@ export function launch(title, lines, theme) {
|
|
|
368
380
|
showToast("Copied to clipboard"); return;
|
|
369
381
|
}
|
|
370
382
|
|
|
383
|
+
case "L":
|
|
384
|
+
lineNumbers = !lineNumbers;
|
|
385
|
+
showToast(lineNumbers ? "Line numbers on" : "Line numbers off"); return;
|
|
386
|
+
|
|
371
387
|
case "M":
|
|
372
388
|
mouseEnabled = !mouseEnabled;
|
|
373
389
|
process.stdout.write(mouseEnabled ? MOUSE_ON : MOUSE_OFF);
|