diff options
Diffstat (limited to 'kjsembed/stdlib/cmdline.js')
-rwxr-xr-x | kjsembed/stdlib/cmdline.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/kjsembed/stdlib/cmdline.js b/kjsembed/stdlib/cmdline.js new file mode 100755 index 00000000..9c96c6cb --- /dev/null +++ b/kjsembed/stdlib/cmdline.js @@ -0,0 +1,78 @@ +#!/usr/bin/env kjscmd + +function list(obj) +{ + println( obj ); + + for ( var i in obj ) { + try { + tp = typeof obj[i]; + + count = 20 - i.length; + spc = ''; + for ( var s=0; s < count; s++ ) + spc = spc + ' '; + + println( ' ' + i + spc + tp ); + } + catch(err) { + println( ' ' + i + spc + 'Error, ' + err ); + } + } +} + +function help() +{ + println(); + println( 'KJSCmd ' + part.versionString + ' Prompt' ); + println( '=======' + '===' + '=======' ); + println(); + println( "Type 'quit' to exit, and 'help' for this text. Anything else" ); + println( 'is evaluated by the KJSCmd engine and the result displayed.' ); + println(); +} + +function cmd_prompt() +{ + System.stdout.print( 'kjscmd> ' ); + return System.stdin.readLine(); +} + +// +// Main +// + +println( "KJSCmd " + part.versionString + " (type 'help' for more information)" ); +done = false; + +do { + + line = cmd_prompt(); + + if ( line == 'quit' ) { + done = true; + } + else if ( line == 'help' ) { + help(); + } + else if ( line == '' ) { + // DO NOTHING + } + else if ( line == null ) { + done = true; + } + else { + try { + output = eval( line ); + + if ( typeof(output) != 'undefined' ) + println( output ); + } + catch(err) { + println( 'Error: ' + err ); + } + } + +} while ( !done ); + +System.exit(0); |