]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Monitor.js
1 Ext
.define('PVE.qemu.Monitor', {
2 extend
: 'Ext.panel.Panel',
4 alias
: 'widget.pveQemuMonitor',
6 // start to trim saved command output once there are *both*, more than `commandLimit` commands
7 // executed and the total of saved in+output is over `lineLimit` lines; repeat by dropping one
8 // full command output until either condition is false again
12 initComponent: function() {
15 var nodename
= me
.pveSelNode
.data
.node
;
17 throw "no node name specified";
20 var vmid
= me
.pveSelNode
.data
.vmid
;
22 throw "no VM ID specified";
29 var textbox
= Ext
.createWidget('panel', {
35 bodyStyle
: 'font-family: monospace;',
38 var scrollToEnd = function() {
39 var el
= textbox
.getTargetEl();
40 var dom
= Ext
.getDom(el
);
42 var clientHeight
= dom
.clientHeight
;
43 // BrowserBug: clientHeight reports 0 in IE9 StrictMode
44 // Instead we are using offsetHeight and hardcoding borders
45 if (Ext
.isIE9
&& Ext
.isStrict
) {
46 clientHeight
= dom
.offsetHeight
+ 2;
48 dom
.scrollTop
= dom
.scrollHeight
- clientHeight
;
51 var refresh = function() {
52 textbox
.update(`<pre>${commands.flat(2).join('\n')}</pre>`);
56 let recordInput
= line
=> {
57 commands
.push([line
]);
59 // drop oldest commands and their output until we're not over both limits anymore
60 while (commands
.length
> me
.commandLimit
&& commands
.flat(2).length
> me
.lineLimit
) {
65 let addResponse
= lines
=> commands
[commands
.length
- 1].push(lines
);
67 var executeCmd = function(cmd
) {
68 recordInput("# " + Ext
.htmlEncode(cmd
), true);
71 if (history
.length
> 20) {
78 Proxmox
.Utils
.API2Request({
79 params
: { command
: cmd
},
80 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ "/monitor",
83 success: function(response
, opts
) {
84 var res
= response
.result
.data
;
85 addResponse(res
.split('\n').map(line
=> Ext
.htmlEncode(line
)));
88 failure: function(response
, opts
) {
89 Ext
.Msg
.alert('Error', response
.htmlStatus
);
95 layout
: { type
: 'border' },
106 fieldStyle
: 'font-family: monospace;',
109 afterrender: function(f
) {
111 recordInput("Type 'help' for help.");
114 specialkey: function(f
, e
) {
115 var key
= e
.getKey();
118 var cmd
= f
.getValue();
123 textbox
.scrollBy(0, -0.9*textbox
.getHeight(), false);
126 textbox
.scrollBy(0, 0.9*textbox
.getHeight(), false);
129 if (histNum
+ 1 < history
.length
) {
130 f
.setValue(history
[++histNum
]);
136 f
.setValue(history
[--histNum
]);
149 var field
= me
.query('textfield[name="cmd"]')[0];
150 field
.focus(false, true);