Improvements around

This commit is contained in:
BlackLight 2010-12-24 19:09:37 +01:00
parent d3435870cd
commit 5e1a804f44
4 changed files with 215 additions and 42 deletions

3
README
View file

@ -75,3 +75,6 @@ look at the file `blash.js' for a brief description of the fields of this object
or to the sample commands in `commands/' directory for seeing how to access or to the sample commands in `commands/' directory for seeing how to access
them. them.
After creating your JSON file with the new command, don't forget to add the name
of the command to the array `commands' in blash.json so that the CMS sees it.

View file

@ -137,6 +137,7 @@ function blash ()
{ {
this.cmdOut.innerHTML = this.json.shellName + ": command not found: " + cmd + '<br/>'; this.cmdOut.innerHTML = this.json.shellName + ": command not found: " + cmd + '<br/>';
} }
}
var value = this.prompt.value; var value = this.prompt.value;
var out = this.cmdOut.innerHTML; var out = this.cmdOut.innerHTML;
@ -147,7 +148,7 @@ function blash ()
this.window.removeChild ( this.prompt ); this.window.removeChild ( this.prompt );
this.window.removeChild ( this.cmdOut ); this.window.removeChild ( this.cmdOut );
if ( this.__first_cmd ) if ( this.__first_cmd && this.prompt.value.length > 0 )
{ {
this.window.innerHTML += value + '<br/>' + out + text; this.window.innerHTML += value + '<br/>' + out + text;
this.__first_cmd = false; this.__first_cmd = false;
@ -180,7 +181,6 @@ function blash ()
this.window.appendChild ( this.prompt ); this.window.appendChild ( this.prompt );
this.window.appendChild ( this.cmdOut ); this.window.appendChild ( this.cmdOut );
this.prompt.focus(); this.prompt.focus();
}
} else if ( key == 38 || key == 40 ) { } else if ( key == 38 || key == 40 ) {
if ( key == 38 ) if ( key == 38 )
{ {
@ -242,7 +242,66 @@ function blash ()
for ( var i in dirs ) for ( var i in dirs )
{ {
this.cmdOut.innerHTML += "<br/>\n" + dirs[i].name; if ( i > 0 )
{
this.cmdOut.innerHTML += "<br/>\n";
}
this.cmdOut.innerHTML += dirs[i].name;
}
if ( dirs.length > 1 )
{
// Get the longest sequence in common
var sequences = new Array();
var min_len = 0;
for ( var i in dirs )
{
for ( var j in dirs )
{
if ( i != j )
{
if ( dirs[i].name.length != dirs[j].name.length )
{
min_len = ( dirs[i].name.length < dirs[j].name.length ) ? dirs[i].name.length : dirs[j].name.length;
} else {
min_len = dirs[i].name.length;
}
var k = 0;
for ( k = min_len-1; k >= 0; k-- )
{
if ( dirs[i].name.charAt ( k ) != dirs[j].name.charAt ( k ))
{
break;
}
}
var seq = '';
for ( var l=0; l < k; l++ )
{
seq += dirs[i].name.charAt ( l );
}
sequences.push ( seq );
}
}
}
var seq = sequences[0];
for ( var i in sequences )
{
if ( sequences[i].length < seq )
{
seq = sequences[i];
}
}
this.prompt.value = this.prompt.value.replace ( arg, seq + (( dirs[0].type == 'directory' ) ? '/' : '' ));
} }
} }
} else { } else {

View file

@ -51,27 +51,138 @@
"type" : "directory", "type" : "directory",
}, },
{ {
"path" : "/home", "path" : "/blog",
"type" : "directory", "type" : "directory",
}, },
{ {
"path" : "/home/blacklight", "path" : "/news",
"type" : "directory", "type" : "directory",
}, },
{ {
"path" : "/home/blacklight/mbox", "path" : "/forum",
"type" : "file", "type" : "directory",
"content" : "No new mail", },
{
"path" : "/tutorials",
"type" : "directory",
},
{
"path" : "/software",
"type" : "directory",
}, },
{ {
"path" : "/etc", "path" : "/etc",
"type" : "directory", "type" : "directory",
}, },
{ {
"path" : "/initrd", "path" : "/home",
"type" : "directory",
},
{
"path" : "/home/guest",
"type" : "directory",
},
{
"path" : "/home/guest/mbox",
"type" : "file",
"content" : "No new mail",
},
{
"path" : "/google",
"type" : "file", "type" : "file",
"href" : "http://www.google.com", "href" : "http://www.google.com",
}, },
{
"path" : "/blog/post1",
"type" : "file",
"content" : "This is my first post",
},
{
"path" : "/blog/post2",
"type" : "file",
"content" : "This is my second post",
},
{
"path" : "/blog/post3",
"type" : "file",
"content" : "This is my third post",
},
{
"path" : "/etc/blashrc",
"type" : "file",
"content" : "This is the default blash configuration file",
},
{
"path" : "/forum/post1",
"type" : "file",
"content" : "<b>Sent by <i>admin</i> at <i>00:00:01</i></b><br/>Welcome to the forum<br/><br/>\n" +
"<b>Sent by <i>troll</i> at <i>00:00:02</i></b><br/>lulz<br/>\n",
},
{
"path" : "/forum/post2",
"type" : "file",
"content" : "<b>Sent by <i>lolcat</i> at <i>00:00:03</i></b><br/>Can I haz cheezburger?<br/>\n",
},
{
"path" : "/home/guest/.blashrc",
"type" : "file",
"content" : "Custom blash configuration file",
},
{
"path" : "/home/guest/mbox",
"type" : "file",
"content" : "No new mail",
},
{
"path" : "/news/news1",
"type" : "file",
"content" : "Nothing new under the sun",
},
{
"path" : "/software/soft1",
"type" : "file",
"href" : "/software/soft1.tar.gz",
},
{
"path" : "/software/soft2",
"type" : "file",
"href" : "/software/soft2.tar.gz",
},
{
"path" : "/software/soft3",
"type" : "file",
"href" : "/software/soft3.tar.gz",
},
{
"path" : "/tutorials/tut1",
"type" : "file",
"href" : "/software/tut1.pdf",
},
{
"path" : "/tutorials/tut2",
"type" : "file",
"href" : "/software/tut2.pdf",
},
{
"path" : "/github",
"type" : "file",
"href" : "https://github.com/BlackLight/blash",
},
{
"path" : "/aboutme",
"type" : "file",
"content" : "Luke, I am your father",
},
{
"path" : "/contacts",
"type" : "file",
"content" : "Contact me at spam@montypython.com",
},
{
"path" : "/irc",
"type" : "file",
"content" : "IRC channel at #thegame@irc.randomstuff.com",
},
], ],
"commands" : [ "commands" : [

View file

@ -20,7 +20,7 @@
arg = RegExp.$1; arg = RegExp.$1;
} }
var re = new RegExp ( arg ); var re = new RegExp ( arg, "i" );
for ( var i in shell.json.directories ) for ( var i in shell.json.directories )
{ {