Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-03-09 04:18:56 +0300
committerisaacs <i@izs.me>2011-03-22 01:55:54 +0300
commitef6f35b555b5a5da7a4a14f2798373eb8c3eea52 (patch)
tree0f69f634317d2238f8618b9f19d6244497e4ad46 /lib/search.js
parent7fa48daf31bbf96a73a886b2d844e6eb04d569da (diff)
Undent long lines
Diffstat (limited to 'lib/search.js')
-rw-r--r--lib/search.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/search.js b/lib/search.js
index 9fea92025..faa663c59 100644
--- a/lib/search.js
+++ b/lib/search.js
@@ -111,7 +111,6 @@ function filterWords (data, args, notArgs) {
var words = data.words
for (var i = 0, l = args.length; i < l; i ++) {
if (words.indexOf(args[i]) === -1) {
- //console.error("fail %j", [args[i], words])
return false
}
}
@@ -134,7 +133,7 @@ function prettify (data, args) {
// name, desc, author, keywords
var longest = []
, spaces
- , maxLen = [20, 80, 25]
+ , maxLen = [20, 60, 20]
return Object.keys(data).map(function (d) {
return data[d]
}).map(function (data) {
@@ -151,8 +150,13 @@ function prettify (data, args) {
, (data.keywords || []).join(" ")
]
l.forEach(function (s, i) {
+ var len = s.length
longest[i] = Math.min(maxLen[i] || Infinity
- ,Math.max(longest[i] || 0, s.length))
+ ,Math.max(longest[i] || 0, len))
+ if (len > longest[i]) {
+ l._undent = l._undent || []
+ l._undent[i] = len - longest[i]
+ }
l[i] = l[i].replace(/\s+/g, " ")
})
return l
@@ -161,7 +165,11 @@ function prettify (data, args) {
spaces = spaces || longest.map(function (n) {
return new Array(n + 2).join(" ")
})
- return (s + spaces[i].substr(s.length))
+ var len = s.length
+ if (line._undent && line._undent[i - 1]) {
+ len += line._undent[i - 1] - 1
+ }
+ return s + spaces[i].substr(len)
}).join(" ").substr(0, cols)
}).sort(function (a, b) {
return a === b ? 0 : a > b ? 1 : -1
@@ -174,7 +182,7 @@ function prettify (data, args) {
}).join("\n")
}
-var colors = [36, 32, 33, 31, 35 ]
+var colors = [31, 33, 32, 36, 34, 35 ]
, cl = colors.length
function addColorMarker (str, arg, i) {
var m = i % cl + 1