Skip to content

Commit 5c25ae6

Browse files
committed
Added clear command and api
1 parent 3672eda commit 5c25ae6

File tree

7 files changed

+46
-2
lines changed

7 files changed

+46
-2
lines changed

js/core/stdio/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ let bgcolor = tty.color.BLACK;
2323

2424
defaultStdio.onwrite = text => tty.print(text, 1, fgcolor, bgcolor);
2525

26+
defaultStdio.onclear = tty.clear;
27+
2628
defaultStdio.onsetcolor = (fg) => {
2729
if (!fg) {
2830
fgcolor = tty.color.WHITE;

js/core/stdio/interface.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class StdioInterface {
4141
this.onsetbackgroundcolor(bg);
4242
}
4343

44+
clear() {
45+
this.onclear();
46+
}
47+
4448
// stdin
4549
read(cb) {
4650
this.onread(cb);

js/core/tty/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable quotes */
1817
const terminal = require('./terminal');
1918
const { DARKGRAY, BLACK, YELLOW, GREEN, LIGHTGRAY } = terminal.color;
2019

@@ -33,6 +32,6 @@ terminal.print('\n Welcome to ', 1, DARKGRAY, BLACK);
3332
terminal.print('JsOS\n', 1, GREEN, BLACK);
3433
terminal.print('Type', 1, LIGHTGRAY, BLACK);
3534
terminal.print(' help ', 1, YELLOW, BLACK);
36-
terminal.print('to get commands\n\n', 1, LIGHTGRAY, BLACK);
35+
terminal.print('to get list of commands\n\n', 1, LIGHTGRAY, BLACK);
3736

3837
module.exports = terminal;

js/core/tty/printer.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ function scrollUp() {
3030
posCurrent -= w;
3131
}
3232

33+
function scrollDown() {
34+
buffer.scrollDown(vga.color.BLACK);
35+
posCurrent -= w;
36+
}
37+
38+
function clear() {
39+
buffer.clear(vga.color.BLACK);
40+
posCurrent = 0;
41+
refresh();
42+
}
43+
3344
refresh();
3445

3546
exports.color = vga.color;
@@ -88,3 +99,7 @@ exports.moveTo = (xOpt, yOpt) => {
8899
}
89100
posCurrent = (y * w) + x;
90101
};
102+
103+
exports.scrollUp = scrollUp;
104+
exports.scrollDown = scrollDown;
105+
exports.clear = clear;

js/core/tty/terminal.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports.color = printer.color;
2121
exports.print = printer.print;
2222
exports.moveOffset = printer.moveOffset;
2323
exports.moveTo = printer.moveTo;
24+
exports.clear = printer.clear;
2425

2526
let isReading = false;
2627

@@ -84,6 +85,12 @@ exports.readLine = (cb) => {
8485
case 'kpend':
8586
editor.moveCursorEnd();
8687
break;
88+
case 'kppageup':
89+
printer.scrollUp(0);
90+
break;
91+
case 'kppagedown':
92+
printer.scrollDown(0);
93+
break;
8794
case 'character':
8895
editor.putChar(keyinfo.character);
8996
break;

js/core/tty/vga.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ class VGABuffer {
113113
setCharXY(this.b, t, h - 1, ' ', bg, bg);
114114
}
115115
}
116+
scrollDown(bg) {
117+
// testInstance(this);
118+
// testColor(bg);
119+
// this.b.set(this.b.subarray(w * 2, w * h * 2));
120+
// for (let t = 0; t < w; ++t) {
121+
// setCharXY(this.b, t, h + 1, ' ', bg, bg);
122+
// }
123+
return debug('Not implented!');
124+
}
116125
}
117126

118127
function testInstance(obj) {

js/service/shell/commands.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ const cmds = {
4646
return res(0);
4747
},
4848
},
49+
clear: {
50+
description: 'Clear the display',
51+
usage: 'clear',
52+
run(a, f, res) {
53+
f.stdio.clear();
54+
return res(0);
55+
},
56+
},
4957
help: {
5058
description: 'Show this message or show usage of the command =)',
5159
usage: 'help <command>',

0 commit comments

Comments
 (0)