Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve action log display with control chars #23820

Merged
merged 7 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,5 +29,6 @@ export default defineConfig({
},
plugins: [
stringPlugin(),
vue(),
],
});
10 changes: 10 additions & 0 deletions web_src/js/components/RepoActionView.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
18 changes: 17 additions & 1 deletion web_src/js/components/RepoActionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved

return div;
Expand Down Expand Up @@ -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;
}
</script>

<style scoped>
Expand Down