@@ -100,6 +100,16 @@ const endRender = (): void => {
100100 }
101101} ;
102102
103+ const withRender = < T > ( callback : ( ) => T ) : T => {
104+ beginRender ( ) ;
105+
106+ try {
107+ return callback ( ) ;
108+ } finally {
109+ endRender ( ) ;
110+ }
111+ } ;
112+
103113const isSensitiveKey = ( key : string ) : boolean => {
104114 const normalizedKey = key . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, "" ) ;
105115
@@ -222,9 +232,7 @@ const filterData = (data: JsonObject): JsonObject => {
222232} ;
223233
224234export const parse = ( data : JsonObject ) : void => {
225- beginRender ( ) ;
226-
227- try {
235+ withRender ( ( ) => {
228236 const sanitizedData = maskSensitiveData ( data ) as JsonObject ;
229237
230238 if ( cliConfig . raw ) {
@@ -285,9 +293,7 @@ export const parse = (data: JsonObject): void => {
285293 printedScalar = true ;
286294 }
287295 }
288- } finally {
289- endRender ( ) ;
290- }
296+ } ) ;
291297} ;
292298
293299const MAX_COL_WIDTH = 40 ;
@@ -312,9 +318,7 @@ const formatCellValue = (value: unknown): string => {
312318} ;
313319
314320export const drawTable = ( data : Array < JsonObject | null | undefined > ) : void => {
315- beginRender ( ) ;
316-
317- try {
321+ withRender ( ( ) => {
318322 if ( data . length == 0 ) {
319323 console . log ( "[]" ) ;
320324 return ;
@@ -395,21 +399,21 @@ export const drawTable = (data: Array<JsonObject | null | undefined>): void => {
395399 colWidths : columns . map ( ( ) => null ) as ( number | null ) [ ] ,
396400 wordWrap : false ,
397401 chars : {
398- top : " " ,
402+ " top" : " " ,
399403 "top-mid" : " " ,
400404 "top-left" : " " ,
401405 "top-right" : " " ,
402- bottom : " " ,
406+ " bottom" : " " ,
403407 "bottom-mid" : " " ,
404408 "bottom-left" : " " ,
405409 "bottom-right" : " " ,
406- left : " " ,
410+ " left" : " " ,
407411 "left-mid" : " " ,
408- mid : chalk . cyan ( "─" ) ,
412+ " mid" : chalk . cyan ( "─" ) ,
409413 "mid-mid" : chalk . cyan ( "┼" ) ,
410- right : " " ,
414+ " right" : " " ,
411415 "right-mid" : " " ,
412- middle : chalk . cyan ( "│" ) ,
416+ " middle" : chalk . cyan ( "│" ) ,
413417 } ,
414418 } ) ;
415419
@@ -421,9 +425,7 @@ export const drawTable = (data: Array<JsonObject | null | undefined>): void => {
421425 table . push ( rowValues ) ;
422426 } ) ;
423427 console . log ( table . toString ( ) ) ;
424- } finally {
425- endRender ( ) ;
426- }
428+ } ) ;
427429} ;
428430
429431export const drawJSON = ( data : unknown ) : void => {
0 commit comments