mirror of
https://github.com/louislam/dockge.git
synced 2025-03-12 20:34:47 +00:00
Compare commits
5 commits
5ded60e862
...
83b5c3888b
Author | SHA1 | Date | |
---|---|---|---|
|
83b5c3888b | ||
|
a65a9f5549 | ||
|
9b73e44cd9 | ||
|
d51cc39711 | ||
|
48ccc27b9f |
2 changed files with 65 additions and 34 deletions
|
@ -236,42 +236,63 @@ export function copyYAMLComments(doc : Document, src : Document) {
|
|||
|
||||
/**
|
||||
* Copy yaml comments from srcItems to items
|
||||
* Typescript is super annoying here, so I have to use any here
|
||||
* TODO: Since comments are belong to the array index, the comments will be lost if the order of the items is changed or removed or added.
|
||||
* Attempts to preserve comments by matching content rather than just array indices
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function copyYAMLCommentsItems(items : any, srcItems : any) {
|
||||
function copyYAMLCommentsItems(items: any, srcItems: any) {
|
||||
if (!items || !srcItems) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First pass - try to match items by their content
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const item : any = items[i];
|
||||
const item: any = items[i];
|
||||
|
||||
// Try to find matching source item by content
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const srcItem : any = srcItems[i];
|
||||
const srcIndex = srcItems.findIndex((srcItem: any) =>
|
||||
JSON.stringify(srcItem.value) === JSON.stringify(item.value) &&
|
||||
JSON.stringify(srcItem.key) === JSON.stringify(item.key)
|
||||
);
|
||||
|
||||
if (!srcItem) {
|
||||
continue;
|
||||
}
|
||||
if (srcIndex !== -1) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const srcItem: any = srcItems[srcIndex];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const nextSrcItem: any = srcItems[srcIndex + 1];
|
||||
|
||||
if (item.key && srcItem.key) {
|
||||
item.key.comment = srcItem.key.comment;
|
||||
item.key.commentBefore = srcItem.key.commentBefore;
|
||||
}
|
||||
if (item.key && srcItem.key) {
|
||||
item.key.comment = srcItem.key.comment;
|
||||
item.key.commentBefore = srcItem.key.commentBefore;
|
||||
}
|
||||
|
||||
if (srcItem.comment) {
|
||||
item.comment = srcItem.comment;
|
||||
}
|
||||
if (srcItem.comment) {
|
||||
item.comment = srcItem.comment;
|
||||
}
|
||||
|
||||
if (item.value && srcItem.value) {
|
||||
if (typeof item.value === "object" && typeof srcItem.value === "object") {
|
||||
item.value.comment = srcItem.value.comment;
|
||||
item.value.commentBefore = srcItem.value.commentBefore;
|
||||
// Handle comments between array items
|
||||
if (nextSrcItem && nextSrcItem.commentBefore) {
|
||||
if (items[i + 1]) {
|
||||
items[i + 1].commentBefore = nextSrcItem.commentBefore;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.value.items && srcItem.value.items) {
|
||||
copyYAMLCommentsItems(item.value.items, srcItem.value.items);
|
||||
// Handle trailing comments after array items
|
||||
if (srcItem.value && srcItem.value.comment) {
|
||||
if (item.value) {
|
||||
item.value.comment = srcItem.value.comment;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.value && srcItem.value) {
|
||||
if (typeof item.value === "object" && typeof srcItem.value === "object") {
|
||||
item.value.comment = srcItem.value.comment;
|
||||
item.value.commentBefore = srcItem.value.commentBefore;
|
||||
|
||||
if (item.value.items && srcItem.value.items) {
|
||||
copyYAMLCommentsItems(item.value.items, srcItem.value.items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,16 +154,17 @@ export default {
|
|||
},
|
||||
|
||||
removeInput() {
|
||||
const textAfterCursorLength = this.terminalInputBuffer.length - this.cursorPosition;
|
||||
const spaces = " ".repeat(textAfterCursorLength);
|
||||
const backspaceCount = this.terminalInputBuffer.length;
|
||||
const backspaces = "\b \b".repeat(backspaceCount);
|
||||
this.cursorPosition = 0;
|
||||
this.terminal.write(backspaces);
|
||||
this.terminal.write(spaces + backspaces);
|
||||
this.terminalInputBuffer = "";
|
||||
},
|
||||
|
||||
mainTerminalConfig() {
|
||||
this.terminal.onKey(e => {
|
||||
const code = e.key.charCodeAt(0);
|
||||
console.debug("Encode: " + JSON.stringify(e.key));
|
||||
|
||||
if (e.key === "\r") {
|
||||
|
@ -180,29 +181,39 @@ export default {
|
|||
this.$root.emitAgent(this.endpoint, "terminalInput", this.name, buffer + e.key, (err) => {
|
||||
this.$root.toastError(err.msg);
|
||||
});
|
||||
|
||||
} else if (code === 127) { // Backspace
|
||||
} else if (e.key === "\u007F") { // Backspace
|
||||
if (this.cursorPosition > 0) {
|
||||
this.terminal.write("\b \b");
|
||||
const trimmedTextBeforeCursor = this.terminalInputBuffer.slice(0, this.cursorPosition - 1);
|
||||
const textAfterCursor = this.terminalInputBuffer.slice(this.cursorPosition);
|
||||
const clearAfterCursor = " ".repeat(textAfterCursor.length) + "\b \b".repeat(textAfterCursor.length + 1);
|
||||
this.terminalInputBuffer = trimmedTextBeforeCursor + textAfterCursor;
|
||||
this.terminal.write(clearAfterCursor + textAfterCursor + "\b".repeat(textAfterCursor.length));
|
||||
this.cursorPosition--;
|
||||
this.terminalInputBuffer = this.terminalInputBuffer.slice(0, -1);
|
||||
}
|
||||
} else if (e.key === "\u001B\u005B\u0041" || e.key === "\u001B\u005B\u0042") { // UP OR DOWN
|
||||
// Do nothing
|
||||
|
||||
} else if (e.key === "\u001B\u005B\u0043") { // RIGHT
|
||||
// TODO
|
||||
if (this.cursorPosition < this.terminalInputBuffer.length) {
|
||||
this.terminal.write(this.terminalInputBuffer[this.cursorPosition]);
|
||||
this.cursorPosition++;
|
||||
}
|
||||
} else if (e.key === "\u001B\u005B\u0044") { // LEFT
|
||||
// TODO
|
||||
if (this.cursorPosition > 0) {
|
||||
this.terminal.write("\b");
|
||||
this.cursorPosition--;
|
||||
}
|
||||
} else if (e.key === "\u0003") { // Ctrl + C
|
||||
console.debug("Ctrl + C");
|
||||
this.$root.emitAgent(this.endpoint, "terminalInput", this.name, e.key);
|
||||
this.removeInput();
|
||||
} else if (e.key === "\u0009" || e.key.startsWith("\u001B")) { // TAB or other special keys
|
||||
// Do nothing
|
||||
} else {
|
||||
const textBeforeCursor = this.terminalInputBuffer.slice(0, this.cursorPosition);
|
||||
const textAfterCursor = this.terminalInputBuffer.slice(this.cursorPosition);
|
||||
this.terminalInputBuffer = textBeforeCursor + e.key + textAfterCursor;
|
||||
this.terminal.write(e.key + textAfterCursor + "\b".repeat(textAfterCursor.length));
|
||||
this.cursorPosition++;
|
||||
this.terminalInputBuffer += e.key;
|
||||
console.log(this.terminalInputBuffer);
|
||||
this.terminal.write(e.key);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -247,7 +258,6 @@ export default {
|
|||
<style scoped lang="scss">
|
||||
.main-terminal {
|
||||
height: 100%;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue