all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager v2] fix #4318: ui: qemu/Monitor: rework output retention mechanism
@ 2022-11-02 11:28 Dominik Csapak
  2022-11-16 19:23 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2022-11-02 11:28 UTC (permalink / raw)
  To: pve-devel

instead of saving maximum 500 lines, count commands + lines, and only
if both are over the limit, truncate the command list

this way, at least the last 10 commands + output are always visible, and
no visible output is truncated, while still not letting the log
grow infinitely

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* adapted to thomas suggestions
* var commands => let commands (since i'm touching the line anyway)
* i adapted the suggest comment from thomas, so it's more clear (imho)
 www/manager6/qemu/Monitor.js | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/www/manager6/qemu/Monitor.js b/www/manager6/qemu/Monitor.js
index d85018e6..7f1626e3 100644
--- a/www/manager6/qemu/Monitor.js
+++ b/www/manager6/qemu/Monitor.js
@@ -3,7 +3,10 @@ Ext.define('PVE.qemu.Monitor', {
 
     alias: 'widget.pveQemuMonitor',
 
-    maxLines: 500,
+    // ouput is trimmed when it's over both commandLimit and lineLimit
+    // by removing the first commands and their output
+    commandLimit: 10,
+    lineLimit: 5000,
 
     initComponent: function() {
 	var me = this;
@@ -20,7 +23,7 @@ Ext.define('PVE.qemu.Monitor', {
 
 	var history = [];
 	var histNum = -1;
-	var lines = [];
+	let commands = [];
 
 	var textbox = Ext.createWidget('panel', {
 	    region: 'center',
@@ -45,19 +48,23 @@ Ext.define('PVE.qemu.Monitor', {
 	};
 
 	var refresh = function() {
-	    textbox.update('<pre>' + lines.join('\n') + '</pre>');
+	    textbox.update(`<pre>${commands.flat(2).join('\n')}</pre>`);
 	    scrollToEnd();
 	};
 
-	var addLine = function(line) {
-	    lines.push(line);
-	    if (lines.length > me.maxLines) {
-		lines.shift();
+	let recordInput = line => {
+	    commands.push([line]);
+
+	    // drop oldest commands and their output until we're not over both limits anymore
+	    while (commands.length > me.commandLimit && commands.flat(2).length > me.lineLimit) {
+		commands.shift();
 	    }
 	};
 
+	let addResponse = lines => commands[commands.length - 1].push(lines);
+
 	var executeCmd = function(cmd) {
-	    addLine("# " + Ext.htmlEncode(cmd));
+	    recordInput("# " + Ext.htmlEncode(cmd), true);
 	    if (cmd) {
 		history.unshift(cmd);
 		if (history.length > 20) {
@@ -74,9 +81,7 @@ Ext.define('PVE.qemu.Monitor', {
 		waitMsgTarget: me,
 		success: function(response, opts) {
 		    var res = response.result.data;
-		    Ext.Array.each(res.split('\n'), function(line) {
-			addLine(Ext.htmlEncode(line));
-		    });
+		    addResponse(res.split('\n').map(line => Ext.htmlEncode(line)));
 		    refresh();
 		},
 		failure: function(response, opts) {
@@ -102,7 +107,7 @@ Ext.define('PVE.qemu.Monitor', {
 		    listeners: {
 			afterrender: function(f) {
 			    f.focus(false);
-			    addLine("Type 'help' for help.");
+			    recordInput("Type 'help' for help.");
 			    refresh();
 			},
 			specialkey: function(f, e) {
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH manager v2] fix #4318: ui: qemu/Monitor: rework output retention mechanism
  2022-11-02 11:28 [pve-devel] [PATCH manager v2] fix #4318: ui: qemu/Monitor: rework output retention mechanism Dominik Csapak
@ 2022-11-16 19:23 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2022-11-16 19:23 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 02/11/2022 um 12:28 schrieb Dominik Csapak:
> instead of saving maximum 500 lines, count commands + lines, and only
> if both are over the limit, truncate the command list
> 
> this way, at least the last 10 commands + output are always visible, and
> no visible output is truncated, while still not letting the log
> grow infinitely
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v1:
> * adapted to thomas suggestions
> * var commands => let commands (since i'm touching the line anyway)
> * i adapted the suggest comment from thomas, so it's more clear (imho)

extended that a bit

>  www/manager6/qemu/Monitor.js | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-16 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 11:28 [pve-devel] [PATCH manager v2] fix #4318: ui: qemu/Monitor: rework output retention mechanism Dominik Csapak
2022-11-16 19:23 ` [pve-devel] applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal