Skip to content

Commit 210fe2d

Browse files
committedApr 16, 2020
Revert to Commit 7e801e8, eliminating complexity
1 parent 0bbeab8 commit 210fe2d

34 files changed

+921
-6263
lines changed
 

‎CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please note we have a code of conduct (below), please follow it in all your inte
66

77
## Code Style and Formating Guide
88

9-
- Restrict Javascript to **ES6** standard to avoid need for transpiling and maximize browser support.
9+
- Restrict Javascript to the latest supported natively in most browsers to avoid need for transpiling and maximize browser support.
1010
- Always comment code sections with jsdoc style comments for methods, functions and classes. Keep comments
1111
meaningful and helpful.
1212
- Comment complex or interesting sections of code.

‎README.md

+32-69
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ Terminal Faker
1111
alt="follow on Twitter"></a>
1212
</div>
1313

14-
![Logo](src/favicon.png)
14+
![Logo](favicon.png)
1515

1616
An extensible pseudo-terminal in Javascript.
1717

1818
# What's this?
19-
20-
A pure Javascript, mobile-friendly, Linux-like terminal simulation for use in a browser. There is a **[live demo here](https://syntaxseed.github.io/terminalfaker/src/)**.
19+
A pure native Javascript, mobile-friendly, Linux-like terminal simulation for use in a browser. There is a **[live demo here](https://syntaxseed.github.io/terminalfaker/)**.
2120

2221
Originally forked from [AVGP/terminal.js](https://github.com/AVGP/terminal.js).
2322

@@ -27,84 +26,74 @@ You can do a bunch of things with it:
2726
- Create a terminal emulator for something that exposes an interface in a browser-consumable way (CORS, Websocket, WebRTC, ...).
2827
- Create a text-based adventure game in the browser.
2928
- Create an educational tool for learning command line applications.
30-
- Create a terminal style collection of docs.
3129
- Etc.
3230

33-
## Features
34-
35-
- A terminal-like look and feel.
36-
- Built in set of basic common commands.
37-
- Autocomplete on commands and files/paths.
38-
- Built in help for commands.
39-
- Customizable boot message.
40-
- Editable file of custom commands.
41-
4231
## How do I use it?
4332

4433
The easiest way to get started is to use the included "index.html" file and modify it for your needs. The basic usage is:
4534

46-
1. Include the "terminal.css" and the javascript files.
35+
1. Include the "terminal.css" and the "bundle.min.js" & "filesystem.js" files.
4736
2. Have a container element (e.g. a div) with a child element holding a contenteditable element of class "input" and another span of class "prompt" with the actual prompt line you want to display.
48-
3. Create an object with methods that will be your custom commands (see below for the details of how this works).
49-
4. Include the minified bundle. - **Ready to roll!**
37+
3. Create an object with methods that will be your commands (see below for the details of how this works).
38+
4. Call terminal.init and pass the container element, your commands object, and a callback which creates the custom prompt. - **Ready to roll!**
5039

51-
Here's a **minimal** example with one custom command:
40+
Here's a **minimal** example with one command:
5241

5342
```html
54-
<div id="terminal">
43+
<div id="terminal">
44+
<p id="boot">Type 'help' to get started.</p>
5545
<p class="hidden">
5646
<span class="prompt"></span>
57-
<span contenteditable="true" class="input" autocorrect="off" autocapitalize="none" autocomplete="off"> </span>
47+
<span contenteditable="true" class="input" autocorrect="off" autocapitalize="none" autocomplete="off"> </span>
5848
</p>
5949
</div>
6050

61-
<!-- Configuration -->
62-
<script>
63-
const TF_CONFIG_BOOT_LOADER = true; // Whether to show the longer boot loading startup message.
64-
const TF_CONFIG_ELEMENT_ID = "terminal"; // Id of the Div to create the terminal in. Should be defined above.
65-
</script>
51+
<script src="js/bundle.min.js"></script>
52+
<script src="js/filesystem.js"></script>
6653

67-
<!-- Global Custom Definitions -->
6854
<script>
69-
var customCommands = {};
70-
customCommands.cow = {
55+
var commands = {};
56+
commands.cow = {
7157
about: "What does the cow say?",
7258
exe: function() {
73-
return "Moooooo!";
59+
return "Moooooo!";
7460
}
7561
};
76-
</script>
7762
78-
<!-- Minified build -->
79-
<script src="js/bundle.min.js"></script>
63+
// Set the command prompt style:
64+
var customPrompt = function () { return "guest@TerminalFaker $ ";};
65+
66+
// Initialize the terminal:
67+
var term = Terminal.init(document.getElementById("terminal"), commands, customPrompt);
68+
</script>
8069
```
8170

8271
## Extensible command interface
8372

8473
The terminal is only a way to interact with "commands" and "commands" are a bundles of functionality.
8574
So to use the terminal, you'll need to create a bunch of functions that actually do something - and that's not hard.
8675

87-
First we modify our minimal example to load in custom commands found in "js/customCommands.js".
76+
First we modify our minimal example to load in custom commands found in "js/commands.js".
8877

8978
```html
9079
...
91-
<!-- Global Custom Definitions -->
92-
<script src="js/customCommands.js"></script>
80+
<script src="js/bundle.min.js"></script>
81+
<script src="js/filesystem.js"></script>
82+
<script src="js/commands.js"></script>
9383
...
9484
```
9585

96-
Then, in customCommands.js we will define custom commands (there are a couple examples in there already for you).
86+
Then, in commands.js we will define custom commands (there are a couple examples in there already for you).
9787

9888
### A greeting command
99-
10089
So let's build a command that greets the user with the name she enters, like this:
10190

10291
```bash
10392
$ hello Alice
10493
Hi there, Alice
10594
```
10695

107-
In customCommands.js this is done by creating a "customCommands" object and adding a "hello" object to it with an "about" property and a "exe" property.
96+
In commands.js this is done by creating a "customCommands" object and adding a "hello" object to it with an "about" property and a "exe" property.
10897

10998
"customCommands.hello.about" will contain a string of the help info to display if the user types ``help hello``.
11099

@@ -115,12 +104,13 @@ In this case, hello will take multiple arguments (separated by spaces), which wi
115104
```javascript
116105
var customCommands = {};
117106
customCommands.hello = {
118-
about: "hello [name ...]<br>&nbsp;&nbsp;Greet the user with a message.",
107+
about: "hello [arg ...]<br>&nbsp;&nbsp;Greet the user with a message.",
119108
exe: function (args) { // Executed for this command. args[0] contains the command name.
120109
if (args.length < 2) {
121110
return "Hello. Why don't you tell me your name?";
122111
}
123112
var name = "";
113+
// Concatenate all remaining arguments as the 'name'.
124114
for (var i = 1; i < args.length; i++) {
125115
name += args[i] + " ";
126116
}
@@ -137,51 +127,29 @@ That's it! Now the commands defined in "commands.js" will extend (and overwrite
137127

138128
## Custom boot message
139129

140-
A boot up message is simulated including delayed line-by line display of the boot text. Your terminal div must contain an element with id of "boot". This message is found in "main/boot.js" and is included via WebPack. To customize this message you will need to rebuild the minified bundle with WebPack. If you don't want this, set the configuration variable: ``var TF_CONFIG_BOOT_LOADER = false; `` in your javascript.
130+
A boot up message is simulated including delayed line-by line display of the boot text. This message is found in "js/boot.js" and is used by including the file *after* "terminal.js" is included. Your terminal div must contain an element with id of "boot". If you don't want this, just remove the "boot.js" file include. Or, if you are using the minified bundle of js, just set a variable: ``var useBootLoader = false;`` in your javascript.
141131

142132
Note that this will over-write any text already in the element with id "boot".
143133

144134
## A Mock Filesystem
145135

146136
![Basic Filesystem](media/screenshot2.png)
147137

148-
A simulated filesystem is initialized from the default content found in main/filesystem.js. Basic navigation around the filesystem is available. You can edit this file to customize the contents, then rebuild with WebPack.
138+
A simulated filesystem is initialized from the default content found in js/filesystem.js. Basic navigation around the filesystem is available. You can edit this file to customize the contents.
149139

150140
## Advanced Example
151141

152142
![Screenshot](media/screenshot1.png)
153143

154-
To see a full example including loading in system commands and the nicer boot message text, see the source of `index.html`.
144+
To see a full example including loading in system commands and the nicer boot message text, see the source of index.html.
155145

156146
## ToDo
157147

158148
* Basic filesystem (in progress).
159149
* Editing of files, mkdir, rmdir, etc.
160-
* See [GitHub issues](https://github.com/syntaxseed/terminalfaker/issues) page.
161150

162151
## Contributing
163-
164-
See the [Contributing Guide](CONTRIBUTING.md). Pull requests for existing issues are welcome. For other or major changes, please open an issue first to discuss what you would like to change.
165-
166-
### For Developers
167-
168-
Terminal Faker uses node packages, namely WebPack to create the minified JS bundle and to transpile the Javascript. When you first download the TerminalFaker source code, you must install the Node packages (make sure you have Node and NPM installed):
169-
170-
```bash
171-
npm install
172-
```
173-
174-
If you have edited the Javascript files, build a new minified bundle with the following command:
175-
176-
```bash
177-
npm run build
178-
```
179-
180-
To start `webpack` in watch mode run (automatically builds edited files):
181-
182-
```bash
183-
npm run build-dev
184-
```
152+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
185153

186154
## Authors
187155

@@ -190,14 +158,9 @@ To start `webpack` in watch mode run (automatically builds edited files):
190158

191159
### Contributors
192160

193-
Many thanks to the many who have contributed to this project (in no particular order):
194-
195161
* **Ben Brunton** - [benbrunton](https://github.com/benbrunton)
196162
* **Sahil Bondre** - [godcrampy](https://github.com/godcrampy)
197163
* **LapinoLapidus** - [LapinoLapidus](https://github.com/LapinoLapidus)
198-
* **Dzhamal Eziev** - [deziev](https://github.com/deziev)
199-
* **Jacob Shu** - [jacob-shu](https://github.com/jacob-shu)
200-
* **John Nenniger** - [John-Nenniger](https://github.com/John-Nenniger)
201164

202165
## License
203166

‎src/favicon.png ‎favicon.png

File renamed without changes.

‎index.html

+67-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
1-
<!--
2-
Redirect GitHub pages to src subdirectory.
3-
-->
4-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5-
<html><head><meta http-equiv=Refresh content="0;url=/src/"></head></html>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Terminal Faker Demo</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
6+
<meta name="theme-color" content="#000" />
7+
<link rel="icon" type="image/png" href="favicon.png" />
8+
<link rel="stylesheet" href="terminal.css" />
9+
<style>
10+
/* Over-write some styles or define on-page styles. */
11+
body {
12+
background: black;
13+
color: white;
14+
15+
width: 100%;
16+
height: 100%;
17+
18+
padding: 4px;
19+
margin: 0;
20+
21+
font-size:1.1em;
22+
23+
box-sizing: border-box;
24+
}
25+
h1 {
26+
font-size: 1.4em;
27+
}
28+
h1 a{
29+
color: #999;
30+
font-size:0.8em;
31+
text-decoration: none;
32+
}
33+
</style>
34+
35+
</head>
36+
<body>
37+
<h1><a href="https://github.com/syntaxseed/terminalfaker">Terminal Faker Demo</a></h1>
38+
39+
<div id="terminal">
40+
<p class="hidden">
41+
<span class="prompt"></span>
42+
<span contenteditable="true" class="input" autocorrect="off" autocapitalize="none" autocomplete="off"> </span>
43+
</p>
44+
</div>
45+
46+
<script src="js/bundle.min.js"></script>
47+
<!--<script src="js/src/terminal.js"></script>
48+
<script src="js/src/boot.js"></script>
49+
<script src="js/src/crypto.js"></script>
50+
<script src="js/src/system.js"></script>-->
51+
52+
53+
<script src="js/filesystem.js"></script>
54+
<script src="js/commands.js"></script>
55+
56+
<script>
57+
// Whether to use the longer boot load screen. If this is missing, defaults to true.
58+
var useBootLoader = true;
59+
60+
// Set the command prompt style:
61+
var customPrompt = function () { return "guest@TermFake ("+Terminal.path+") $ ";};
62+
63+
// Initialize the terminal:
64+
var term = Terminal.init(document.getElementById("terminal"), commands, customPrompt);
65+
</script>
66+
</body>
67+
</html>

‎js/bundle.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+17-32
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
/**
22
* Custom Terminal Commands
3+
* -----------------------------
34
* In this file, define custom commands for your terminal application.
45
* This will overwrite any built-in system commands if they exist.
56
*/
6-
77
var customCommands = {};
88

9-
10-
/**
11-
* Adds passed values.
12-
**/
13-
customCommands.add = {
14-
about: "add [value1] [value2]... [valueN]<br>&nbsp;&nbsp;Add specified values.",
15-
exe: (args) => {
16-
if (args.length < 2) {
17-
return "Too few arguments.";
18-
}
19-
let values = args.slice(1);
20-
let result = values.reduce((accumulator, current) => {
21-
return Number(current) + Number(accumulator);
22-
}, 0);
23-
return result;
24-
},
25-
};
26-
279
/**
2810
* Base64 encodes a string.
2911
*/
30-
customCommands.base64enc = {
12+
builtInCommands.base64enc = {
3113
about: "base64enc [string]<br>&nbsp;&nbsp;Base64 encode a string.",
32-
exe: (args) => {
33-
if (args.length == 1) {
14+
exe: function (args) {
15+
if(args.length == 1){
3416
return "No string specified.";
3517
}
3618
args.shift();
@@ -41,10 +23,10 @@ customCommands.base64enc = {
4123
/**
4224
* Base64 decodes a string.
4325
*/
44-
customCommands.base64dec = {
26+
builtInCommands.base64dec = {
4527
about: "base64dec [string]<br>&nbsp;&nbsp;Base64 decode a string.",
46-
exe: (args) => {
47-
if (args.length == 1) {
28+
exe: function (args) {
29+
if(args.length == 1){
4830
return "No string specified.";
4931
}
5032
args.shift();
@@ -56,9 +38,9 @@ customCommands.base64dec = {
5638
* Print a simple message.
5739
**/
5840
customCommands.cow = {
59-
about: "cow<br>&nbsp;&nbsp;What does a cow say?", // Help text for this command.
60-
exe: () => { // Executed for this command.
61-
return "Moooooo!";
41+
about: "cow<br>&nbsp;&nbsp;What does a cow say?", // Help text for this command.
42+
exe: function() { // Executed for this command.
43+
return "Moooooo!";
6244
}
6345
};
6446

@@ -67,7 +49,7 @@ customCommands.cow = {
6749
**/
6850
customCommands.hello = {
6951
about: "hello [name ...]<br>&nbsp;&nbsp;Greet the user with a message.",
70-
exe: (args) => { // Executed for this command. args[0] contains the command name.
52+
exe: function (args) { // Executed for this command. args[0] contains the command name.
7153
if (args.length < 2) {
7254
return "Hello. Why don't you tell me your name?";
7355
}
@@ -83,9 +65,12 @@ customCommands.hello = {
8365
* Print a simple message.
8466
**/
8567
customCommands.secret = {
86-
about: "secret<br>&nbsp;&nbsp;A command that is not listed in the help.", // Help text for this command.
68+
about: "secret<br>&nbsp;&nbsp;A command that is not listed in the help.", // Help text for this command.
8769
hidden: true, // Whether to hide this command from the help list.
88-
exe: () => { // Executed for this command.
89-
return "The password is: goldfish";
70+
exe: function() { // Executed for this command.
71+
return "The password is: goldfish";
9072
}
9173
};
74+
75+
// Use the commands in this file, to extend the built-in commands:
76+
var commands = extendObject(builtInCommands, customCommands);

‎js/filesystem.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
var originalFilesystem="<d name='/' path='/'>\
2+
<c>\
3+
<d name='docs' path='/docs/'>\
4+
<c>\
5+
<d name='private' path='/docs/private/'>\
6+
<c>\
7+
<f name='secret.txt' path='/docs/private/'>\
8+
<contents>PxNmGkl6M+jDP4AYAKZET18SEnWD5qw5LIP9174lONWslF144K9VHFIk1JA=</contents>\
9+
</f>\
10+
</c>\
11+
</d>\
12+
<f name='shoplist.txt' path='/docs/'>\
13+
<contents>-Apples\n-Bananas\n-Cookies</contents>\
14+
</f>\
15+
<f name='ok.txt' path='/docs/'>\
16+
<contents>I am ok.</contents>\
17+
</f>\
18+
<f name='moretodo.txt' path='/docs/'>\
19+
<contents>A, B, C.</contents>\
20+
</f>\
21+
</c>\
22+
</d>\
23+
<d name='more' path='/more/'>\
24+
<c>\
25+
<f name='moretodo.txt' path='/more/'>\
26+
<contents>Don't forget this other stuff.</contents>\
27+
</f>\
28+
</c>\
29+
</d>\
30+
<d name='stuff' path='/stuff/'>\
31+
<c>\
32+
</c>\
33+
</d>\
34+
<f name='cool.txt' path='/'>\
35+
<contents>There is a hidden command in this terminal called 'secret'.</contents>\
36+
</f>\
37+
</c>\
38+
</d>";
39+
/*
40+
originalFilesystem = {
41+
"/" : {
42+
type: "d",
43+
name: "/",
44+
path: "/",
45+
children: {
46+
"animals" : {
47+
type: "d",
48+
name: "animals",
49+
path: "/animals",
50+
children: {
51+
"images" : {
52+
type: "d",
53+
name: "images",
54+
path: "/animals/cat",
55+
children: {
56+
"cat.txt" : {
57+
type: "f",
58+
name: "cat.txt",
59+
path: "/animals/cat/cat.txt",
60+
content: "Meow this is a cat."
61+
},
62+
"cat2.txt" : {
63+
type: "f",
64+
name: "cat2.txt",
65+
path: "/animals/cat/cat2.txt",
66+
content: "Meow this is ANOTHER a cat."
67+
}
68+
}
69+
}
70+
}
71+
},
72+
"hello.txt" : {
73+
type: "f",
74+
name: "hello.txt",
75+
path: "/hello.txt",
76+
content: "Hi there."
77+
}
78+
}
79+
}
80+
};
81+
*/

‎src/main/boot.js ‎js/src/boot.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import { version } from './version';
2-
3-
/**
4-
* The bootloader message that will appear line by line on terminal boot.
5-
* This is the 'long' format.
6-
* To skip this, set useBootLoader to false in the on-page configuration.
7-
* In HTML format.
8-
*/
9-
export const bootMessageLines = [
1+
var bootMessageLines = [
102
"System loading...<br>",
113
(new Date()).toString()+"<br>",
124
"&nbsp;_______&nbsp;&nbsp;&nbsp;______&nbsp;<br>|__&nbsp;&nbsp;&nbsp;__|&nbsp;|&nbsp;&nbsp;____|<br>&nbsp;&nbsp;&nbsp;|&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;|__&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;|&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;__|&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;|&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;|_|&nbsp;&nbsp;&nbsp;&nbsp;|_|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>",

‎src/main/components/crypto.js ‎js/src/crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
2929
* www.movable-type.co.uk/scripts/xtea.pdf - Tea extensions (1997)
3030
* www.movable-type.co.uk/scripts/xxtea.pdf - Correction to xtea (1998)
3131
*/
32-
export var Tea =
32+
var Tea =
3333
/*#__PURE__*/
3434
function () {
3535
function Tea() {

‎js/src/system.js

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
var builtInCommands = {};
2+
3+
builtInCommands.cat = {
4+
about: "cat [file]<br>&nbsp;&nbsp;Display the contents of the specified file.",
5+
exe: function (args) {
6+
if(args.length != 2){
7+
return "No such file.";
8+
}
9+
var result = term.catFile(args[1]);
10+
if(result === false){
11+
return "No such file, or argument is a directory.";
12+
}
13+
result = (result + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '<br>' + '$2');
14+
return result;
15+
}
16+
}
17+
18+
/**
19+
* Change into a directory.
20+
**/
21+
builtInCommands.cd = {
22+
about: "cd [path]<br>&nbsp;&nbsp;Change directory to the specified path.",
23+
exe: function (args) {
24+
if(args.length != 2){
25+
return "";
26+
}
27+
var result = term.changeDirectory(args[1]);
28+
if(!result){
29+
return "No such directory.";
30+
}
31+
return "";
32+
}
33+
}
34+
35+
/**
36+
* Clears the terminal using a special flag on the resetPrompt function.
37+
**/
38+
builtInCommands.clear = {
39+
about: "clear<br>&nbsp;&nbsp;Clear the terminal window.",
40+
exe: function () {
41+
return ""; // Functionality is handled internally by watching for this specific command name when resetting the prompt.
42+
}
43+
};
44+
45+
/**
46+
* Echos text to the terminal
47+
**/
48+
builtInCommands.echo = {
49+
about: "echo [string]<br>&nbsp;&nbsp;Display a line of text.",
50+
exe: function(args) {
51+
var result = args.slice();
52+
result.shift();
53+
return result.join(" ");
54+
}
55+
};
56+
57+
/**
58+
* Encryption commands which use a password a string.
59+
**/
60+
builtInCommands.encrypt = {
61+
about: "encrypt [message] [password]<br>&nbsp;&nbsp;Encrypt a provided message using the password.",
62+
exe: function(args) {
63+
if(args.length != 3){
64+
return "encrypt: Invalid number of arguments.";
65+
}
66+
var result = Tea.encrypt(args[1], args[2]);
67+
return result;
68+
}
69+
};
70+
builtInCommands.decrypt = {
71+
about: "decrypt [encoded] [password]<br>&nbsp;&nbsp;Decrypt a provided message using the password.",
72+
exe: function(args) {
73+
if(args.length != 3){
74+
return "decrypt: Invalid number of arguments.";
75+
}
76+
var result = Tea.decrypt(args[1], args[2]);
77+
return result;
78+
}
79+
};
80+
81+
82+
/**
83+
* Lists all available commands or the help for a given command.
84+
**/
85+
builtInCommands.help = {
86+
about: "help [command]<br>&nbsp;&nbsp;Show a list of available commands, or help for a specific command.",
87+
exe: function (args) {
88+
var output = "";
89+
if (args.length == 2 && args[1] && args[1].toLowerCase() in commands) {
90+
output += "<strong>" + args[1].toLowerCase() + "</strong>: " + commands[args[1].toLowerCase()].about + "";
91+
} else {
92+
output += "TERMFAKE bash, version " + version + "-release (x86_64-pc-linux-gnu)<br>These shell commands are defined internally. Type 'help' to see this list.<br>Type 'help name' to find out more about the function 'name'.<br><br>";
93+
output += "";
94+
95+
Object.keys(commands).sort().forEach(function (cName) {
96+
if( !commands[cName].hidden ){
97+
output += "<strong>" + cName + "</strong>&nbsp; ";
98+
}
99+
});
100+
}
101+
output += "<br><br>";
102+
return output;
103+
}
104+
};
105+
106+
/**
107+
* Lists the recent builtInCommands.
108+
**/
109+
builtInCommands.history = {
110+
about: "history [-c]<br>&nbsp;&nbsp;Display the list of recent commands.<br>&nbsp;&nbsp;-c clear the history list.",
111+
exe: function (args) {
112+
if (args.length == 2 && args[1] == "-c") {
113+
localStorage.setItem("history", []);
114+
term.history = [];
115+
116+
}
117+
var history = term.history;
118+
var output = "";
119+
120+
history.forEach(function (element, index) {
121+
output += index + "&nbsp;&nbsp;" + element + "<br>";
122+
});
123+
return output;
124+
}
125+
};
126+
127+
/**
128+
* Lists the files and directories in the current path.
129+
**/
130+
builtInCommands.ls = {
131+
about: "ls [-l]<br>&nbsp;&nbsp;List directory contents.<br>&nbsp;&nbsp;-l list contents vertically.",
132+
exe: function (args) {
133+
var listing = "";
134+
var children = Array.prototype.slice.call(term.filesystemPointer.querySelector('c').children);
135+
children.forEach(function(element, index){
136+
listing += "<span class='filesystem-"+element.nodeName+"'>"+element.getAttribute('name')+"</span>";
137+
if( args[1] && args[1] == "-l"){
138+
listing += "<br>";
139+
}else{
140+
listing += "&nbsp;&nbsp;";
141+
}
142+
});
143+
144+
return listing;
145+
}
146+
}
147+
148+
/**
149+
* Print the name of the current/working directory.
150+
*/
151+
builtInCommands.pwd = {
152+
about: "pwd<br>&nbsp;&nbsp;Print the name of the current working directory.",
153+
exe: function () {
154+
return term.path
155+
}
156+
}
157+
158+
/**
159+
* Reset the local storage data for this app.
160+
**/
161+
builtInCommands.reboot = {
162+
about: "reboot<br>&nbsp;&nbsp;Reboot the terminal and reset saved environment.",
163+
exe: function () {
164+
localStorage.removeItem("filesystem");
165+
localStorage.removeItem("history");
166+
term.initSession();
167+
term.bootTerminalStart(document.getElementById("terminal"));
168+
return "";
169+
}
170+
};
171+
172+
/**
173+
* Delete a file with the given name.
174+
**/
175+
builtInCommands.rm = {
176+
about: "rm [name]<br>&nbsp;&nbsp;Delete the file with the specified name in the current directory.",
177+
exe: function (args) {
178+
if(args.length == 1){
179+
return "No filename specified.";
180+
}
181+
if(args.length > 2){
182+
return "Too many parameters supplied.";
183+
}
184+
var result = term.deleteFile(args[1]);
185+
if(result !== true){
186+
return result;
187+
}
188+
return "";
189+
}
190+
}
191+
192+
/**
193+
* Create an empty file with the given name.
194+
**/
195+
builtInCommands.touch = {
196+
about: "touch [name]<br>&nbsp;&nbsp;Create a file with the specified name in the current directory.",
197+
exe: function (args) {
198+
if(args.length == 1){
199+
return "No filename specified.";
200+
}
201+
if(args.length > 2){
202+
return "Too many parameters supplied.";
203+
}
204+
var result = term.makeFile(args[1]);
205+
if(result !== true){
206+
return result;
207+
}
208+
return "";
209+
}
210+
}
211+
212+
/**
213+
* Get the version, author and repo information for Terminal Faker.
214+
*/
215+
builtInCommands.version = {
216+
about: "version<br>&nbsp;&nbsp;Display the version and attribution of this terminal application.",
217+
exe: function () {
218+
return "Terminal Faker: version " + version + " (https://github.com/syntaxseed/terminalfaker) by Sherri Wheeler.";
219+
}
220+
};

‎js/src/terminal.js

+497
Large diffs are not rendered by default.

‎package-lock.json

-4,088
This file was deleted.

‎package.json

-16
This file was deleted.

‎src/index.html

-57
This file was deleted.

‎src/js/bundle.min.js

-362
This file was deleted.

‎src/main/app/Cmd.js

-324
This file was deleted.

‎src/main/app/CustomCmd_UNUSED.js

-88
This file was deleted.

‎src/main/app/Terminal.js

-377
This file was deleted.

‎src/main/components/CmdHelper.js

-66
This file was deleted.

‎src/main/components/InputHelper.js

-72
This file was deleted.

‎src/main/components/errors/CmdValidationError.js

-10
This file was deleted.

‎src/main/components/fs/FileSystem.js

-135
This file was deleted.

‎src/main/components/fs/FsDir.js

-84
This file was deleted.

‎src/main/components/fs/FsFile.js

-52
This file was deleted.

‎src/main/components/fs/FsUnit.js

-88
This file was deleted.

‎src/main/components/fs/utils.js

-47
This file was deleted.

‎src/main/components/keysMap.js

-7
This file was deleted.

‎src/main/components/path/PathHelper.js

-143
This file was deleted.

‎src/main/components/utils.js

-18
This file was deleted.

‎src/main/filesystem.js

-61
This file was deleted.

‎src/main/index.js

-24
This file was deleted.

‎src/main/version.js

-1
This file was deleted.

‎src/terminal.css ‎terminal.css

+3-16
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ the font size as it's quite small.
1212
*/
1313
#terminal {
1414
font-family: 'Courier New', monospace;
15-
width: 100%;
16-
height: 100%;
17-
padding-bottom:50px;
18-
}
19-
20-
#terminal pre{
21-
font-family: 'Courier New', monospace;
22-
margin :0;
23-
white-space: pre-wrap;
15+
width: 100%;
16+
height: 100%;
2417
}
2518

2619
/**
@@ -29,7 +22,7 @@ the font size as it's quite small.
2922
*/
3023
#terminal .input {
3124
height: 1em;
32-
min-width: 4em;
25+
min-width: 3em;
3326
outline-color: transparent;
3427
border: none;
3528
display: inline-block;
@@ -54,9 +47,3 @@ the font size as it's quite small.
5447
#terminal div{
5548
word-wrap: break-word;
5649
}
57-
58-
#terminal pre{
59-
font-family: 'Courier New', monospace;
60-
margin :0;
61-
white-space: pre-wrap;
62-
}

‎webpack.config.js

-10
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.