Skip to content

Commit 4a86759

Browse files
committed
Factor out MaxLocWidthPlusOne()
1 parent 3fa0007 commit 4a86759

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

markut.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,17 @@ func defaultContext() (EvalContext, bool) {
196196
return context, true
197197
}
198198

199-
func PrintFlagsSummary(flags []Token) {
199+
func MaxLocWidthPlusOne(tokens []Token) int {
200200
locWidth := 0
201-
for _, flag := range flags {
201+
for _, token := range tokens {
202202
// TODO: Loc.String() should include the extra ":", but that requires a huge refactoring in all the places where call it explicitly or implicitly
203-
locWidth = max(locWidth, len(flag.Loc.String()) + 1)
203+
locWidth = max(locWidth, len(token.Loc.String()) + 1)
204204
}
205+
return locWidth
206+
}
207+
208+
func PrintFlagsSummary(flags []Token) {
209+
locWidth := MaxLocWidthPlusOne(flags)
205210
// TODO: merge together parameters defined on the same line
206211
for _, flag := range flags {
207212
fmt.Printf("%-*s %s\n", locWidth, flag.Loc.String() + ":", string(flag.Text))
@@ -244,12 +249,13 @@ func (context EvalContext) PrintSummary() error {
244249
TwitchVodFileRegexp := "([0-9]+)-[0-9a-f\\-]+\\.mp4"
245250
re := regexp.MustCompile(TwitchVodFileRegexp)
246251
fmt.Printf(">>> Twitch Chat Logs (Detected by regex `%s`)\n", TwitchVodFileRegexp)
252+
locWidth := MaxLocWidthPlusOne(context.inputPathLog)
247253
for _, inputPath := range context.inputPathLog {
248254
match := re.FindStringSubmatch(string(inputPath.Text))
249255
if len(match) > 0 {
250-
fmt.Printf("%s: https://www.twitchchatdownloader.com/video/%s\n", inputPath.Loc, match[1])
256+
fmt.Printf("%-*s https://www.twitchchatdownloader.com/video/%s\n", locWidth, inputPath.Loc.String() + ":", match[1])
251257
} else {
252-
fmt.Printf("%s: NO MATCH\n", inputPath.Loc)
258+
fmt.Printf("%-*s NO MATCH\n", locWidth, inputPath.Loc.String() + ":")
253259
}
254260
}
255261
fmt.Println()

0 commit comments

Comments
 (0)