@dunkinfrunkin/mdcat 0.1.12 → 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 CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@dunkinfrunkin/mdcat?color=61afef&label=npm)](https://www.npmjs.com/package/@dunkinfrunkin/mdcat)
4
4
  [![license](https://img.shields.io/badge/license-MIT-98c379)](LICENSE)
5
- [![node](https://img.shields.io/badge/node-%3E%3D18-e5c07b)](package.json)
5
+ [![node](https://img.shields.io/badge/node-%3E%3D20-e5c07b)](package.json)
6
+ [![CI](https://github.com/dunkinfrunkin/mdcat/actions/workflows/ci.yml/badge.svg)](https://github.com/dunkinfrunkin/mdcat/actions/workflows/ci.yml)
7
+ [![site](https://img.shields.io/badge/site-mdcat.frankchan.dev-61afef)](https://mdcat.frankchan.dev)
6
8
 
7
9
  **Terminal pager for Markdown.** Full colour, syntax highlighting, incremental search, mouse support — zero config.
8
10
 
@@ -10,7 +12,7 @@
10
12
  npm install -g @dunkinfrunkin/mdcat
11
13
  ```
12
14
 
13
- <video src="https://github.com/dunkinfrunkin/mdcat/releases/download/v0.1.2/demo.mp4" autoplay loop muted playsinline width="100%"></video>
15
+ ![mdcat demo](https://github.com/dunkinfrunkin/mdcat/releases/download/v0.1.12/demo.gif)
14
16
 
15
17
  ---
16
18
 
@@ -32,6 +34,7 @@ npx @dunkinfrunkin/mdcat README.md
32
34
  ```sh
33
35
  mdcat README.md # open a file
34
36
  mdcat --web README.md # render and open in browser
37
+ mdcat -n README.md # show line numbers
35
38
  mdcat --light README.md # force light theme
36
39
  mdcat --dark README.md # force dark theme
37
40
  cat CHANGELOG.md | mdcat # pipe from stdin
@@ -46,6 +49,7 @@ mdcat --version # show version
46
49
  |-----|--------|
47
50
  | `q` | Quit |
48
51
  | `y` | Copy visible page to clipboard |
52
+ | `L` | Toggle line numbers |
49
53
  | `M` | Toggle mouse (off = free text selection) |
50
54
  | `j` / `k` | Scroll down / up |
51
55
  | `Space` / `b` | Page down / up |
@@ -104,10 +108,16 @@ npm install
104
108
  npm test
105
109
  ```
106
110
 
107
- All PRs must pass `npm test` (68 tests).
111
+ All PRs must pass `npm test` (85 tests).
108
112
 
109
113
  See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
110
114
 
115
+ ## Links
116
+
117
+ - [mdcat.frankchan.dev](https://mdcat.frankchan.dev) -- landing page
118
+ - [npm package](https://www.npmjs.com/package/@dunkinfrunkin/mdcat)
119
+ - [GitHub](https://github.com/dunkinfrunkin/mdcat)
120
+
111
121
  ## License
112
122
 
113
123
  [MIT](LICENSE) © Frank Chan
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunkinfrunkin/mdcat",
3
- "version": "0.1.12",
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": ">=18"
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")} quit\n`);
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
- if (mode === "normal" || !searchQuery) return " ";
229
- if (matchLines[matchIdx] === absLine) return `${C.matchFg}▶${RESET} `;
230
- if (matchSet.has(absLine)) return `${C.otherMatchFg}›${RESET} `;
231
- return " ";
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);