Skip to content

Commit 24f02d0

Browse files
authored
Adding extra info in the "help" command output (jacksonbenete#27)
1 parent 2b81906 commit 24f02d0

File tree

4 files changed

+73
-43
lines changed

4 files changed

+73
-43
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"UsernameIsEmptyError": false
4747
},
4848
"rules": {
49+
"array-element-newline": ["error", "consistent"],
4950
"complexity": 0,
5051
"id-blacklist": 0,
5152
"id-match": 0,

src/glitch-img.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function glitchImage( imgElem ) { /* eslint-disable-line no-unused-vars */
2626
imgElem.remove();
2727
const glitch = new Glitch( loadedImg, sketch );
2828
sketch.draw = () => {
29+
if ( !document.body.contains( canvas.elt ) ) {
30+
sketch.remove();
31+
return;
32+
}
2933
sketch.clear();
3034
sketch.background( 0 ); // fill canvas in black
3135
glitch.show();

src/kernel.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,13 @@ system = {
280280
const commands = Object.keys( system ).filter( ( cmd ) => cmd !== "dumpdb" );
281281
Array.prototype.push.apply( commands, Object.keys( programs ).filter( ( pName ) => !programs[ pName ].secretCommand ) );
282282
commands.sort();
283-
resolve( [ "You can read the help of a specific command by entering as follows: 'help commandName'", "List of useful commands:", `<div class="ls-files">${ commands.join( "<br>" ) }</div>` ] );
283+
resolve( [
284+
"You can read the help of a specific command by entering as follows: 'help commandName'",
285+
"List of useful commands:",
286+
`<div class="ls-files">${ commands.join( "<br>" ) }</div>`,
287+
"You can navigate in the commands usage history using the UP & DOWN arrow keys.",
288+
"The TAB key will provide command auto-completion."
289+
] );
284290
} else if ( args[ 0 ] === "clear" ) {
285291
resolve( [ "Usage:", "> clear", "The clear command will completely wipeout the entire screen, but it will not affect the history." ] );
286292
} else if ( args[ 0 ] === "date" ) {
@@ -296,11 +302,23 @@ system = {
296302
} else if ( args[ 0 ] === "mail" ) {
297303
resolve( [ "Usage:", "> mail", "If you're logged in you can list your mail messages if any." ] );
298304
} else if ( args[ 0 ] === "ping" ) {
299-
resolve( [ "Usage:", "> ping address", "The ping command will try to reach a valid address.", "If the ping doesn't return a valid response, the address may be incorrect, may not exist or can't be reached locally." ] );
305+
resolve( [
306+
"Usage:",
307+
"> ping address",
308+
"The ping command will try to reach a valid address.",
309+
"If the ping doesn't return a valid response, the address may be incorrect, may not exist or can't be reached locally."
310+
] );
300311
} else if ( args[ 0 ] === "read" ) {
301312
resolve( [ "Usage:", "> read x", "If you're logged in you can read your mail messages if any." ] );
302313
} else if ( args[ 0 ] === "telnet" ) {
303-
resolve( [ "Usage:", "> telnet address", "> telnet address@password", "You can connect to a valid address to access a specific server if the server is at internet.", "Intranet servers can only be accessed locally.", "You may need a password if it isn't a public server." ] );
314+
resolve( [
315+
"Usage:",
316+
"> telnet address",
317+
"> telnet address@password",
318+
"You can connect to a valid address to access a specific server if the server is at internet.",
319+
"Intranet servers can only be accessed locally.",
320+
"You may need a password if it isn't a public server."
321+
] );
304322
} else if ( args[ 0 ] === "whoami" ) {
305323
resolve( [ "Usage:", "> whoami", "Display the server you are currently connected to, and the login you are registered with." ] );
306324
} else if ( args[ 0 ] in softwareInfo ) {
@@ -526,7 +544,7 @@ function allowedSoftwares() {
526544
for ( const app in softwareInfo ) {
527545
const program = softwareInfo[ app ];
528546
if (
529-
( !program.location || program.location.includes( serverDatabase.serverAddress ) || program.location.includes( "all" ) ) &&
547+
( !program.location || program.location.includes( serverDatabase.serverAddress ) ) &&
530548
( !program.protection || program.protection.includes( userDatabase.userId ) )
531549
) {
532550
softwares[ app ] = program;

src/particle-img.js

+46-39
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,57 @@ const DETAIL = 1;
1212
*/
1313
function particleImage( imgElem ) { /* eslint-disable-line no-unused-vars */
1414
const particulesCount = imgElem.dataset.particules ? Number( imgElem.dataset.particules ) : 5000;
15-
imgElem.addEventListener( "load", () => {
16-
const canvas = document.createElement( "canvas" );
17-
imgElem.parentNode.appendChild( canvas );
18-
const ctx = canvas.getContext( "2d" );
19-
canvas.width = imgElem.width;
20-
canvas.height = imgElem.height;
15+
return new Promise( ( resolve ) => {
16+
imgElem.addEventListener( "load", () => {
17+
const canvas = document.createElement( "canvas" );
18+
imgElem.parentNode.appendChild( canvas );
19+
const ctx = canvas.getContext( "2d" );
20+
canvas.width = imgElem.width;
21+
canvas.height = imgElem.height;
2122

22-
ctx.drawImage( imgElem, 0, 0, canvas.width, canvas.height );
23-
imgElem.remove();
24-
const pixels = ctx.getImageData( 0, 0, canvas.width, canvas.height );
25-
ctx.clearRect( 0, 0, canvas.width, canvas.height );
23+
ctx.drawImage( imgElem, 0, 0, canvas.width, canvas.height );
24+
imgElem.remove();
25+
const pixels = ctx.getImageData( 0, 0, canvas.width, canvas.height );
26+
ctx.clearRect( 0, 0, canvas.width, canvas.height );
2627

27-
const grid = [];
28-
for ( let y = 0; y < canvas.height; y += DETAIL ) {
29-
const row = [];
30-
for ( let x = 0; x < canvas.width; x += DETAIL ) {
31-
const red = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 ) ];
32-
const green = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 + 1 ) ];
33-
const blue = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 + 2 ) ];
34-
const color = `rgb(${ red },${ green },${ blue })`;
35-
const brightness = calculateBrightness( red, green, blue ) / 100;
36-
const cell = [ color, brightness ];
37-
row.push( cell );
28+
const grid = [];
29+
for ( let y = 0; y < canvas.height; y += DETAIL ) {
30+
const row = [];
31+
for ( let x = 0; x < canvas.width; x += DETAIL ) {
32+
const red = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 ) ];
33+
const green = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 + 1 ) ];
34+
const blue = pixels.data[ ( y * 4 * pixels.width ) + ( x * 4 + 2 ) ];
35+
const color = `rgb(${ red },${ green },${ blue })`;
36+
const brightness = calculateBrightness( red, green, blue ) / 100;
37+
const cell = [ color, brightness ];
38+
row.push( cell );
39+
}
40+
grid.push( row );
41+
}
42+
const particlesArray = [];
43+
for ( let i = 0; i < particulesCount; i++ ) {
44+
particlesArray.push( new Particle( canvas.width, canvas.height ) );
3845
}
39-
grid.push( row );
40-
}
41-
const particlesArray = [];
42-
for ( let i = 0; i < particulesCount; i++ ) {
43-
particlesArray.push( new Particle( canvas.width, canvas.height ) );
44-
}
4546

46-
function animate() {
47-
ctx.globalAlpha = 0.05;
48-
ctx.fillStyle = "rgb(0, 0, 0)";
49-
ctx.fillRect( 0, 0, canvas.width, canvas.height );
50-
ctx.globalAlpha = 0.2;
51-
for ( let i = 0; i < particlesArray.length; i++ ) {
52-
particlesArray[ i ].update( grid );
53-
ctx.globalAlpha = particlesArray[ i ].speed * 0.3;
54-
particlesArray[ i ].draw( grid, ctx );
47+
function animate() {
48+
if ( !document.body.contains( canvas ) ) {
49+
return;
50+
}
51+
ctx.globalAlpha = 0.05;
52+
ctx.fillStyle = "rgb(0, 0, 0)";
53+
ctx.fillRect( 0, 0, canvas.width, canvas.height );
54+
ctx.globalAlpha = 0.2;
55+
for ( let i = 0; i < particlesArray.length; i++ ) {
56+
particlesArray[ i ].update( grid );
57+
ctx.globalAlpha = particlesArray[ i ].speed * 0.3;
58+
particlesArray[ i ].draw( grid, ctx );
59+
}
60+
requestAnimationFrame( animate );
5561
}
56-
requestAnimationFrame( animate );
57-
}
58-
animate();
62+
animate();
63+
64+
resolve( canvas );
65+
} );
5966
} );
6067
}
6168

0 commit comments

Comments
 (0)