-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.html
67 lines (58 loc) · 2.01 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
<!DOCTYPE html>
<html>
<head>
<title>Terminal.js Demo</title>
<link rel="stylesheet" href="terminal.css">
<style>
body {
background: black;
color: white;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Terminal.js Demo</h1>
<div id="terminal">
<p>Type 'help' to get started.</p>
<p class="hidden">
<span class="prompt">[email protected] ∼ > </span>
<span contenteditable="true" class="input"> </span>
</p>
</div>
<script src="terminal.js"></script>
<script>
var commands = {};
commands.help = function() {
var output = "<div>" +
"<ul>" +
"<li><strong>help</strong> - display this help.</li>" +
"<li><strong>hello NAME</strong> - displays a greeting for NAME.</li>" +
"<li><strong>weather LOCATION</strong> - show weather for LOCATION</li>" +
"</ul></div>";
return output;
};
commands.hello = function(args) {
if(args.length < 2) return "<p>Hello. Why don't you tell me your name?</p>";
return "Hello " + args[1];
};
commands.weather = function(args) {
args.shift();
var xhr = new XMLHttpRequest();
xhr.open("get", "http://api.openweathermap.org/data/2.5/weather?units=metric&q=" + args.join(" "), false);
xhr.send();
if(xhr.status !== 200) return "Error :(";
weather = JSON.parse(xhr.responseText);
return "<p><img style=\"vertical-align: middle\" src=\"http://openweathermap.org/img/w/" +
weather.weather[0].icon + ".png\">" +
weather.weather[0].description + ", " +
weather.main.temp + " °C</p>"
};
Terminal.init(document.getElementById("terminal"), commands);
</script>
</body>
</html>