phewsh 0.15.57 → 0.15.58

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.
Files changed (3) hide show
  1. package/lib/md.js +1 -1
  2. package/lib/ui.js +17 -3
  3. package/package.json +1 -1
package/lib/md.js CHANGED
@@ -44,7 +44,7 @@ const ANSI = /\x1b\[[0-9;]*m/g;
44
44
  const vis = (s) => s.replace(ANSI, '').length;
45
45
 
46
46
  function softWrap(s, base = '', hang) {
47
- const width = process.stdout.columns;
47
+ const width = require('./ui').termWidth();
48
48
  if (!width || width < 24 || vis(s) <= width) return s;
49
49
  const lead = s.match(/^ */)[0].length;
50
50
  const indent = hang == null ? lead : hang;
package/lib/ui.js CHANGED
@@ -121,6 +121,20 @@ async function brandReveal(fast = false) {
121
121
  const SGR = /\x1b\[[0-9;]*m/g;
122
122
  const visW = (s) => s.replace(SGR, '').length;
123
123
 
124
+ // Best available terminal width, with one column of safety margin so content
125
+ // never sits flush against the edge (where terminals add their own wrap).
126
+ // `PHEWSH_WIDTH` pins it explicitly — the escape hatch for host terminals that
127
+ // misreport their size (some embedded/agent terminals advertise a wider pty
128
+ // than the visible pane, which makes text break mid-word even with smart wrap
129
+ // on). Falls back to COLUMNS, then the live tty size, then 80.
130
+ function termWidth() {
131
+ const pin = parseInt(process.env.PHEWSH_WIDTH, 10);
132
+ const base = (Number.isFinite(pin) && pin >= 20)
133
+ ? pin
134
+ : (process.stdout.columns || parseInt(process.env.COLUMNS, 10) || 80);
135
+ return Math.max(24, base - 1);
136
+ }
137
+
124
138
  // Active SGR state after consuming `s`, starting from `prev`. A reset clears it;
125
139
  // any other colour code accumulates. Good enough to re-open colour at a break.
126
140
  function sgrAfter(prev, s) {
@@ -131,7 +145,7 @@ function sgrAfter(prev, s) {
131
145
  return active;
132
146
  }
133
147
 
134
- function wrapAnsi(s, width = process.stdout.columns) {
148
+ function wrapAnsi(s, width) {
135
149
  if (!width || width < 24) return s;
136
150
  return s.split('\n').map((line) => {
137
151
  if (visW(line) <= width) return line;
@@ -168,7 +182,7 @@ function installSmartWrap() {
168
182
  const orig = console.log.bind(console);
169
183
  const wrapped = (...args) => {
170
184
  if (args.length && args.every((a) => typeof a === 'string')) {
171
- orig(wrapAnsi(args.join(' ')));
185
+ orig(wrapAnsi(args.join(' '), termWidth()));
172
186
  } else {
173
187
  orig(...args);
174
188
  }
@@ -334,7 +348,7 @@ module.exports = {
334
348
  spinner, brandReveal, statusPanel, interopLine, divider, typewrite,
335
349
  randomTip, TOUR_PAGES,
336
350
  // Smart wrap
337
- wrapAnsi, installSmartWrap,
351
+ wrapAnsi, installSmartWrap, termWidth,
338
352
  // ANSI helpers
339
353
  hide, show, up, clearLine, sleep,
340
354
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phewsh",
3
- "version": "0.15.57",
3
+ "version": "0.15.58",
4
4
  "description": "Turn intent into action. Structure your thinking, execute your next step.",
5
5
  "bin": {
6
6
  "phewsh": "bin/phewsh.js"