| author | |
| committer | |
| log | 5b403d91b350d337f743d3a99ac0637fd3c12953 |
| tree | a010799cfbc394934da44161341b1abc71368834 |
| parent | 2f082aadf24befd5d4005e5734216bd23f5af84c |
| signature | Signed by SSH key SHA256:xbd+BjjhyBfwk7GVoURf9Yx0gzDerHbvYv7SddNWmAs |
4 files changed, 10 insertions(+), 8 deletions(-)
lib/log.ts+1-1| ... | ... | @@ -404,7 +404,7 @@ export function createWidgetHost(env: WidgetHostOptions): WidgetHost { |
| 404 | 404 | if (rowsLeft === 1) break; |
| 405 | 405 | const lines = outText.split("\n").slice(0, rowsLeft); |
| 406 | 406 | newWidgetLines.push( |
| 407 | ...lines.map((line) => ansi.trimToWidth(line, columns - 1)), | |
| 407 | ...lines.map((line) => ansi.trimForTerminal(line, columns - 1)), | |
| 408 | 408 | ); |
| 409 | 409 | |
| 410 | 410 | next = Math.min(next, UNWRAP(internals[w]).frameTime); |
lib/readme.changes.md+4-1| ... | ... | @@ -22,7 +22,9 @@ |
| 22 | 22 | you to give some information about where the cursor was moved to. |
| 23 | 23 | - messages now do not imply a newline |
| 24 | 24 | - `render` is now deprecated with no replacement. in the downstream `sitegen` |
| 25 | project, the entire codebase is moving to Marko after depending on both renderers. | |
| 25 | project, the codebase is moving to Marko after depending on both renderers. | |
| 26 | - `string/ansi` | |
| 27 | - rename `trimToWidth` to `trimForTerminal` | |
| 26 | 28 | |
| 27 | 29 | ### features |
| 28 | 30 | |
| ... | ... | @@ -36,6 +38,7 @@ |
| 36 | 38 | a newline. |
| 37 | 39 | - `async.delay` handles timers longer than 23 days. |
| 38 | 40 | - `Lru.revive` recieves bug fixes. this function previously didn't really work. |
| 41 | - `ansi` gets more cursor control constants | |
| 39 | 42 | |
| 40 | 43 | ## v3 |
| 41 | 44 |
lib/string/ansi.test.ts+3-3| ... | ... | @@ -8,13 +8,13 @@ test("widthInTerminal", () => { |
| 8 | 8 | 9, |
| 9 | 9 | ); |
| 10 | 10 | }); |
| 11 | test("trimToWidth", () => { | |
| 11 | test("trimForTerminal", () => { | |
| 12 | 12 | assert.equal( |
| 13 | ansi.trimToWidth("snowmobile", 6), | |
| 13 | ansi.trimForTerminal("snowmobile", 6), | |
| 14 | 14 | "snowmo", |
| 15 | 15 | ); |
| 16 | 16 | assert.equal( |
| 17 | ansi.trimToWidth("🏳️⚧️ " + ansi.style(ansi.bold, "rights"), 5), | |
| 17 | ansi.trimForTerminal("🏳️⚧️ " + ansi.style(ansi.bold, "rights"), 5), | |
| 18 | 18 | "🏳️⚧️ " + ansi.bold + "ri" + ansi.reset, |
| 19 | 19 | ); |
| 20 | 20 | }); |
lib/string/ansi.ts+2-3| ... | ... | @@ -277,8 +277,7 @@ export function widthInTerminal(str: string): number { |
| 277 | 277 | * Like `str.slice(0, columns)`, but respecting width in a terminal. |
| 278 | 278 | * preserves ansi escape sequences. |
| 279 | 279 | */ |
| 280 | // TODO: rename to trimForTerminal | |
| 281 | export function trimToWidth(str: string, columns: number): string { | |
| 280 | export function trimForTerminal(str: string, columns: number): string { | |
| 282 | 281 | segmenter ??= new Intl.Segmenter(); |
| 283 | 282 | let width = 0; |
| 284 | 283 | let ansi = false; |
| ... | ... | @@ -286,7 +285,7 @@ export function trimToWidth(str: string, columns: number): string { |
| 286 | 285 | const code = str.charCodeAt(i); |
| 287 | 286 | if (code < 32) { |
| 288 | 287 | if (code === 0x1b) { |
| 289 | const esc = str.slice().match(ansiEscapes); | |
| 288 | const esc = str.slice(i).match(ansiEscapes); | |
| 290 | 289 | if (esc) i += esc[0].length - 1, ansi = true; |
| 291 | 290 | } |
| 292 | 291 | continue; |