Skip to content

Commit 9c6769c

Browse files
authored
refactor: use jsr:@david/console-static-text@^0.3.0 (#334)
1 parent 4541be0 commit 9c6769c

26 files changed

+2270
-3859
lines changed

Cargo.lock

Lines changed: 0 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
],
3434
"exports": "./mod.ts",
3535
"imports": {
36+
"@david/console-static-text": "jsr:@david/console-static-text@^0.3.0",
3637
"@deno/dnt": "jsr:@deno/dnt@~0.41.3",
3738
"@david/path": "jsr:@david/[email protected]",
3839
"@std/assert": "jsr:@std/assert@1",
40+
"@std/async": "jsr:@std/async@^1.0.13",
3941
"@std/fmt": "jsr:@std/fmt@1",
4042
"@std/fs": "jsr:@std/fs@1",
4143
"@std/io": "jsr:@std/[email protected]",

deno.lock

Lines changed: 36 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
select,
3838
type SelectOptions,
3939
} from "./src/console/mod.ts";
40-
import { strip_ansi_codes } from "./src/lib/rs_lib.js";
40+
import { stripAnsiCodes } from "@david/console-static-text";
4141

4242
import { Path } from "@david/path";
4343
import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts";
@@ -629,7 +629,7 @@ const helperObject = {
629629
cd,
630630
escapeArg,
631631
stripAnsi(text: string) {
632-
return strip_ansi_codes(text);
632+
return stripAnsiCodes(text);
633633
},
634634
dedent: outdent,
635635
sleep,

src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { whichCommand } from "./commands/which.ts";
2222
import { Box, delayToMs, errorToString, LoggerTreeBox } from "./common.ts";
2323
import type { Delay } from "./common.ts";
2424
import { symbols } from "./common.ts";
25-
import { isShowingProgressBars } from "./console/progress/interval.ts";
25+
import { isShowingProgressBars } from "./console/progress.ts";
2626
import {
2727
CapturingBufferWriter,
2828
CapturingBufferWriterSync,

src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class LoggerTreeBox extends TreeBox<(...args: any[]) => void> {
207207
override getValue(): (...args: any[]) => void {
208208
const innerValue = super.getValue();
209209
return (...args: any[]) => {
210-
return logger.logAboveStaticText(() => {
210+
return logger.withTempClear(() => {
211211
innerValue(...args);
212212
});
213213
};

src/console/confirm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as colors from "@std/fmt/colors";
2-
import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts";
2+
import { createSelection, Keys, resultOrExit, type SelectionOptions } from "./utils.ts";
3+
import type { TextItem } from "@david/console-static-text";
34

45
/** Options for showing confirming a yes or no question. */
56
export interface ConfirmOptions {

src/console/logger.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { type ConsoleSize, isOutputTty, safeConsoleSize, staticText, type TextItem } from "./utils.ts";
1+
import { isOutputTty } from "./utils.ts";
2+
import { type ConsoleSize, renderInterval, staticText, type TextItem } from "@david/console-static-text";
3+
4+
const staticTextScope = staticText.createScope();
5+
const _renderScope = renderInterval.start();
26

37
export enum LoggerRefreshItemKind {
48
ProgressBars,
@@ -20,33 +24,18 @@ function refresh(size?: ConsoleSize) {
2024
return;
2125
}
2226
const items = Object.values(refreshItems).flatMap((items) => items ?? []);
23-
staticText.set(items, size);
24-
}
25-
26-
function logAboveStaticText(inner: () => void, providedSize?: ConsoleSize) {
27-
if (!isOutputTty) {
28-
inner();
29-
return;
30-
}
31-
32-
const size = providedSize ?? safeConsoleSize();
33-
if (size != null) {
34-
staticText.clear(size);
35-
}
36-
inner();
37-
refresh(size);
38-
}
39-
40-
function logOnce(items: TextItem[], size?: ConsoleSize) {
41-
logAboveStaticText(() => {
42-
staticText.outputItems(items, size);
43-
}, size);
27+
staticTextScope.setText(items);
28+
staticText.refresh(size);
4429
}
4530

4631
const logger = {
4732
setItems,
48-
logOnce,
49-
logAboveStaticText,
33+
logOnce(items: TextItem[], size?: ConsoleSize) {
34+
staticTextScope.logAbove(items, size);
35+
},
36+
withTempClear(action: () => void) {
37+
staticText.withTempClear(action);
38+
},
5039
};
5140

5241
export { logger };

src/console/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export type { ConfirmOptions } from "./confirm.ts";
33
export { logger } from "./logger.ts";
44
export { maybeMultiSelect, multiSelect } from "./multiSelect.ts";
55
export type { MultiSelectOption, MultiSelectOptions } from "./multiSelect.ts";
6-
export type { ProgressOptions } from "./progress/mod.ts";
7-
export { isShowingProgressBars, ProgressBar } from "./progress/mod.ts";
6+
export type { ProgressOptions } from "./progress.ts";
7+
export { isShowingProgressBars, ProgressBar } from "./progress.ts";
88
export { maybePrompt, prompt } from "./prompt.ts";
99
export type { PromptInputMask, PromptOptions } from "./prompt.ts";
1010
export { maybeSelect, select } from "./select.ts";

src/console/multiSelect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as colors from "@std/fmt/colors";
2-
import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts";
2+
import type { TextItem } from "@david/console-static-text";
3+
import { createSelection, Keys, resultOrExit, type SelectionOptions } from "./utils.ts";
34

45
/** Single options within a multi-select option. */
56
export interface MultiSelectOption {

0 commit comments

Comments
 (0)