Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ui/asciicast-annot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This is normal asciinema v1 recording with "var data =" line prepended.
var data =
{
"duration": 10.0,
"env": {
"TERM": "xterm",
"SHELL": "/bin/bash"
},
"version": 1,
"title": "dumb sample asciicast",
"height": 24,
"command": null,
"width": 80,
"annotations": [
{at:0.5, dur: 1, relx: 0.1, rely: 0.1, text: "annotation #1"},
{at:3.0, dur: 3, relx: 0.8, rely: 0.8, text: "annotation\n#2"}
],
"stdout": [
[
0,
"Just"
],
[
0.5,
" a dumb"
],
[
3.0,
" sample asciicast.\r\n"
],
]
}
43 changes: 43 additions & 0 deletions ui/index-annotations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/min.css" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
#controls {
background: #000;
}
button {
color: #fff;
background: none;
border: none;
font-size: 13pt;
height: 30px;
width: 3%;
margin: 0 0 0 2px;
}
button:focus {
outline: none;
}
.rangeslider--horizontal {
margin: 8px 2% 0 1%;
float:right;
width: 93%;
}
</style>
<script src="js/min.js"></script>
<script src="js/player.js"></script>
</head>
<body>
<div id="container"></div>
<!-- The file below is a normal asciinema recording
with "var data =" line prepended. -->
<script src="asciicast-annot.js"></script>
<script>
// You can pass null instead of audio
var p = player(null, $("#container"), data);
</script>
</body>
</html>
27 changes: 27 additions & 0 deletions ui/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var player = function(audioFile, containerElem, events) {
var init = function(audioFile, containerElem, events) {
Player.container = containerElem;

$('<div id="annot" style="border: 2px solid red; border-radius: 6px; background-color: white; padding: 3px; visibility: hidden; position: absolute;"></div>')
.appendTo(Player.container);

Player.termContainer = $('<div id="term"></div>')
.appendTo(Player.container);

Expand Down Expand Up @@ -62,6 +65,11 @@ var player = function(audioFile, containerElem, events) {
Player.eventOff = 0;
Player.rem = 0;
Player.timerHandle = undefined;
Player.annotations = [];
if (events.annotations !== undefined) {
Player.annotations = events.annotations;
}
Player.annOff = 0;

Player.playTime = 0;

Expand All @@ -73,6 +81,7 @@ var player = function(audioFile, containerElem, events) {
Player.term.clear();
Player.term.reset();
Player.pos = 0;
Player.annOff = 0;
}

var i = back ? 0 : Player.eventOff;
Expand All @@ -81,6 +90,9 @@ var player = function(audioFile, containerElem, events) {
Player.pos + Player.termEvents[i][0] <= (t / 1000)) {
str += Player.termEvents[i][1];
Player.pos += Player.termEvents[i++][0];
if (Player.annOff < Player.annotations.length && Player.pos >= Player.annotations[Player.annOff].at) {
Player.annOff++;
}
}

i = i == Player.termEvents.length ? i - 1 : i;
Expand Down Expand Up @@ -108,6 +120,21 @@ var player = function(audioFile, containerElem, events) {
} else {
str = Player.termEvents[Player.eventOff][1];
Player.pos += Player.termEvents[Player.eventOff++][0];
if (Player.annOff < Player.annotations.length && Player.pos >= Player.annotations[Player.annOff].at) {
var ann = Player.annotations[Player.annOff++];
var off = $("#term").offset();
var w = $("#term").width();
var h = $("#term").height();
$("#annot").css({
position: "absolute",
left: off.left + w * ann.relx,
top: off.top + h * ann.rely,
"z-index": 10000,
visibility: "visible"
});
$("#annot").html(ann.text.replace("\n", "<br/>"));
setTimeout(function() { $("#annot").css("visibility", "hidden"); }, ann.dur * 1000);
}
}

Player.term.write(str);
Expand Down