@@ -43,20 +43,33 @@ const regexMarker = /^{§[0-9a-f]{8}}/;
4343const ANSI_WHITE = '\x1B[0;37m' ;
4444const ANSI_GRAY = '\x1B[1;90m' ;
4545const ANSI_RESET = '\x1B[0m' ;
46- const formatUnixTimestamp = ( timestamp : number ) : string => {
46+ let timestampDisabled = false ;
47+ let timestampForceHour12 : boolean | undefined = undefined ;
48+ try {
49+ const localConfig = localStorage . getItem ( 'liveConsoleTimestamp' ) ;
50+ if ( localConfig === '24h' ) {
51+ timestampForceHour12 = false ;
52+ } else if ( localConfig === '12h' ) {
53+ timestampForceHour12 = true ;
54+ } else if ( localConfig === 'off' ) {
55+ timestampDisabled = true ;
56+ }
57+ } catch ( error ) { }
58+ const getConsolePrefix = ( timestamp : number ) : string => {
59+ if ( timestampDisabled ) return '' ;
4760 const time = new Date ( timestamp * 1000 ) ;
4861 const str = time . toLocaleTimeString (
4962 'en-US' , //as en-gb uses 4 digits for the am/pm indicator
5063 {
5164 hour : '2-digit' ,
5265 minute : '2-digit' ,
5366 second : '2-digit' ,
54- hour12 : window . txBrowserHour12 ,
67+ hour12 : timestampForceHour12 ?? window . txBrowserHour12 ,
5568 }
5669 ) ;
57- return str + ANSI_RESET ;
70+ return str + ANSI_RESET + ' ' ;
5871}
59- const defaultTermPrefix = formatUnixTimestamp ( Date . now ( ) ) . replace ( / \w / g, '-' ) ;
72+ const defaultTermPrefix = getConsolePrefix ( Date . now ( ) ) . replace ( / \w / g, '-' ) ;
6073
6174//Main component
6275export default function LiveConsolePage ( ) {
@@ -256,7 +269,7 @@ export default function LiveConsolePage() {
256269 const ts = parseInt ( line . slice ( 2 , 10 ) , 16 ) ;
257270 line = line . slice ( 11 ) ;
258271 termPrefixRef . current . ts = ts ;
259- termPrefixRef . current . prefix = formatUnixTimestamp ( ts ) ;
272+ termPrefixRef . current . prefix = getConsolePrefix ( ts ) ;
260273 } catch ( error ) {
261274 termPrefixRef . current . prefix = defaultTermPrefix ;
262275 console . warn ( 'Failed to parse timestamp from:' , line , ( error as any ) . message ) ;
@@ -268,7 +281,7 @@ export default function LiveConsolePage() {
268281 //Check if it's last line, and if the EOL was stripped
269282 const prefixColor = isNewTs ? ANSI_WHITE : ANSI_GRAY ;
270283 const prefix = termPrefixRef . current . lastEol
271- ? prefixColor + termPrefixRef . current . prefix + ' '
284+ ? prefixColor + termPrefixRef . current . prefix
272285 : '' ;
273286 if ( i < lines . length - 1 ) {
274287 term . writeln ( prefix + line ) ;
0 commit comments