Skip to content

Instantly share code, notes, and snippets.

@Baudin999
Last active August 20, 2016 11:54
Show Gist options
  • Save Baudin999/a6c43d7e3ea5fd41b3cc34bebe2728b2 to your computer and use it in GitHub Desktop.
Save Baudin999/a6c43d7e3ea5fd41b3cc34bebe2728b2 to your computer and use it in GitHub Desktop.
A custom promt
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="console">
<div class="output">
<ul class="messages">
</ul>
</div>
<div class="command-line">
<span class="prompt">></span>
<span class="content"></span>
<span class="cursor">_</span>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
var content = document.querySelector('.content');
var cursor = document.querySelector('.cursor');
var messages = document.querySelector('.messages');
var index = 0;
var ignore = ["Shift", "Control", "Alt", "CapsLock", "Meta", "Backspace", "Enter"];
document.addEventListener('keydown', function(event) {
if (ignore.indexOf(event.key) === -1) {
content.innerText += event.key;
index += 1;
}
if (event.key === "Backspace") {
content.innerText = content.innerText.slice(0, -1);
}
if (event.key === "Enter") {
var li = document.createElement("li");
li.innerText = content.innerText;
messages.appendChild(li);
content.innerText = "";
index = 0;
}
});
.console {
height: 500px;
width: 500px;
font-familly: consolas;
background: black;
color: white;
position: relative;
}
.console .command-line {
border-top: 1px solid white;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 25px;
line-height: 25px;
padding-left: 5px;
-webkit-font-smoothing: antialiased;
font-smoothing: antialiased;
}
.console .output {
position: absolute;
top: 0;
bottom: 25px;
left: 0;
right: 0;
overflow-y: auto;
padding: 5px;
}
.console .output ul {
margin: 0;
padding: 0;
}
.console .output li {
display: block;
line-height: 25px;
}
.console .output li:before {
content: ">";
margin-right: 5px;
}
.console .command-line .cursor {
animation: 1s blink step-end infinite;
}
@keyframes "blink" {
from, to {
color: transparent;
}
50% {
color: black;
}
}
@-webkit-keyframes "blink" {
from, to {
color: transparent;
}
50% {
color: white;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment