From 3799a92a63c6408dd89b09f7a877e734002b3daa Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Mar 2023 21:55:38 +0800 Subject: [PATCH 1/5] fix --- package-lock.json | 14 ++++++++++++++ package.json | 1 + vitest.config.js | 2 ++ web_src/js/components/RepoActionView.test.js | 10 ++++++++++ web_src/js/components/RepoActionView.vue | 18 +++++++++++++++++- 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 web_src/js/components/RepoActionView.test.js diff --git a/package-lock.json b/package-lock.json index 93adf5622f83b..313fa515aeaaa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "@playwright/test": "1.31.2", "@rollup/pluginutils": "5.0.2", "@stoplight/spectral-cli": "6.6.0", + "@vitejs/plugin-vue": "4.1.0", "eslint": "8.36.0", "eslint-plugin-import": "2.27.5", "eslint-plugin-jquery": "1.5.1", @@ -1609,6 +1610,19 @@ "integrity": "sha512-FDJNkyhmKLw7uEvTxx5tSXfPeQpO0iy73Ry+PmYZJvQy0QIWX8a7kJ4kLWRf+EbTPJEPDSgPXHaM7pzr5lmvCg==", "dev": true }, + "node_modules/@vitejs/plugin-vue": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.1.0.tgz", + "integrity": "sha512-++9JOAFdcXI3lyer9UKUV4rfoQ3T1RN8yDqoCLar86s0xQct5yblxAE+yWgRnU5/0FOlVCpTZpYSBV/bGWrSrQ==", + "dev": true, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "peerDependencies": { + "vite": "^4.0.0", + "vue": "^3.2.25" + } + }, "node_modules/@vitest/expect": { "version": "0.29.3", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.29.3.tgz", diff --git a/package.json b/package.json index a5d09157a65dc..dc781c6a323b9 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@playwright/test": "1.31.2", "@rollup/pluginutils": "5.0.2", "@stoplight/spectral-cli": "6.6.0", + "@vitejs/plugin-vue": "4.1.0", "eslint": "8.36.0", "eslint-plugin-import": "2.27.5", "eslint-plugin-jquery": "1.5.1", diff --git a/vitest.config.js b/vitest.config.js index 37ebfa57222f1..0cf2996b6ee88 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -2,6 +2,7 @@ import {defineConfig} from 'vitest/dist/config.js'; import {readFile} from 'node:fs/promises'; import {dataToEsm} from '@rollup/pluginutils'; import {extname} from 'node:path'; +import vue from '@vitejs/plugin-vue'; function stringPlugin() { return { @@ -28,5 +29,6 @@ export default defineConfig({ }, plugins: [ stringPlugin(), + vue(), ], }); diff --git a/web_src/js/components/RepoActionView.test.js b/web_src/js/components/RepoActionView.test.js new file mode 100644 index 0000000000000..24c2f75527a35 --- /dev/null +++ b/web_src/js/components/RepoActionView.test.js @@ -0,0 +1,10 @@ +import {expect, test} from 'vitest'; + +import {processConsoleLine} from './RepoActionView.vue'; + +test('processConsoleLine', () => { + expect(processConsoleLine('abc')).toEqual('abc'); + expect(processConsoleLine('\r')).toEqual(''); + expect(processConsoleLine('\rx\rabc')).toEqual('abc'); + expect(processConsoleLine('\rabc\rx\r')).toEqual('xbc'); +}); diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 72801725d029f..66e65424415d1 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -214,7 +214,7 @@ const sfc = { const logMessage = document.createElement('div'); logMessage.className = 'log-msg'; - logMessage.innerHTML = this.ansiToHTML.toHtml(line.message); + logMessage.innerHTML = this.ansiToHTML.toHtml(processConsoleLine(line.message)); div.appendChild(logMessage); return div; @@ -307,6 +307,22 @@ export function initRepositoryActionView() { view.mount(el); } +export function processConsoleLine(line) { + if (!line.includes('\r')) return line; + + // handle "\rReading...1%\rReading...5%\rReading...100%", only show the final message + // TODO: control chars like "\033[" ? + const parts = line.split('\r'); + let result = ''; + for (const part of parts) { + if (part.length >= result.length) { + result = part; + } else { + result = part + result.substring(part.length); + } + } + return result; +}