This repository was archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathterminal_filesystem.dart
63 lines (50 loc) · 1.76 KB
/
terminal_filesystem.dart
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
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This is a port of "Exploring the FileSystem APIs" to Dart.
// See: http://www.html5rocks.com/en/tutorials/file/filesystem/
library terminal_filesystem;
import 'dart:convert' show HtmlEscape;
import 'dart:html';
part 'terminal.dart';
class TerminalFilesystem {
Terminal term;
void run() {
term = new Terminal('#input-line', '#output', '#cmdline');
term.initializeFilesystem(false, 1024 * 1024);
if (!window.location.hash.isEmpty) {
var theme = window.location.hash.substring(1, window.location.hash.length).split('=')[1];
term.setTheme(theme);
} else if (window.localStorage.containsKey('theme')) {
term.setTheme(window.localStorage['theme']);
}
// Setup the DnD listeners for file drop.
var body = document.body;
body.onDragEnter.listen(onDragEnter);
body.onDragOver.listen(onDragOver);
body.onDrop.listen(onDrop);
}
void onDragEnter(MouseEvent event) {
event.stopPropagation();
event.preventDefault();
Element dropTarget = event.target;
dropTarget.classes.add('dropping');
}
void onDragOver(MouseEvent event) {
event.stopPropagation();
event.preventDefault();
// Explicitly show this is a copy.
event.dataTransfer.dropEffect = 'copy';
}
void onDrop(MouseEvent event) {
event.stopPropagation();
event.preventDefault();
Element dropTarget = event.target;
dropTarget.classes.remove('dropping');
term.addDroppedFiles(event.dataTransfer.files);
term.writeOutput('<div>File(s) added!</div>');
}
}
void main() {
new TerminalFilesystem().run();
}