Skip to content

Commit

Permalink
[#51982] frontend: components: Terminal: Scroll back to top after cle…
Browse files Browse the repository at this point in the history
…aring

Signed-off-by: Mateusz Leonowicz <[email protected]>
  • Loading branch information
mleonowicz authored and glatosinski committed Dec 5, 2023
1 parent c63c63d commit ad705cd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pipeline_manager/frontend/src/components/Terminal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export default defineComponent({

const logs = computed(() => terminalStore.logs[props.terminalInstance]);

const printLog = (log) => {
if (term === undefined) return;
term.io.print(props.terminalInstance === MAIN_TERMINAL ? log.replace(/\n/g, '\r\n') : log);
};

onMounted(async () => {
// wait for hterm.js library to load
// (glatosinski: we may later need to move it to some global scope)
Expand All @@ -61,10 +66,10 @@ export default defineComponent({

term.onTerminalReady = function onTerminalReady() {
// load logs that have existed already in the storage.
if (props.terminalInstance === MAIN_TERMINAL) {
if (logs.value !== undefined) {
logs.value.forEach((log, index) => {
if (index > 0) this.io.print('\r\n\r\n');
this.io.print(log.replace(/\n/g, '\r\n'));
if (index > 0 && props.terminalInstance === MAIN_TERMINAL) printLog('\n\n');
printLog(log);
});
}
// for now configure the terminal as read-only
Expand All @@ -80,14 +85,10 @@ export default defineComponent({
term.decorate(document.querySelector('#hterm-terminal'));
});

const printLog = (log) => {
if (term === undefined) return;
term.io.print(props.terminalInstance === MAIN_TERMINAL ? log.replace(/\n/g, '\r\n') : log);
};

const clearLog = () => {
if (term === undefined) return;
term.wipeContents();
term.scrollHome();
};

// If a terminal instance was changed, then all messages should be written
Expand Down

0 comments on commit ad705cd

Please sign in to comment.