Created
August 23, 2017 11:22
-
-
Save BaseCase/15b6c693b09921d0555925737fc2dc1b to your computer and use it in GitHub Desktop.
bwaaaaaaamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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