-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LilithGames/jansen
add agent option
- Loading branch information
Showing
4 changed files
with
111 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package agent | ||
|
||
import "github.com/olekukonko/tablewriter" | ||
|
||
type ViewOpt struct { | ||
tableApply []func(*tablewriter.Table) | ||
} | ||
|
||
func mergeViewOpt(opts ...*ViewOpt) *ViewOpt { | ||
res := &ViewOpt{} | ||
for _, opt := range opts { | ||
if opt == nil { | ||
continue | ||
} | ||
res.tableApply = append(res.tableApply, opt.tableApply...) | ||
} | ||
return res | ||
} | ||
|
||
func (o *ViewOpt) apply(t *tablewriter.Table) { | ||
for _, f := range o.tableApply { | ||
if f == nil { | ||
continue | ||
} | ||
f(t) | ||
} | ||
} | ||
|
||
func ViewColWidth(v int) *ViewOpt { | ||
return &ViewOpt{ | ||
tableApply: []func(*tablewriter.Table){ | ||
func(t *tablewriter.Table) { | ||
t.SetColWidth(v) | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type AgentOpt struct { | ||
view *ViewOpt | ||
} | ||
|
||
func AgentViewOpt(opts ...*ViewOpt) *AgentOpt { | ||
return &AgentOpt{ | ||
view: mergeViewOpt(opts...), | ||
} | ||
} | ||
|
||
func (o *AgentOpt) getView() *ViewOpt { | ||
return o.view | ||
} | ||
|
||
func mergeAgentOpt(opts ...*AgentOpt) *AgentOpt { | ||
res := &AgentOpt{} | ||
for _, opt := range opts { | ||
if opt == nil { | ||
continue | ||
} | ||
res.view = mergeViewOpt(res.view, opt.view) | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters