github.com/webx-top/com@v1.2.12/test/process/main.go (about)

     1  package main
     2  
     3  import (
     4  	"bufio"
     5  	"context"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/admpub/color"
    10  	"github.com/webx-top/com"
    11  )
    12  
    13  func main() {
    14  	ctx := context.Background()
    15  	// Listen to keypress of "return" and restart the app automatically
    16  	go func() {
    17  		color.Blue(`[process] listen return ==> ` + com.NowStr())
    18  		in := bufio.NewReader(os.Stdin)
    19  		for {
    20  			select {
    21  			case <-ctx.Done():
    22  				return
    23  			default:
    24  				color.Yellow(`[process] reading ==> ` + com.NowStr())
    25  				input, _ := in.ReadString(com.LF)
    26  				if input == com.StrLF || input == com.StrCRLF {
    27  					color.Green(`[process] restart ==> ` + com.NowStr())
    28  				} else {
    29  					color.Blue(`[process] waiting ==> ` + com.NowStr())
    30  				}
    31  				time.Sleep(20 * time.Second)
    32  				//os.Exit(1)
    33  			}
    34  		}
    35  	}()
    36  
    37  	<-make(chan struct{})
    38  }