@@ -7,8 +7,9 @@ const yaml = require('js-yaml')
77const execSync = require ( 'child_process' ) . execSync
88const program = require ( 'commander' )
99const prompt = require ( 'prompt-sync' ) ( )
10- const spellcheck = require ( 'nodehun-sentences' ) ;
11- const nodehun = require ( 'nodehun' ) ;
10+ const spellcheck = require ( 'nodehun-sentences' )
11+ const nodehun = require ( 'nodehun' )
12+ const emoji = require ( 'node-emoji' )
1213
1314const templateFileName = '.gitcommit_template'
1415const definitionsFileName = '.git_consistent'
@@ -62,15 +63,35 @@ const createProgram = (program, definitions, terms) => {
6263 . parse ( process . argv )
6364}
6465
66+ const formatChoices = ( choices ) => {
67+ const nameMaxLength = _ ( choices ) . map ( 'name' ) . map ( ( n ) => { return n . length } ) . max ( )
68+ const emojiMaxLength = _ ( choices ) . map ( 'emoji' ) . map ( ( n ) => { return n . length } ) . max ( )
69+
70+ aaa = _ . map ( choices , ( choice ) => {
71+ const n = _ . padEnd ( choice . name , nameMaxLength )
72+ const e = emojiMaxLength === 0 ? '' : _ . padEnd ( choice . emoji , 3 )
73+ return [ n , e , choice . description ] . join ( " " )
74+ } )
75+ return aaa . join ( "\n" )
76+ }
77+
6578const select = ( term , definition ) => {
6679 const none = "(none)"
6780 const header = `Select ${ term } : `
68- const choices = _ . map ( definition . values , function ( value ) { return `${ value . name } \t${ value . description } ` } )
69- if ( ! definition . required ) choices . unshift ( `\t${ none } ` )
70- const command = `echo '${ _ . replace ( choices . join ( "\n" ) , "'" , '"' ) } ' | fzf --reverse --cycle --header="${ header } "`
81+ const choices = _ . map ( definition . values , function ( value ) {
82+ const name = value . name
83+ const description = value . description
84+ let emojiStr = ''
85+
86+ if ( / ^ : .+ : $ / . test ( name ) && emoji . hasEmoji ( name ) ) emojiStr = emoji . get ( name )
87+ return { name : name , emoji : emojiStr , description : description }
88+ } )
89+ if ( ! definition . required ) choices . unshift ( { name : '' , emoji : '' , description : none } )
90+
91+ const command = `echo '${ _ . replace ( formatChoices ( choices ) , "'" , '"' ) } ' | fzf --reverse --cycle --header="${ header } "`
7192
7293 const selectedValue = execSync ( command , { stdio : [ 'inherit' , 'pipe' , 'inherit' ] , shell : true } ) . toString ( ) . trim ( )
73- const value = selectedValue . split ( "\t " ) [ 0 ]
94+ const value = selectedValue . split ( " " ) [ 0 ]
7495 const v = value === none ? '' : value
7596 console . log ( `${ header } ${ value } ` )
7697 return v
0 commit comments