Skip to content

Commit

Permalink
fix: preserve \n\t\r control characters when displaying logs
Browse files Browse the repository at this point in the history
  • Loading branch information
monojack committed Feb 21, 2024
1 parent cc1919e commit e098543
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styled from 'styled-components';
import {Tooltip} from '@components/atoms/Tooltip/Tooltip';

import {useMainPaneDimensions} from '@utils/hooks';
import {preserveControlCharacters} from '@utils/preserveControlCharacters';

import {ContextId} from '@shared/ipc';
import {Colors} from '@shared/styles';
Expand Down Expand Up @@ -82,7 +83,7 @@ export function DebugClusterDrawer({contextId, open, onClose}: Props) {
<LogMeta>
[{DateTime.fromMillis(l.timestamp).toFormat('HH:MM:ss')} - {l.type}]
</LogMeta>
<LogContent $wrap={wordWrap}>{l.content}</LogContent>
<LogContent $wrap={wordWrap}>{preserveControlCharacters(l.content)}</LogContent>
</LogEntry>
))}
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/utils/preserveControlCharacters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function preserveControlCharacters(str: string) {
return str.replace(/[\n\r\t]/g, cc => {
return `\\${cc === '\n' ? 'n' : cc === '\r' ? 'r' : 't'}`;
});
}

0 comments on commit e098543

Please sign in to comment.