Skip to content

Commit 05cb233

Browse files
committed
remove file
1 parent 9ac9633 commit 05cb233

File tree

3 files changed

+43
-47
lines changed

3 files changed

+43
-47
lines changed

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/container.ts";
25+
import { isShowingProgressBars } from "./console/progress/mod.ts";
2626
import {
2727
CapturingBufferWriter,
2828
CapturingBufferWriterSync,

src/console/progress/container.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/console/progress/mod.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import * as colors from "@std/fmt/colors";
22
import {
33
type ConsoleSize,
4+
type DeferredItem,
45
maybeConsoleSize,
56
renderTextItems,
67
staticText,
78
type TextItem,
89
} from "@david/console-static-text";
910
import { isOutputTty } from "../utils.ts";
1011
import { humanDownloadSize } from "./format.ts";
11-
import { addProgressBar, removeProgressBar, type RenderIntervalProgressBar } from "./container.ts";
12+
import { logger, LoggerRefreshItemKind } from "../logger.ts";
1213

13-
export { isShowingProgressBars } from "./container.ts";
14+
const progressBars: RenderIntervalProgressBar[] = [];
1415

1516
/** Options for showing progress. */
1617
export interface ProgressOptions {
@@ -250,3 +251,42 @@ export function renderProgressBar(state: RenderState, size: ConsoleSize | undefi
250251
return result;
251252
}
252253
}
254+
255+
export interface RenderIntervalProgressBar {
256+
render(size: ConsoleSize | undefined): TextItem[];
257+
}
258+
259+
function addProgressBar(render: (size: ConsoleSize) => TextItem[]): RenderIntervalProgressBar {
260+
const pb = {
261+
render,
262+
};
263+
progressBars.push(pb);
264+
refresh();
265+
return pb;
266+
}
267+
268+
function removeProgressBar(pb: RenderIntervalProgressBar) {
269+
const index = progressBars.indexOf(pb);
270+
if (index === -1) {
271+
return false;
272+
}
273+
progressBars.splice(index, 1);
274+
refresh();
275+
return true;
276+
}
277+
278+
function refresh() {
279+
logger.setItems(
280+
LoggerRefreshItemKind.ProgressBars,
281+
progressBars.map((p) => {
282+
const item: DeferredItem = (consoleSize) => {
283+
return p.render(consoleSize);
284+
};
285+
return item;
286+
}),
287+
);
288+
}
289+
290+
export function isShowingProgressBars() {
291+
return isOutputTty && progressBars.length > 0;
292+
}

0 commit comments

Comments
 (0)