Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofghosts committed Dec 10, 2014
1 parent 1e8d718 commit 45e60ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
18 changes: 9 additions & 9 deletions lib/match-stream.js
Expand Up @@ -6,18 +6,18 @@ var escape = require('quotemeta')
module.exports = wack

function wack(_options) {
var bad_chars = /[\x00-\x1F\x80-\x9F]+/
var badChars = /[\x00-\x1F\x80-\x9F]+/
, options = _options || {}
, current_file
, file_count
, currentFile
, fileCount
, regex
, tr

regex = new RegExp(
escape(options.pattern)
, options.ignorecase ? 'i' : ''
)

if(!options.dir) options.dir = process.cwd()

options.dir = path.normalize(options.dir)
Expand All @@ -27,23 +27,23 @@ function wack(_options) {
return tr

function write(obj) {
if(obj.filename !== current_file) {
current_file = obj.filename
file_count = 0
if(obj.filename !== currentFile) {
currentFile = obj.filename
fileCount = 0
}

var result = {}
, match

if(bad_chars.test(obj.data)) return
if(badChars.test(obj.data)) return

match = regex.exec(obj.data)

if((match && options.invertmatch) || (!match && !options.invertmatch)) {
return
}

if(options.maxcount && ++file_count > options.maxcount) return
if(options.maxcount && ++fileCount > options.maxcount) return

result.filename = obj.filename
result.line = obj.line
Expand Down
35 changes: 17 additions & 18 deletions lib/pretty-stream.js
Expand Up @@ -4,43 +4,42 @@ var color = require('bash-color')
module.exports = prettify

function prettify(options) {
return pretty_stream
return prettyStream

function pretty_stream() {
function prettyStream() {
var tr = through(pretty)
, current_file
, currentFile

return tr

function pretty(obj) {
var filename = obj.filename.slice(options.dir.length)
, line = obj.line + ':'
, file_out = filename
, fileOut = filename
, str = obj.context
, final_string
, to_output
, finalString
, toOutput

if(options.nocolor || options.invertmatch) {
to_output = ' ' + line + ' ' + str
toOutput = ' ' + line + ' ' + str
} else {
file_out = color.green(filename)
final_string = str.slice(0, obj.match.index)
final_string += color.yellow(obj.match[0], true)
final_string += str.slice(obj.match.index + obj.match[0].length)
fileOut = color.green(filename)
finalString = str.slice(0, obj.match.index)
finalString += color.yellow(obj.match[0], true)
finalString += str.slice(obj.match.index + obj.match[0].length)

to_output = ' ' +
toOutput = ' ' +
color.wrap(line, color.colors.WHITE, color.styles.bold)

to_output += final_string
toOutput += finalString
}

if(filename !== current_file) {
current_file = filename
tr.queue(file_out + '\n')
if(filename !== currentFile) {
currentFile = filename
tr.queue(fileOut + '\n')
}

tr.queue(to_output + '\n')
tr.queue(toOutput + '\n')
}
}
}

0 comments on commit 45e60ca

Please sign in to comment.