<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Terminal</title>
<script src="./script/jquery.min.js"></script>
<style>
* {
margin: 0 0;
}
#terminal {
width: 1440px;
height: 810px;
position: absolute;
background: black;
color: white;
}
#cmdInput, #cmdHist {
width: 1px;
height: 1px;
}
</style>
<script>
$(() => {
var files = ['sys.log', 'var.log', 'hist.log']
var content = {
'sys.log':'this is sys.log',
'var.log':'this is var.log',
'hist.log':'this is hist.log',
};
var is_Show = true;
var hist = 'root@web# ';
const ps = 'root@web# ';
$('#contHist').text(hist);
$('#cmdInput').focus();
$('#cmdInput').on('input', () => {
const cmd = $('#cmdInput').val();
$('#content').text(cmd);
});
function ls() {
hist += '<br>';
for (let idx in files) {
hist += files[idx] + ' ';
}
hist += '<br>';
}
function exit() {
$('#terminal').hide();
}
function clear() {
hist = '';
}
function cat(args) {
hist += '<br>';
for (let i = 1; i < args.length; i++) {
hist += content[args[i]] + '<br>';
}
}
function touch(args) {
for (let i = 1; i < args.length; i++) {
content[args[i]] = '';
files.push(args[i]);
}
hist += '<br>';
}
function modify(args) {
content[args[1]] = args[2];
hist += '<br>';
}
function err() {
hist += '<br> command does not exist ! <br>';
}
$(window).on('keydown', (evt) => {
const key = evt.which;
if (evt.which === 13) {
hist += $('#content').text();
const cmd = $('#content').text();
var args = cmd.split(' ');
if (args[0] === 'ls') ls();
else if (args[0] === 'exit') exit();
else if (args[0] === 'clear') clear();
else if (args[0] === 'cat') cat(args);
else if (args[0] === 'touch') touch(args);
else if (args[0] === 'modify') modify(args);
else err();
hist += ps;
$('#cmdHist').text(hist);
$('#contHist').html(hist);
$('#content').text('');
$('#cmdInput').val('');
}
});
setInterval(() => {
if (is_Show) {
is_Show = false;
$('#underline').hide();
} else {
is_Show = true;
$('#underline').show();
}
}, 700);
});
</script>
</head>
<body>
<div id="terminal">
<span id="contHist"></span>
<span id="content"></span>
<span id="underline">_<span>
</div>
<input id="cmdInput" type="text">
<textarea id="cmdHist"></textarea>
</body>
</html>
显然 只有一个虚拟目录 && 并没有高级的功能