@@ -175,36 +175,48 @@ func displaySlice(listVal reflect.Value, fieldList []string) {
175175 for i := 0 ; i < listVal .Len (); i ++ {
176176 elemVal := listVal .Index (i )
177177 elemType := elemVal .Type ()
178- row := make ( map [string ]interface {})
178+ rows := [] map [string ]interface {}{}
179179 for j := 0 ; j < elemVal .NumField (); j ++ {
180180 field := elemVal .Field (j )
181181 fieldName := elemType .Field (j ).Name
182182 if _ , ok := showFieldMap [fieldName ]; ok {
183- row [fieldName ] = field .Interface ()
184183 text := fmt .Sprintf ("%v" , field .Interface ())
185- width := calcWidth (text )
186- if showFieldMap [fieldName ] < width {
187- showFieldMap [fieldName ] = width
184+ cells := strings .Split (text , "\n " )
185+ for i , cell := range cells {
186+ width := calcWidth (cell )
187+ if showFieldMap [fieldName ] < width {
188+ showFieldMap [fieldName ] = width
189+ }
190+ if len (rows ) == i {
191+ rows = append (rows , make (map [string ]interface {}))
192+ }
193+ rows [i ][fieldName ] = cell
188194 }
189195 }
190196 }
191- rowList = append (rowList , row )
197+ rowList = append (rowList , rows ... )
192198 }
193199 printTable (rowList , fieldList , showFieldMap )
194200}
195201
196202func printTable (rowList []map [string ]interface {}, fieldList []string , fieldWidthMap map [string ]int ) {
203+ //打印表头
197204 for _ , field := range fieldList {
198205 tmpl := "%-" + strconv .Itoa (fieldWidthMap [field ]+ GAP ) + "s"
199206 fmt .Printf (tmpl , field )
200207 }
201208 fmt .Printf ("\n " )
202209
210+ //打印数据
203211 for _ , row := range rowList {
204212 for _ , field := range fieldList {
205213 cutWidth := calcCutWidth (fmt .Sprintf ("%v" , row [field ]))
206214 tmpl := "%-" + strconv .Itoa (fieldWidthMap [field ]- cutWidth + GAP ) + "v"
207- fmt .Printf (tmpl , row [field ])
215+ if row [field ] != nil {
216+ fmt .Printf (tmpl , row [field ])
217+ } else {
218+ fmt .Printf (tmpl , "" )
219+ }
208220 }
209221 fmt .Printf ("\n " )
210222 }
@@ -239,6 +251,11 @@ func FormatDate(seconds int) string {
239251 return time .Unix (int64 (seconds ), 0 ).Format ("2006-01-02" )
240252}
241253
254+ //FormatDateTime 格式化时间,把以秒为单位的时间戳格式化未年月日/时分秒
255+ func FormatDateTime (seconds int ) string {
256+ return time .Unix (int64 (seconds ), 0 ).Format ("2006-01-02/15:04:05" )
257+ }
258+
242259//RegionLabel regionlable
243260var RegionLabel = map [string ]string {
244261 "cn-bj1" : "Beijing1" ,
0 commit comments