Skip to content

Commit ae5cca3

Browse files
sehropebuchdag
authored andcommitted
refactor: create outlet formatter once rather than for each line
The output padding is based upon the longest name of processes and thus never changes at runtime so we can optimize things a bit by only creating the output formatter pattern once at startup.
1 parent b412cee commit ae5cca3

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

outlet.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
type OutletFactory struct {
15-
Padding int
15+
LeftFormatter string
1616

1717
sync.Mutex
1818
}
@@ -80,8 +80,7 @@ func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, i
8080
if colorize {
8181
ct.ChangeColor(leftC, true, ct.None, false)
8282
}
83-
formatter := fmt.Sprintf("%%-%ds | ", of.Padding)
84-
fmt.Printf(formatter, left)
83+
fmt.Printf(of.LeftFormatter, left)
8584

8685
if colorize {
8786
if isError {

start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func runStart(cmd *Command, args []string) {
281281
handleError(err)
282282

283283
of := NewOutletFactory()
284-
of.Padding = pf.LongestProcessName(concurrency)
284+
of.LeftFormatter = fmt.Sprintf("%%-%ds | ", pf.LongestProcessName(concurrency))
285285

286286
f := &Forego{
287287
outletFactory: of,

0 commit comments

Comments
 (0)