]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/qemu/Monitor.js
ui: cloudinit: match backend privilege checks
[pve-manager.git] / www / manager6 / qemu / Monitor.js
index 900aee584e85d2e5f084dc6b766703bd86495750..7a84b39acd54c12a28627e657238d1146507159b 100644 (file)
@@ -3,9 +3,13 @@ Ext.define('PVE.qemu.Monitor', {
 
     alias: 'widget.pveQemuMonitor',
 
-    maxLines: 500,
+    // start to trim saved command output once there are *both*, more than `commandLimit` commands
+    // executed and the total of saved in+output is over `lineLimit` lines; repeat by dropping one
+    // full command output until either condition is false again
+    commandLimit: 10,
+    lineLimit: 5000,
 
-    initComponent : function() {
+    initComponent: function() {
        var me = this;
 
        var nodename = me.pveSelNode.data.node;
@@ -20,7 +24,7 @@ Ext.define('PVE.qemu.Monitor', {
 
        var history = [];
        var histNum = -1;
-       var lines = [];
+       let commands = [];
 
        var textbox = Ext.createWidget('panel', {
            region: 'center',
@@ -28,7 +32,7 @@ Ext.define('PVE.qemu.Monitor', {
            autoScroll: true,
            border: true,
            margins: '5 5 5 5',
-           bodyStyle: 'font-family: monospace;'
+           bodyStyle: 'font-family: monospace;',
        });
 
        var scrollToEnd = function() {
@@ -45,19 +49,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,14 +82,12 @@ 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) {
                    Ext.Msg.alert('Error', response.htmlStatus);
-               }
+               },
            });
        };
 
@@ -92,7 +98,7 @@ Ext.define('PVE.qemu.Monitor', {
                textbox,
                {
                    region: 'south',
-                   margins:'0 5 5 5',
+                   margins: '0 5 5 5',
                    border: false,
                    xtype: 'textfield',
                    name: 'cmd',
@@ -102,7 +108,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) {
@@ -134,18 +140,18 @@ Ext.define('PVE.qemu.Monitor', {
                                default:
                                    break;
                            }
-                       }
-                   }
-               }
+                       },
+                   },
+               },
            ],
            listeners: {
                show: function() {
                    var field = me.query('textfield[name="cmd"]')[0];
                    field.focus(false, true);
-               }
-           }
+               },
+           },
        });
 
        me.callParent();
-    }
+    },
 });