Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Created August 23, 2017 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaseCase/15b6c693b09921d0555925737fc2dc1b to your computer and use it in GitHub Desktop.
Save BaseCase/15b6c693b09921d0555925737fc2dc1b to your computer and use it in GitHub Desktop.
bwaaaaaaamp
<html>
<head>
<style>
.shadow-input { opacity: 0; }
.prompt { font-family: monospace; }
.cursor {
display: flex;
flex-direction: row;
position: absolute;
}
.cursor .offset { opacity: 0; }
.cursor .caret {
background-color: green;
display: inline-block;
height: 1em;
opacity: .5;
width: 8px;
}
</style>
</head>
<body>
<div class="prompt">
<div class="cursor">
<span class="offset"></span>
<span class="caret"></span>
</div>
<div class="content"></div>
</div>
<input type="text" class="shadow-input" />
<script>
(function() {
let shadow_input = document.querySelector(".shadow-input"),
prompt_text = document.querySelector(".prompt .content"),
cursor_offset = document.querySelector(".cursor .offset");
shadow_input.addEventListener("keydown", function handle_prompt_keydown() {
setTimeout(render_prompt, 15);
});
function render_prompt() {
let buffer = shadow_input.value,
cursor_position = shadow_input.selectionStart;
prompt_text.textContent = buffer;
let positioning_text = buffer.slice(0, cursor_position);
cursor_offset.textContent = positioning_text;
}
shadow_input.focus();
render_prompt();
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment