Skip to content

Commit 78e5da0

Browse files
committed
added help command for overview of installed programs
1 parent 107d79c commit 78e5da0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

commandline/programms/help/init.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
function helpMain($args, $command){
3+
lCommand::write("> $command");
4+
$content = "installed programs:<br>";
5+
$dirs = array_filter(glob('programms/*'), 'is_dir');
6+
foreach($dirs as $s){
7+
$content .= str_replace("programms/", "", $s)."<br>";
8+
}
9+
lCommand::write($content);
10+
}
11+
?>

index.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,28 @@
4040
}
4141
</style>
4242
<script>
43-
class CommandLine{
43+
class CommandLine{
4444
static parseCommand(event){
4545
if(event.keyCode==13){
4646
event.preventDefault();
4747
CommandLine.sendCommand(event.srcElement.value)
4848
event.srcElement.value = "";
4949
}
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+
}
5062
}
5163
static sendCommand(command){
64+
CommandLine.commandhistory.unshift(command);
5265
let xhttp = new XMLHttpRequest();
5366
xhttp.onreadystatechange = function() {
5467
if (this.readyState == 4 && this.status == 200) {
@@ -63,7 +76,15 @@ class CommandLine{
6376
static print(content){
6477
document.getElementById("content").innerHTML += "<br>"+content;
6578
}
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+
}
6685
}
86+
CommandLine.commandhistory = [];
87+
CommandLine.historyindex = -1;
6788
</script>
6889
</head>
6990
<body onclick="document.getElementsByTagName('textarea')[0].focus();">

0 commit comments

Comments
 (0)