yeoman / yosay

Tell Yeoman what to say
BSD 2-Clause "Simplified" License
205 stars 43 forks source link

Have some problems with Chinese characters #17

Closed sunnylost closed 9 years ago

sunnylost commented 9 years ago
var Chalk        = require( 'chalk' ),
    Yosay        = require( 'yosay' ),
    StringLength = require( 'string-length' ),
    message      = []

var newVersion = Chalk.green.bold( '1.0.3' ),
    curVersion = Chalk.gray( ' (current: 1.0.1)' ),
    command    = Chalk.magenta( 'sudo npm install -g cage' )

message.push( '项目可以更新了: ' + newVersion + curVersion )
message.push( '运行' + command + ' to update' )
console.log( Yosay( message.join( ' ' ), { maxLength: StringLength( message[ 0 ] ) } ) )

Result:


     _-----_
    |       |    .---------------------------------.
    |--(o)--|    | 项目可以更新了: 1.0.3 (current: 1.0.1) |
   `---------´   |  运行sudo npm install -g cage to  |
    ( _´U`_ )    |              update             |
    /___A___\    '---------------------------------'
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 
sindresorhus commented 9 years ago

This is fixed in 1.0.5. Use string-width instead of string-length.