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
37export 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
4631const 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
5241export { logger } ;
0 commit comments