@@ -2,6 +2,7 @@ const semver = require('semver')
22const byteSize = require ( 'byte-size' )
33const relativeDate = require ( 'tiny-relative-date' )
44const columns = require ( 'cli-columns' )
5+ const sliceAnsi = require ( 'slice-ansi' )
56
67const {
78 h, // eslint-disable-line
@@ -45,6 +46,11 @@ class Columns extends Component {
4546 sort : false
4647 } )
4748 }
49+
50+ const Line = ( { width, children } ) => {
51+ const string = children . map ( renderToString ) . join ( '' )
52+ const sliced = sliceAnsi ( string , 0 , width )
53+ return string === sliced ? string : sliceAnsi ( string , 0 , width - 3 ) + '...'
4854}
4955
5056const packageValueObjectItems = function ( { field, value, props, maxItems } ) {
@@ -285,6 +291,7 @@ module.exports.PackageFields = PackageFields
285291
286292class PackageSummary extends Component {
287293 render ( ) {
294+ const width = process . env . COLUMNS - 2
288295 let { packument, spec } = this . props
289296 let [ data ] = getData ( packument , spec )
290297 let views = data . map ( ( pkg ) => {
@@ -309,8 +316,12 @@ class PackageSummary extends Component {
309316 </ span >
310317 </ div >
311318
312- < div > { pkg . description } </ div >
313- < span > < PackageValue { ...getProps ( 'homepage' ) } /> - < PackageValue { ...getProps ( 'keywords' ) } /> </ span >
319+ < div > < Line width = { width } > { pkg . description } </ Line > </ div >
320+ < span >
321+ < Line width = { width } >
322+ < PackageValue { ...getProps ( 'homepage' ) } /> - < PackageValue { ...getProps ( 'keywords' ) } />
323+ </ Line >
324+ </ span >
314325 </ Box >
315326 } )
316327
@@ -324,6 +335,7 @@ module.exports.PackageSummary = PackageSummary
324335
325336class PackageSearchResult extends Component {
326337 render ( ) {
338+ const width = process . env . COLUMNS - 2
327339 const { result : { package : pkg } } = this . props
328340 return < Box >
329341 < div >
@@ -337,8 +349,12 @@ class PackageSearchResult extends Component {
337349 </ span >
338350 </ div >
339351
340- < div > { pkg . description } </ div >
341- < span > < PackageValue field = 'homepage' value = { pkg . links . homepage } /> - < PackageValue field = 'keywords' value = { pkg . keywords } /> </ span >
352+ < div > < Line width = { width } > { pkg . description } </ Line > </ div >
353+ < span >
354+ < Line width = { width } >
355+ < PackageValue field = 'homepage' value = { pkg . links . homepage } /> - < PackageValue field = 'keywords' value = { pkg . keywords } />
356+ </ Line >
357+ </ span >
342358 </ Box >
343359 }
344360}
0 commit comments