Transform your Command Line Interface (CLI) function into a web browser-based terminal emulator.
-
go get github.com/byebyebruce/clipty
-
func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() opt := &server.Options{} err := clipty.RunServerWithOption(ctx, opt, nil, func(ctx context.Context, params map[string][]string, stdin *os.File, stdout *os.File, stderr *os.File) { for i := 0; i < 10; i++ { select { case <-ctx.Done(): return default: } time.Sleep(time.Second) fmt.Fprintln(stdout, "sleep", i+1) } fmt.Fprintln(stdout, "Bye..") }) if err != nil { log.Fatal(err) } }
-
go run .
- open http://localhost:8080