chore: 优化 tool table printer

This commit is contained in:
loveuer 2024-07-19 15:13:36 +08:00
parent 6c5e74525e
commit 1efc908b05

View File

@ -54,9 +54,16 @@ Start:
reflect.Float64,
reflect.Complex64,
reflect.Complex128,
reflect.Interface,
reflect.String:
reflect.Interface:
w.AppendRow(table.Row{strings.TrimPrefix(prefix, "."), rv.Interface()})
case reflect.String:
val := rv.String()
if len(val) <= 160 {
w.AppendRow(table.Row{strings.TrimPrefix(prefix, "."), val})
return
}
w.AppendRow(table.Row{strings.TrimPrefix(prefix, "."), val[0:64] + "..." + val[len(val)-64:]})
case reflect.Array, reflect.Slice:
for i := 0; i < rv.Len(); i++ {
p := strings.Join([]string{prefix, fmt.Sprintf("[%d]", i)}, ".")