@@ -6,6 +6,7 @@ package cmdr
6
6
7
7
import (
8
8
"fmt"
9
+ "strconv"
9
10
"strings"
10
11
)
11
12
@@ -82,9 +83,9 @@ func (s *helpPainter) FpCommandsTitle(command *Command) {
82
83
func (s * helpPainter ) FpCommandsGroupTitle (group string ) {
83
84
if group != UnsortedGroup {
84
85
if GetBoolR ("no-color" ) {
85
- s .Printf (" [%s]" , StripOrderPrefix (group ))
86
+ s .Printf (fmtCmdGroupTitleNC , StripOrderPrefix (group ))
86
87
} else {
87
- s .Printf (" [ \x1b [2m \x1b [%dm%s \x1b [0m]" , CurrentGroupTitleColor , StripOrderPrefix (group ))
88
+ s .Printf (fmtCmdGroupTitle , CurrentGroupTitleColor , StripOrderPrefix (group ))
88
89
}
89
90
}
90
91
}
@@ -93,18 +94,18 @@ func (s *helpPainter) FpCommandsLine(command *Command) {
93
94
if ! command .Hidden {
94
95
if len (command .Deprecated ) > 0 {
95
96
if GetBoolR ("no-color" ) {
96
- s .Printf (" %-48s%s [deprecated since %v]" , command .GetTitleNames (), command .Description , command .Deprecated )
97
+ s .Printf (fmtCmdlineDepNC , command .GetTitleNames (), command .Description , command .Deprecated )
97
98
} else {
98
- s .Printf (" \x1b [%dm \x1b [%dm%-48s%s \x1b [0m [deprecated since %v]" , BgNormal , CurrentDescColor , command .GetTitleNames (), command .Description , command .Deprecated )
99
+ s .Printf (fmtCmdlineDep , BgNormal , CurrentDescColor , command .GetTitleNames (), command .Description , command .Deprecated )
99
100
}
100
101
} else {
101
102
if GetBoolR ("no-color" ) {
102
- s .Printf (" %-48s%s" , command .GetTitleNames (), command .Description )
103
+ s .Printf (fmtCmdlineNC , command .GetTitleNames (), command .Description )
103
104
} else {
104
105
// s.Printf(" %-48s%v", command.GetTitleNames(), command.Description)
105
106
// s.Printf("\n\x1b[%dm\x1b[%dm%s\x1b[0m", BgNormal, DarkColor, title)
106
107
// s.Printf(" [\x1b[%dm\x1b[%dm%s\x1b[0m]", BgDim, DarkColor, StripOrderPrefix(group))
107
- s .Printf (" %-48s \x1b [%dm \x1b [%dm%s \x1b [0m" , command .GetTitleNames (), BgNormal , CurrentDescColor , command .Description )
108
+ s .Printf (fmtCmdline , command .GetTitleNames (), BgNormal , CurrentDescColor , command .Description )
108
109
}
109
110
}
110
111
}
@@ -127,34 +128,69 @@ func (s *helpPainter) FpFlagsTitle(command *Command, flag *Flag, title string) {
127
128
func (s * helpPainter ) FpFlagsGroupTitle (group string ) {
128
129
if group != UnsortedGroup {
129
130
if GetBoolR ("no-color" ) {
130
- s .Printf (" [%s]" , StripOrderPrefix (group ))
131
+ s .Printf (fmtGroupTitleNC , StripOrderPrefix (group ))
131
132
} else {
132
133
// fp(" [%s]:", StripOrderPrefix(group))
133
134
// // echo -e "Normal \e[2mDim"
134
135
// _, _ = fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m\x1b[2m\x1b[%dm[%04d]\x1b[0m%-48s \x1b[2m\x1b[%dm%s\x1b[0m ",
135
136
// levelColor, levelText, DarkColor, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message, DarkColor, caller)
136
- s .Printf (" [ \x1b [2m \x1b [%dm%s \x1b [0m]" , CurrentGroupTitleColor , StripOrderPrefix (group ))
137
+ s .Printf (fmtGroupTitle , CurrentGroupTitleColor , StripOrderPrefix (group ))
137
138
}
138
139
}
139
140
}
140
141
141
142
func (s * helpPainter ) FpFlagsLine (command * Command , flg * Flag , defValStr string ) {
142
143
if len (flg .Deprecated ) > 0 {
143
144
if GetBoolR ("no-color" ) {
144
- s .Printf (" %-48s%s%s [deprecated since %v]" , flg . GetTitleFlagNames (), flg . Description ,
145
- defValStr , flg .Deprecated )
145
+ s .Printf (fmtFlagsDepNC , // " %-48s%s%s [deprecated since %v]",
146
+ flg . GetTitleFlagNames (), flg . Description , defValStr , flg .Deprecated )
146
147
} else {
147
- s .Printf (" \x1b [%dm\x1b [%dm%-48s%s\x1b [%dm\x1b [%dm%s\x1b [0m [deprecated since %v]" ,
148
+ s .Printf (fmtFlagsDep , // " \x1b[%dm\x1b[%dm%-48s%s\x1b[%dm\x1b[%dm%s\x1b[0m [deprecated since %v]",
148
149
BgNormal , CurrentDescColor , flg .GetTitleFlagNames (), flg .Description ,
149
150
BgItalic , CurrentDefaultValueColor , defValStr , flg .Deprecated )
150
151
}
151
152
} else {
152
153
if GetBoolR ("no-color" ) {
153
- s .Printf (" %-48s%s%s" , flg .GetTitleFlagNames (), flg .Description , defValStr )
154
+ s .Printf (fmtFlagsNC , flg .GetTitleFlagNames (), flg .Description , defValStr )
154
155
} else {
155
- s .Printf (" %-48s\x1b [%dm\x1b [%dm%s\x1b [%dm\x1b [%dm%s\x1b [0m" ,
156
+ s .Printf (fmtFlags , // " %-48s\x1b[%dm\x1b[%dm%s\x1b[%dm\x1b[%dm%s\x1b[0m",
156
157
flg .GetTitleFlagNames (), BgNormal , CurrentDescColor , flg .Description ,
157
158
BgItalic , CurrentDefaultValueColor , defValStr )
158
159
}
159
160
}
160
161
}
162
+
163
+ // SetHelpTabStop sets the tab stop for help screen output
164
+ func SetHelpTabStop (tabStop int ) {
165
+ initTabStop (tabStop )
166
+ }
167
+
168
+ func initTabStop (ts int ) {
169
+ tabStop = ts
170
+
171
+ var s = strconv .Itoa (tabStop )
172
+
173
+ fmtCmdGroupTitle = " [\x1b [2m\x1b [%dm%s\x1b [0m]"
174
+ fmtCmdGroupTitleNC = " [%s]"
175
+
176
+ fmtCmdline = " %-" + s + "s\x1b [%dm\x1b [%dm%s\x1b [0m"
177
+ fmtCmdlineDep = " \x1b [%dm\x1b [%dm%-" + s + "s%s\x1b [0m [deprecated since %v]"
178
+ fmtCmdlineNC = " %-" + s + "s%s"
179
+ fmtCmdlineDepNC = " %-" + s + "s%s [deprecated since %v]"
180
+
181
+ fmtGroupTitle = " [\x1b [2m\x1b [%dm%s\x1b [0m]"
182
+ fmtGroupTitleNC = " [%s]"
183
+
184
+ fmtFlagsDep = " \x1b [%dm\x1b [%dm%-" + s + "s%s\x1b [%dm\x1b [%dm%s\x1b [0m [deprecated since %v]"
185
+ fmtFlags = " %-" + s + "s\x1b [%dm\x1b [%dm%s\x1b [%dm\x1b [%dm%s\x1b [0m"
186
+ fmtFlagsDepNC = " %-" + s + "s%s%s [deprecated since %v]"
187
+ fmtFlagsNC = " %-" + s + "s%s%s"
188
+ }
189
+
190
+ var (
191
+ tabStop = 48
192
+ fmtCmdGroupTitle , fmtCmdGroupTitleNC string
193
+ fmtCmdline , fmtCmdlineDep , fmtCmdlineNC , fmtCmdlineDepNC string
194
+ fmtGroupTitle , fmtGroupTitleNC string
195
+ fmtFlags , fmtFlagsDep , fmtFlagsNC , fmtFlagsDepNC string
196
+ )
0 commit comments