40
40
}
41
41
</style>
42
42
<script>
43
- class CommandLine{
43
+ class CommandLine{
44
44
static parseCommand(event){
45
45
if(event.keyCode==13){
46
46
event.preventDefault();
47
47
CommandLine.sendCommand(event.srcElement.value)
48
48
event.srcElement.value = "";
49
49
}
50
+ if(event.keyCode==38){
51
+ event.preventDefault();
52
+ CommandLine.historyindex += 1;
53
+ CommandLine.historyindex = Math.min(CommandLine.historyindex, CommandLine.commandhistory.length -1 );
54
+ CommandLine.loadHistoryCommand();
55
+ }
56
+ if(event.keyCode==40){
57
+ event.preventDefault();
58
+ CommandLine.historyindex -= 1;
59
+ CommandLine.historyindex = Math.max(-1, CommandLine.historyindex);
60
+ CommandLine.loadHistoryCommand();
61
+ }
50
62
}
51
63
static sendCommand(command){
64
+ CommandLine.commandhistory.unshift(command);
52
65
let xhttp = new XMLHttpRequest();
53
66
xhttp.onreadystatechange = function() {
54
67
if (this.readyState == 4 && this.status == 200) {
@@ -63,7 +76,15 @@ class CommandLine{
63
76
static print(content){
64
77
document.getElementById("content").innerHTML += "<br>"+content;
65
78
}
79
+ static loadHistoryCommand(){
80
+ if(CommandLine.historyindex==-1) document.getElementsByTagName('textarea')[0].value = "";
81
+ else document.getElementsByTagName('textarea')[0].value = CommandLine.commandhistory[CommandLine.historyindex];
82
+ document.getElementsByTagName('textarea')[0].focus();
83
+ document.getElementsByTagName('textarea')[0].setSelectionRange(document.getElementsByTagName('textarea')[0].value.length,document.getElementsByTagName('textarea')[0].value.length);
84
+ }
66
85
}
86
+ CommandLine.commandhistory = [];
87
+ CommandLine.historyindex = -1;
67
88
</script>
68
89
</head>
69
90
<body onclick="document.getElementsByTagName('textarea')[0].focus();">
0 commit comments