0.5.2 • Published 10 years ago

cli_debug v0.5.2

Weekly downloads
3
License
MIT
Repository
-
Last release
10 years ago

CLI_debug

CLI_debug is a Node.js package allowing you to enter and execute code interactively right from the console. It's like Node.JS's interactive mode, or a JS console in a browser.

This is really usefull for debugging, when you want to quickly execute a command to check for variables or if you want to manually run functions.

Note: this is still work-in-progress

Installation

Usage

var http = require('http');
var cli = require('cli_debug')

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

cli.debug()

Extra

CLI_debug has some extra features, just like Webkit's console for example:

  • shows the type/class of the returned value (e.g. [Number] 1337)
  • if the returned value has a custom .toString, there's an asterisk after the type/classname
> new Date
< [Date*]
Thu May 22 2014 16:21:36 GMT+0200 (Central European Summer Time)
  • to get the last returned value without using the custom .toString, use !!
> b = function(){return "[super secret]"};b.toString=b
< [Function*] [super secret]
> b
< [Function*] [super secret]
> !!
< [Function]
0: function (){
1: return "[super secret]"
2: }
  • the returned value of the last command is saved in the global variable $0
  • long output is paginated (enter q to end the pagination)
  • when Functions are returned, their code is syntax highlighted
  • multiline input works - explicitly force multiline code by ending a line with a tab character - if executing the code causes an SyntaxError: Unexpected end of input, then an implicit multiline command is assumed
  • proper error reporting

You can also change the input language to CoffeeScript or LiveScript

var cli = require('cli_debug')
var ls = require('livescript')

cli.debug()
> console.cli.toLiveScript(ls)
CLI input language set to LiveScript v1.2.0
< [undefined]  undefined
> world = "LiveScript"
< [String]  LiveScript
> console.log "hello #{world}"
hello LiveScript
< [undefined]  undefined

Still in Progress

  • proper syntax highlighting
  • better pagination
  • better handling of implicit multiline code
  • better CoffeeScript and LiveScript integration

maybe even some super fancy deep console integration, which would allow

  • autocompletion
  • syntax highlighting while typing
  • better handling of local variables