]> git.proxmox.com Git - pve-manager.git/commitdiff
qemu/Monitor: save the last 20 commands
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 26 Jan 2018 14:25:26 +0000 (15:25 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 29 Jan 2018 14:08:30 +0000 (15:08 +0100)
and make them available with the up/down arrow key

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Tested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/qemu/Monitor.js

index 686950adf930add680e695afed085566f9552a0c..4cfd1537a694957bdb2e67d5ae4682d92eb0ba86 100644 (file)
@@ -18,6 +18,8 @@ Ext.define('PVE.qemu.Monitor', {
            throw "no VM ID specified";
        }
 
+       var history = [];
+       var histNum = -1;
        var lines = [];
 
        var textbox = Ext.createWidget('panel', {
@@ -56,6 +58,14 @@ Ext.define('PVE.qemu.Monitor', {
 
        var executeCmd = function(cmd) {
            addLine("# " + Ext.htmlEncode(cmd));
+           if (cmd) {
+               history.unshift(cmd);
+               if (history.length > 20) {
+                   history.splice(20);
+               }
+           }
+           histNum = -1;
+
            refresh();
            Proxmox.Utils.API2Request({
                params: { command: cmd },
@@ -96,14 +106,33 @@ Ext.define('PVE.qemu.Monitor', {
                            refresh();
                        },
                        specialkey: function(f, e) {
-                           if (e.getKey() === e.ENTER) {
-                               var cmd = f.getValue();
-                               f.setValue('');
-                               executeCmd(cmd);
-                           } else if (e.getKey() === e.PAGE_UP) {
-                               textbox.scrollBy(0, -0.9*textbox.getHeight(), false);
-                           } else if (e.getKey() === e.PAGE_DOWN) {
-                               textbox.scrollBy(0, 0.9*textbox.getHeight(), false);
+                           var key = e.getKey();
+                           switch (key) {
+                               case e.ENTER:
+                                   var cmd = f.getValue();
+                                   f.setValue('');
+                                   executeCmd(cmd);
+                                   break;
+                               case e.PAGE_UP:
+                                   textbox.scrollBy(0, -0.9*textbox.getHeight(), false);
+                                   break;
+                               case e.PAGE_DOWN:
+                                   textbox.scrollBy(0, 0.9*textbox.getHeight(), false);
+                                   break;
+                               case e.UP:
+                                   if (histNum + 1 < history.length) {
+                                       f.setValue(history[++histNum]);
+                                   }
+                                   e.preventDefault();
+                                   break;
+                               case e.DOWN:
+                                   if (histNum > 0) {
+                                       f.setValue(history[--histNum]);
+                                   }
+                                   e.preventDefault();
+                                   break;
+                               default:
+                                   break;
                            }
                        }
                    }