Skip to content

Commit

Permalink
Strip ANSI terminal escape sequences from console.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Aug 5, 2023
1 parent 6fb7ebf commit 03f54a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-virtualized-auto-sizer": "^1.0.20",
"react-window": "^1.8.9"
"react-window": "^1.8.9",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
"@babel/core": "^7.22.9",
Expand Down
4 changes: 3 additions & 1 deletion pages/dashboard/[server]/console.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useRef, startTransition, useCallback } from 'react'
import { Paper, Typography, TextField, Fab, useTheme } from '@mui/material'
import Check from '@mui/icons-material/Check'
import stripAnsi from 'strip-ansi'

import useInterval from '../../../imports/helpers/useInterval'
import useKy from '../../../imports/helpers/useKy'
Expand Down Expand Up @@ -118,7 +119,8 @@ const Console = ({ setAuthenticated }: {
}
connectedOnce.current = true
}
buffer.current.push(...data.split('\n').map((text: string) => ({ id: ++id.current, text })))
buffer.current.push(...data.split('\n')
.map(text => ({ id: ++id.current, text: stripAnsi(text) })))
}
newWS.onmessage = (event): void => {
if (newWS.protocol === 'console-v2') {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,11 @@ ansi-regex@^5.0.1:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

ansi-regex@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a"
integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==

ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
Expand Down Expand Up @@ -4365,6 +4370,13 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1:
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
integrity sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==
dependencies:
ansi-regex "^6.0.1"

strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
Expand Down

0 comments on commit 03f54a9

Please sign in to comment.