Skip to content

Commit

Permalink
Add Line Wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
groundwater committed Nov 12, 2012
1 parent 419f9d4 commit 667cb2c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ console.log("Conncting to MySQL '%s' as '%s' with Password '%s'",
env.MYSQL_HOST,
env.MYSQL_USER,
env.MYSQL_PASS);
console.log("Well, the way they make shows is, they make one show. That show's called a pilot. Then they show that show to the people who make shows, and on the strength of that one show they decide if they're going to make more shows. Some pilots get picked and become television programs. Some don't, become nothing. She starred in one of the ones that became nothing.")

http.createServer(function(req,res){
console.log("Ping");
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ program
.option('-x, --proxy <port>','start a load balancing proxy on PORT')
.option('-f, --forward <port>','start a forward proxy')
.option('-t, --trim <N>' ,'trim logs to N characters',0)
.option('-w, --wrap' ,'wrap logs (negates trim)',false)
.description('Start the jobs in the Procfile')
.action(function(command_left,command_right){

Expand All @@ -94,8 +95,15 @@ program

var reqs = getreqs(program.args[0],proc);

cons.padding = calculatePadding(reqs);

cons.padding = calculatePadding(reqs);

if(command.wrap){
cons.wrapline = process.stdout.columns - cons.padding - 7
cons.trimline = 0
}else{
cons.trimline = command.trim || process.stdout.columns - cons.padding - 5
}

if(command.forward) startForward(command.forward,emitter);

startProxies(reqs,proc,command,emitter,program.port);
Expand Down
43 changes: 33 additions & 10 deletions lib/console.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
var util = require('util')
var cols = require('colors')

function wrap(log,length,res){
if(!res) res=[]
if(log.length <= length){
res.push(log)
return res
}else{
res.push(log.substr(0,length))
return wrap(log.substr(length),length,res)
}
}

var Console = new function(){

this.padding = 25

this.trimline = 0
this.trimline = 10
this.wrapline = 500

this.fmt = function fmt(){
return util.format.apply(null,arguments);
}

this.pad = function pad(string,n){
var l = string.length;
var d = n - l;
var o = string;
for(i=l;i<n;i++){
o += " "
}
return o + " | ";
return o
}


Expand Down Expand Up @@ -49,14 +61,25 @@ var Console = new function(){
if (line.trim().length==0) return;

var stamp = (new Date().toLocaleTimeString()) + " " + key;

if(this.trimline>0){
line = self.trim(line,command.trim);
}else if(this.trimline==0){
line = self.trim(line,process.stdout.columns - this.padding - 5);

if(self.trimline>0){
line = self.trim(line,self.trimline);
}

var delimiter = " | "

var wrapline
if(self.wrapline==0){
wrapline = line.length
}else{
wrapline = self.wrapline
}

console.log(proc.color(self.pad(stamp,this.padding)),line);

wrap(line,wrapline).forEach(function(l){
console.log(proc.color(self.pad(stamp,self.padding) + delimiter),l.trim());
delimiter = " | > "
})

});
}

Expand Down

0 comments on commit 667cb2c

Please sign in to comment.