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
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.

129
blash.js
View file

@ -137,50 +137,50 @@ function blash ()
{
this.cmdOut.innerHTML = this.json.shellName + ": command not found: " + cmd + '<br/>';
}
}
var value = this.prompt.value;
var out = this.cmdOut.innerHTML;
var value = this.prompt.value;
var out = this.cmdOut.innerHTML;
var text = ( shell.json.promptText ) ? shell.json.promptText : "[%n@%m %W] $ ";
text = shell.unescapePrompt ( text, shell.json.promptSequences );
var text = ( shell.json.promptText ) ? shell.json.promptText : "[%n@%m %W] $ ";
text = shell.unescapePrompt ( text, shell.json.promptSequences );
this.window.removeChild ( this.prompt );
this.window.removeChild ( this.cmdOut );
this.window.removeChild ( this.prompt );
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.__first_cmd = false;
} else {
if ( out )
{
this.window.innerHTML += value + '<br/>' + out + text;
this.__first_cmd = false;
} else {
if ( out )
if ( out.match ( /^\s*<br.?>\s*/ ))
{
if ( out.match ( /^\s*<br.?>\s*/ ))
{
out = '';
}
out = '';
}
this.window.innerHTML += value + '<br/>' + out + text;
}
this.prompt = document.createElement ( 'input' );
this.prompt.setAttribute ( 'name', 'blashPrompt' );
this.prompt.setAttribute ( 'type', 'text' );
this.prompt.setAttribute ( 'class', 'promptInput' );
this.prompt.setAttribute ( 'autocomplete', 'off' );
this.prompt.setAttribute ( 'onkeydown', 'shell.getKey ( event )' );
this.prompt.setAttribute ( 'onkeyup', 'this.focus()' );
this.prompt.setAttribute ( 'onblur', 'return false' );
this.cmdOut = document.createElement ( 'div' );
this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
this.cmdOut.setAttribute ( 'class', 'blashCmdOut' );
this.cmdOut.innerHTML = '<br/>';
this.window.appendChild ( this.prompt );
this.window.appendChild ( this.cmdOut );
this.prompt.focus();
this.window.innerHTML += value + '<br/>' + out + text;
}
this.prompt = document.createElement ( 'input' );
this.prompt.setAttribute ( 'name', 'blashPrompt' );
this.prompt.setAttribute ( 'type', 'text' );
this.prompt.setAttribute ( 'class', 'promptInput' );
this.prompt.setAttribute ( 'autocomplete', 'off' );
this.prompt.setAttribute ( 'onkeydown', 'shell.getKey ( event )' );
this.prompt.setAttribute ( 'onkeyup', 'this.focus()' );
this.prompt.setAttribute ( 'onblur', 'return false' );
this.cmdOut = document.createElement ( 'div' );
this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
this.cmdOut.setAttribute ( 'class', 'blashCmdOut' );
this.cmdOut.innerHTML = '<br/>';
this.window.appendChild ( this.prompt );
this.window.appendChild ( this.cmdOut );
this.prompt.focus();
} else if ( key == 38 || key == 40 ) {
if ( key == 38 )
{
@ -242,7 +242,66 @@ function blash ()
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 {

View file

@ -51,27 +51,138 @@
"type" : "directory",
},
{
"path" : "/home",
"path" : "/blog",
"type" : "directory",
},
{
"path" : "/home/blacklight",
"path" : "/news",
"type" : "directory",
},
{
"path" : "/home/blacklight/mbox",
"type" : "file",
"content" : "No new mail",
"path" : "/forum",
"type" : "directory",
},
{
"path" : "/tutorials",
"type" : "directory",
},
{
"path" : "/software",
"type" : "directory",
},
{
"path" : "/etc",
"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",
"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" : [

View file

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