Skip to content

Instantly share code, notes, and snippets.

@mewmix
Created October 13, 2020 05:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mewmix/23b1c26e8b6d23ff897080984806c870 to your computer and use it in GitHub Desktop.
Save mewmix/23b1c26e8b6d23ff897080984806c870 to your computer and use it in GitHub Desktop.
Animated Terminal Session
<div class="terminal-window">
<header>
<div class="button green"></div>
<div class="button yellow"></div>
<div class="button red"></div>
</header>
<section class="terminal">
<div class="history"></div>
$&nbsp;<span class="prompt"></span>
<span class="typed-cursor"></span>
</section>
</div>
<!-- data -->
<div class="terminal-data mimik-run-output">
<br>Found 1 feature<br>
----------------------------------------------<br>
Feature: Alexander Klein <span class="gray"># ./features/alexander.klein</span><br><br>
&nbsp;&nbsp;Advanced Web Consulting<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="green">✓</span> <span class="gray">Windows Linux Mac OS </span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="green">✓</span> <span class="gray">Android iOS embedded systems </span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="green">✓</span> <span class="gray">Java, PHP, CSS, HTML, Solidity, Ajax </span><br>
<br>
<span class="gray">&nbsp;---------- ----------- ------- -------- --------</span><br>
&nbsp;&nbsp;Features&nbsp;&nbsp;&nbsp;Scenarios&nbsp;&nbsp;&nbsp;Skills &nbsp;&nbsp;&nbsp;Passed&nbsp;&nbsp;&nbsp;Failed<br>
<span class="gray">&nbsp;---------- ----------- ------- -------- --------</span><br>
&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="green">✓ 4</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 <br>
<br>
&nbsp;&nbsp;Completed 1 feature in 0.01s<br>
<br>
</div>
$(function() {
var data = [
{
action: 'type',
strings: ["sudo wget curiosity.sh"],
output: '<span class="gray">+lonliness@0.1.0 installed</span><br>&nbsp;',
postDelay: 1000
},
{
action: 'type',
strings: ["tar xzf curiosity.zip"],
output: ' ',
postDelay: 1000
},
{
action: 'type',
//clear: true,
strings: ['passion + curiosity run learn^400'],
output: $('.mimik-run-output').html()
},
{
action: 'type',
strings: ["that was easy!", ''],
postDelay: 2000
}
];
runScripts(data, 0);
});
function runScripts(data, pos) {
var prompt = $('.prompt'),
script = data[pos];
if(script.clear === true) {
$('.history').html('');
}
switch(script.action) {
case 'type':
// cleanup for next execution
prompt.removeData();
$('.typed-cursor').text('');
prompt.typed({
strings: script.strings,
typeSpeed: 30,
callback: function() {
var history = $('.history').html();
history = history ? [history] : [];
history.push('$ ' + prompt.text());
if(script.output) {
history.push(script.output);
prompt.html('');
$('.history').html(history.join('<br>'));
}
// scroll to bottom of screen
$('section.terminal').scrollTop($('section.terminal').height());
// Run next script
pos++;
if(pos < data.length) {
setTimeout(function() {
runScripts(data, pos);
}, script.postDelay || 1000);
}
}
});
break;
case 'view':
break;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://www.mattboldt.com/demos/typed-js/js/typed.custom.js"></script>
body {
background: #6D7074;
}
.terminal-window {
text-align: left;
width: 600px;
height: 360px;
border-radius: 10px;
margin: auto;
position: relative;
}
.terminal-window header {
background: #E0E8F0;
height: 30px;
border-radius: 8px 8px 0 0;
padding-left: 10px;
}
.terminal-window header .button {
width: 12px;
height: 12px;
margin: 10px 4px 0 0;
display: inline-block;
border-radius: 8px;
}
.terminal-window header .button.green {
background: #3BB662;
}
.terminal-window header .button.yellow {
background: #E5C30F;
}
.terminal-window header .button.red {
background: #E75448;
}
.terminal-window section.terminal {
color: white;
font-family: Menlo, Monaco, "Consolas", "Courier New", "Courier";
font-size: 11pt;
background: #30353A;
padding: 10px;
box-sizing: border-box;
position: absolute;
width: 100%;
top: 30px;
bottom: 0;
overflow: auto;
}
.terminal-window section.terminal .typed-cursor {
opacity: 1;
-webkit-animation: blink 0.7s infinite;
-moz-animation: blink 0.7s infinite;
animation: blink 0.7s infinite;
}
@keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-webkit-keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-moz-keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
.terminal-data { display: none; }
.terminal-window .gray { color: gray; }
.terminal-window .green { color: green;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment