Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 0af7ab4

Browse files
committed
Merge pull request #21 from runtimejs/new-terminal
New terminal & shell
2 parents b07b51a + dc70881 commit 0af7ab4

28 files changed

+1082
-545
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 0.1.2 (2014-07-27)
2+
3+
- New terminal
4+
- Shell application
5+
- User space tools (ls, eval, cat etc)
6+
- Threading system fixes and improvements
7+
- Separate v8 isolate for every application
8+
19
### 0.1.1 (2014-06-26)
210

311
- Fix QEMU 'I/O thread has spun for 1000 iterations' warning bug

initrd/app/cat.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
18+
function error(text) {
19+
console.error('cat: ' + text);
20+
}
21+
22+
if ('string' !== typeof args.data.command) {
23+
console.error('cat: no input filenames');
24+
return;
25+
}
26+
27+
var fileNames = args.data.command.split(' ');
28+
29+
fileNames.forEach(function(filename) {
30+
args.system.fs.current({
31+
action: 'readFile',
32+
path: filename,
33+
}).then(function(fileContent) {
34+
args.env.stdout(fileContent);
35+
}, function(err) {
36+
var message = 'unknown error';
37+
switch(err.message) {
38+
case 'NOT_FOUND': message = 'file "' + filename + '" not found'; break;
39+
}
40+
41+
error(message);
42+
});
43+
});
44+
})(runtime.args());

initrd/app/clear.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
args.env.stdout('', {x: 0, y: 0, clear: true});
18+
})(runtime.args());

initrd/app/date.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
console.log(new Date().toString());
18+
})(runtime.args());

initrd/app/echo.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
if ('string' !== typeof args.data.command) {
18+
console.error('echo: no input data');
19+
return;
20+
}
21+
22+
console.log(args.data.command);
23+
})(runtime.args());

initrd/app/eval.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function exit() {
16+
runtime.exit();
17+
}
18+
19+
(function(args) {
20+
"use strict";
21+
22+
if ('string' === typeof args.data.command && '' !== args.data.command) {
23+
evalLine(args.data.command);
24+
return;
25+
}
26+
27+
args.env.stdout('JavaScript REPL (special commands: exit)\n', {fg: 'darkgray'});
28+
29+
function readLine(cb) {
30+
args.env.stdout('> ', {fg: 'lightgreen'});
31+
args.env.stdin({
32+
mode: 'line',
33+
onData: function(data) {
34+
cb(data.text);
35+
}
36+
});
37+
}
38+
39+
function evalLine(text) {
40+
text = text.trim();
41+
42+
if ('' === text) {
43+
return;
44+
}
45+
46+
try {
47+
var result = (1, eval)(text);
48+
args.env.stdout(result + '\n', {fg: 'lightgray'});
49+
} catch (err) {
50+
console.error(err.toString());
51+
}
52+
}
53+
54+
readLine(function onData(text) {
55+
if ('exit' === text.trim()) {
56+
runtime.exit();
57+
}
58+
59+
evalLine(text);
60+
readLine(onData);
61+
});
62+
63+
})(runtime.args());

initrd/app/input.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
args.env.stdout('What is your name? ');
18+
19+
function readLine(cb) {
20+
args.env.stdin({
21+
mode: 'line',
22+
onData: function(data) {
23+
cb(data.text);
24+
}
25+
});
26+
}
27+
28+
readLine(function(text) {
29+
console.log('Hello, ' + text + '!');
30+
runtime.exit();
31+
});
32+
33+
})(runtime.args());

initrd/app/ls.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2014 Runtime.JS project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(args) {
16+
"use strict";
17+
18+
args.system.fs.current({
19+
action: 'list',
20+
path: '/',
21+
}).then(function(data) {
22+
data.forEach(function(name) {
23+
console.log(name);
24+
});
25+
}, function(err) {
26+
console.error(err.message);
27+
});
28+
})(runtime.args());

0 commit comments

Comments
 (0)