forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (148 loc) · 6.35 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/noupper_white.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<link rel="stylesheet" href="node_modules/xterm/dist/xterm.css" />
<script type="module">
// Import Xterm reqs.
import * as attach from './node_modules/xterm/dist/addons/attach/attach.js';
import * as fit from './node_modules/xterm/dist/addons/fit/fit.js';
</script>
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section><h1>Title Slide</h1></section>
<section>
<section>
<h2>Slide 2</h2>
</section>
<!-- Terminal slides MUST have a unique data-state="terminal-*" value. -->
<section data-state="terminal-example">
<h3>This is my terminal.</h3>
<!--
The terminal will be attached to the first child element with data-is-terminal.
The data-cwd attribute sets a relative or absolute working directory, and is optional.
Relative paths are created in the 'terms' directory in this package as needed.
-->
<div data-is-terminal data-cwd="subdir"></div>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script defer="true">
// Stores all terminal references, added as their slides come into view, by the state name.
var initializedTerminals = {};
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
// Retain slide info in URL / history.
history: true,
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'node_modules/xterm/dist/xterm.js', async: true, callback: function() {
Terminal.applyAddon(attach);
Terminal.applyAddon(fit);
var hostPort = location.hostname + ':' + location.port;
var terminalsUrl = 'http://' + hostPort + '/terminals';
var startSlide = Reveal.getCurrentSlide();
// Find all sections with an embedded terminal, and bind an event listener for when
// they're clicked into.
var sectionEls = document.querySelectorAll('section[data-state^="terminal"]');
sectionEls.forEach(function(section) {
var stateName = section.getAttribute('data-state');
var handler = function () {
if (initializedTerminals[stateName]) {
return;
}
var terminalEl = section.querySelector('*[data-is-terminal]');
if (!terminalEl) {
console.warn('section ' + stateName + ' had no associated terminal, ignoring');
initializedTerminals[stateName] = true;
return;
}
console.log('initializing terminal for section ' + stateName);
var pid = 0;
var term = initializedTerminals[stateName] = new Terminal({
'macOptionIsMeta': true,
// Use a light-colored theme. The default is a black background.
'theme': {
'background': '#eeeeee',
'foreground': '#000000',
'cursor': '#000000',
'cursorAccent': '#ffffff',
'selection': 'rgba(0, 0, 0, 0.3)',
},
// These values produce a legible terminal on a slide with a title + one line of
// text, without the terminal falling off of the slide.
'cols': 70,
'rows': 18,
'fontSize': 24
});
term.on('resize', function (size) {
if (!pid) {
return;
}
var cols = size.cols,
rows = size.rows,
url = terminalsUrl + '/' + pid + '/size?cols=' + cols + '&rows=' + rows;
fetch(url, {method: 'POST'});
});
term.open(terminalEl);
term.fit();
Reveal.layout();
var cwd = terminalEl.getAttribute('data-cwd');
fetch(terminalsUrl + '?cols=' + term.cols + '&rows=' + term.rows +
(cwd ? '&cwd=' + cwd : ''),
{method: 'POST'}).then(function (res) {
res.text().then(function (processId) {
console.log('connecting to PID ' + processId);
pid = processId;
socket = new WebSocket('ws://' + hostPort + '/terminals/' + processId);
socket.onopen = function() {
term.attach(socket);
term._initialized = true;
term.fit();
Reveal.layout();
};
});
});
};
if (startSlide === section) {
handler();
} else {
Reveal.addEventListener(stateName, handler, false);
};
});
} }
]
});
</script>
<script>
// LiveReload Updates (hardcoded).
document.write('<script src="http://' + location.hostname +
':35729/livereload.js?snipver=1"></' +
'script>');
</script>
</body>
</html>