Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tidy search output by tuning date format, adjusting column widths and…

… truncating output for columns that is too long.
  • Loading branch information...
commit 1df29406fad54c0f99d1095784f5a6dd49b712bc 1 parent afcc93b
Tim Oxley authored

Showing 1 changed file with 11 additions and 64 deletions. Show diff stats Hide diff stats

  1. +11 64 lib/search.js
75 lib/search.js
@@ -146,19 +146,18 @@ function prettify (data, args) {
146 146 var longest = []
147 147 , spaces
148 148 , maxLen = npm.config.get("description")
149   - ? [1, 26, 60, 20, 11, Infinity]
150   - : [1, 26, 20, 11, Infinity]
  149 + ? [26, 60, 20, 11, Infinity]
  150 + : [26, 20, 11, Infinity]
151 151 , headings = npm.config.get("description")
152   - ? [" ", "NAME", "DESCRIPTION", "AUTHOR", "DATE", "KEYWORDS"]
153   - : [" ", "NAME", "AUTHOR", "DATE", "KEYWORDS"]
  152 + ? ["NAME", "DESCRIPTION", "AUTHOR", "DATE", "KEYWORDS"]
  153 + : ["NAME", "AUTHOR", "DATE", "KEYWORDS"]
154 154 , lines
155 155 , searchsort = (npm.config.get("searchsort") || "NAME").toLowerCase()
156   - , sortFields = { rating: 0
157   - , name: 1
158   - , description: 2
159   - , author: 3
160   - , date: 4
161   - , keywords: 5 }
  156 + , sortFields = { name: 0
  157 + , description: 1
  158 + , author: 2
  159 + , date: 3
  160 + , keywords: 4 }
162 161 , searchRev = searchsort.charAt(0) === "-"
163 162 , sortField = sortFields[searchsort.replace(/^\-+/, "")]
164 163
@@ -172,11 +171,7 @@ function prettify (data, args) {
172 171 data.keywords = data.keywords.split(/[,\s]+/)
173 172 }
174 173 if (!Array.isArray(data.keywords)) data.keywords = []
175   - var rating = getRating(data.time)
176   -
177   - var l = [
178   - String(rating)
179   - , data.name
  174 + var l = [ data.name
180 175 , data.description || ""
181 176 , data.maintainers.join(" ")
182 177 , data.time
@@ -185,7 +180,7 @@ function prettify (data, args) {
185 180 l.forEach(function (s, i) {
186 181 // limit description to maxLen.
187 182 // Remember to change this when changing/reordering columns
188   - if (s.length > maxLen[i] && i == 2) {
  183 + if (s.length > maxLen[i] && (i == 1 || i == 2)) {
189 184 s = l[i] = s.substring(0, maxLen[i] - 1) + '>'
190 185 }
191 186 var len = s.length
@@ -265,10 +260,6 @@ function addColorMarker (str, arg, i) {
265 260 }
266 261
267 262 function colorize (line) {
268   -
269   - // replace rating number (first char) with sexy color block
270   - line = getRatingColor(line[0]) + line.slice(2)
271   -
272 263 for (var i = 0; i < cl; i ++) {
273 264 var m = i + 1
274 265 line = line.split(String.fromCharCode(m)).join("\033["+colors[i]+"m")
@@ -276,47 +267,3 @@ function colorize (line) {
276 267 return line.split("\u0000").join("\033[0m")
277 268 }
278 269
279   -function getRating(dateString) {
280   - // simple rating based on modified time
281   - var aMonth = 1000 * 60 * 60 * 24 * 30 // a month (30 days) in milliseconds
282   - var aYearAgo = new Date().getTime() - aMonth * 12
283   - var oneMonthAgo = new Date().getTime() - aMonth * 1
284   - var threeMonthsAgo = new Date().getTime() - aMonth * 3
285   - var sixMonthsAgo = new Date().getTime() - aMonth * 6
286   -
287   - var modified = new Date(dateString).getTime() || aYearAgo
288   - if (modified > oneMonthAgo) {
289   - return 1
290   - } else if (modified > threeMonthsAgo) {
291   - return 2
292   - } else if (modified > sixMonthsAgo) {
293   - return 3
294   - } else if (modified > aYearAgo) {
295   - return 4
296   - } else {
297   - return 5
298   - }
299   -}
300   -
301   -function getRatingColor(rating) {
302   - var color
303   - switch(parseInt(rating)) {
304   - case 1:
305   - color = '\033[35;42m+' // green +
306   - break
307   - case 2:
308   - color = '\033[42m ' // green
309   - break
310   - case 3:
311   - color = '\033[43m ' // yellow
312   - break
313   - case 4:
314   - color = '\033[41m ' // red
315   - break
316   - case 5:
317   - default:
318   - color = '\033[9;41m ' // red
319   - break
320   - }
321   - return color + '\033[0m' // end
322   -}

0 comments on commit 1df2940

Please sign in to comment.
Something went wrong with that request. Please try again.