Skip to content

Commit 4d3ff9e

Browse files
committed
Rewrite as flexible object
- Proper API - Basic readable docs - Fixed history not counting args - Improved things - More generic demo page
1 parent 815d08a commit 4d3ff9e

File tree

4 files changed

+187
-158
lines changed

4 files changed

+187
-158
lines changed

README.md

+11-17
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,36 @@ var settings = {
2323
name: "echo", //Command name
2424
description: "a test command with one echo arg", //Help text to be displayed when `help` command is called
2525
parameters: ["a string to be echoed in console"], //An optional array of successive parameter descriptions, used when the command that needs args is being called without any args
26-
func: function(params){println(params[0])} //Function to be called when the command is executed. Accepts an array of parameters, ordered in the same way as in the previous property
26+
func: function(params){plainterm.print(params[0])} //Function to be called when the command is executed. Accepts an array of parameters, ordered in the same way as in the previous property
2727
},
2828
test: {
2929
name: "test",
3030
description: "a test command with no args",
31-
func: function(){println("testing things")}
31+
func: function(){plainterm.print("testing things")}
3232
},
3333
multiply: {
3434
name: "multiply",
3535
description: "Multiply two numbers",
3636
parameters: ["number one", "number two"],
37-
func: function(params){println(params[0]*params[1])}
37+
func: function(params){plainterm.print(params[0]*params[1])}
3838
}
3939
}
4040
};
4141

42-
term_init(settings);
42+
plainterm.init(settings);
4343
```
4444

4545
## Working with the terminal:
4646

4747
`help` - Display a list of all commands with descriptions
48+
4849
`command` - Execute a command. Will display "Usage: command [parameter 1 description] [parameter 2 description], etc.", when needs args but called without them.
4950

5051
## API:
5152

52-
`println(text, command)` - Print a text in terminal starting from a new line. Command - optional, count given string as a command (prepend prompt, syntax highlight).
53-
54-
`bash.version` - plainterm.js version
55-
`bash.commands` - an object containing all available commands available
56-
57-
58-
`bash.commands.[command].name` - command name
59-
60-
`bash.commands.[command].description` - command description
61-
62-
`bash.commands.[command].parameters` - command parameters
63-
64-
`bash.commands.[command].func` - retrieve a function. call with `bash.commands.[command].func()`
53+
| Method | Description | Parameters |
54+
| ------------- | ------------- | ------------- |
55+
| `init(settings)` | Initialize a terminal in a DOM with given ID | Object. See the example above |
56+
| `print(text, c)` | Prints a given text in the terminal | `text` - String, `c` - Boolean, optional, defaults to false. Count given string as a command (displays prompt, syntax highlight and appears in history) |
57+
| `run(text)` | Emulates a command execution in a terminal (acts the same way as a use would have typed and pressed Enter) | `text` - String |
58+
| `hist(up)` | Search in command history. Returns string. | `up` - Boolean, optional. Defaults to true. Upward/downward search. |

index.html

+22-14
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,55 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>mkrl.xyz</title>
6-
<meta name="description" content="A personal website of mine. Why are you here?">
7-
<meta name="author" content="mkrl">
8-
<link rel="stylesheet" href="s.css">
5+
<title>plainterm.js</title>
6+
<link rel="stylesheet" href="style.css">
7+
<style>
8+
.container > div {
9+
margin: 0 auto;
10+
}
11+
</style>
912
</head>
1013
<body>
1114

12-
<center><h3>Hello</h3></center>
15+
<center><h3>Terminal</h3></center>
1316

17+
<div class="container">
1418
<div id="terminal">
1519
</div>
20+
</div>
1621

1722
<script src="./plainterm.js"></script>
1823
<script>
1924
var settings = {
2025
id: "terminal",
21-
welcome: "Welcome to plainterm.js terminal emulator",
2226
prompt: "[email protected]:~$ ",
2327
commands: {
24-
test: {
25-
name: "test",
26-
description: "a test command with no args",
27-
func: function(){println("testing things")}
28+
about: {
29+
name: "about",
30+
description: "about the module",
31+
func: function(){plainterm.print('A dead simple lightweight pure Javascript terminal "emulator" that is intended to be used for entertainment purposes. Written in one night.')}
32+
},
33+
repo: {
34+
name: "repo",
35+
description: "GitHub repository",
36+
func: function(){plainterm.print('<a href="https://github.com/mkrl/plainterm.js" target="blank">Click</a>')}
2837
},
2938
echo: {
3039
name: "echo",
3140
description: "a test command with one echo arg",
3241
parameters: ["a string to be echoed in console"],
33-
func: function(params){println(params[0])}
42+
func: function(params){plainterm.print(params[0])}
3443
},
3544
multiply: {
3645
name: "multiply",
3746
description: "multiply two numbers",
3847
parameters: ["number one", "number two"],
39-
func: function(params){println(params[0]*params[1])}
48+
func: function(params){plainterm.print(params[0]*params[1])}
4049
}
4150
}
4251
};
4352

44-
term_init(settings);
45-
println(settings.welcome);
53+
plainterm.init(settings);
4654
</script>
4755
</body>
4856
</html>

0 commit comments

Comments
 (0)