mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
bundle chans to struct
This commit is contained in:
@@ -29,6 +29,12 @@ type PSScanner interface {
|
|||||||
Run(triggerCh chan struct{}) (chan string, chan error)
|
Run(triggerCh chan struct{}) (chan string, chan error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type chans struct {
|
||||||
|
sigCh chan os.Signal
|
||||||
|
fsEventCh chan string
|
||||||
|
psEventCh chan string
|
||||||
|
}
|
||||||
|
|
||||||
func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{} {
|
func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{} {
|
||||||
b.Logger.Infof("Config: %+v", cfg)
|
b.Logger.Infof("Config: %+v", cfg)
|
||||||
|
|
||||||
@@ -39,25 +45,30 @@ func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{}
|
|||||||
|
|
||||||
triggerEvery(100*time.Millisecond, triggerCh)
|
triggerEvery(100*time.Millisecond, triggerCh)
|
||||||
|
|
||||||
exit := printOutput(cfg, b, sigCh, fsEventCh, psEventCh)
|
chans := &chans{
|
||||||
|
sigCh: sigCh,
|
||||||
|
fsEventCh: fsEventCh,
|
||||||
|
psEventCh: psEventCh,
|
||||||
|
}
|
||||||
|
exit := printOutput(cfg, b, chans)
|
||||||
return exit
|
return exit
|
||||||
}
|
}
|
||||||
|
|
||||||
func printOutput(cfg *config.Config, b *Bindings, sigCh chan os.Signal, fsEventCh chan string, psEventCh chan string) chan struct{} {
|
func printOutput(cfg *config.Config, b *Bindings, chans *chans) chan struct{} {
|
||||||
exit := make(chan struct{})
|
exit := make(chan struct{})
|
||||||
fsEventColor, psEventColor := getColors(cfg.Colored)
|
fsEventColor, psEventColor := getColors(cfg.Colored)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case se := <-sigCh:
|
case se := <-chans.sigCh:
|
||||||
b.Logger.Infof("Exiting program... (%s)", se)
|
b.Logger.Infof("Exiting program... (%s)", se)
|
||||||
exit <- struct{}{}
|
exit <- struct{}{}
|
||||||
case fe := <-fsEventCh:
|
case fe := <-chans.fsEventCh:
|
||||||
if cfg.LogFS {
|
if cfg.LogFS {
|
||||||
b.Logger.Eventf(fsEventColor, "FS: %+v", fe)
|
b.Logger.Eventf(fsEventColor, "FS: %+v", fe)
|
||||||
}
|
}
|
||||||
case pe := <-psEventCh:
|
case pe := <-chans.psEventCh:
|
||||||
if cfg.LogPS {
|
if cfg.LogPS {
|
||||||
b.Logger.Eventf(psEventColor, "CMD: %+v", pe)
|
b.Logger.Eventf(psEventColor, "CMD: %+v", pe)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user