Permalink
Browse files

Tidy search output:

* Truncate description to maxLen to get neater npm search output.
* Remove updated time (but leave date) from npm search results.
* Increase space for name from 20 to 30 characters.
* Remove unnecessary brackets around 'prehistoric'.
* Make date column fit the word 'prehistoric' better.
* Reduce name column to 26 chars.
* Tighten space between status and name.
  • Loading branch information...
1 parent 57003ea commit c32dec54039eafbae723dab448dad6d96300e53d @timoxley committed Mar 25, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/search.js
View
@@ -94,7 +94,8 @@ function stripData (data) {
&& (new Date(data.time.modified).toISOString()
.split("T").join(" ")
.replace(/:[0-9]{2}\.[0-9]{3}Z$/, ""))
- || "(prehistoric)"
+ .slice(0, -5) // remove time
+ || "prehistoric"
}
}
@@ -145,8 +146,8 @@ function prettify (data, args) {
var longest = []
, spaces
, maxLen = npm.config.get("description")
- ? [20, 60, 20, 20, Infinity]
- : [20, 20, 20, Infinity]
+ ? [26, 60, 20, 11, Infinity]
+ : [26, 20, 11, Infinity]
, headings = npm.config.get("description")
? ["NAME", "DESCRIPTION", "AUTHOR", "DATE", "KEYWORDS"]
: ["NAME", "AUTHOR", "DATE", "KEYWORDS"]
@@ -170,13 +171,18 @@ function prettify (data, args) {
data.keywords = data.keywords.split(/[,\s]+/)
}
if (!Array.isArray(data.keywords)) data.keywords = []
- var l = [ data.name
+ var l = [ data.name
, data.description || ""
, data.maintainers.join(" ")
, data.time
, (data.keywords || []).join(" ")
]
l.forEach(function (s, i) {
+ // limit description to maxLen.
+ // Remember to change this when changing/reordering columns
+ if (s.length > maxLen[i] && (i == 1 || i == 2)) {
+ s = l[i] = s.substring(0, maxLen[i] - 1) + '>'
+ }
var len = s.length
longest[i] = Math.min(maxLen[i] || Infinity
,Math.max(longest[i] || 0, len))
@@ -221,7 +227,7 @@ function prettify (data, args) {
return headings.map(function (h, i) {
var space = Math.max(2, 3 + (longest[i] || 0) - h.length)
return h + (new Array(space).join(" "))
- }).join("").substr(0, cols).trim() + "\n" + lines.join("\n")
+ }).join("").substr(0, cols) + "\n" + lines.join("\n")
}
@@ -260,3 +266,4 @@ function colorize (line) {
}
return line.split("\u0000").join("\033[0m")
}
+

0 comments on commit c32dec5

Please sign in to comment.