clipty

package module
v0.0.0-...-30ec66f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 6 Imported by: 7

README

CLIPTY

Transform your Command Line Interface (CLI) function into a web browser-based terminal emulator.

Preview

Usage

  1. go get github.com/byebyebruce/clipty
    
  2. 
    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)
        }
    }
    
  3. go run .
    
  4. open http://localhost:8080

Example

example

SPECIAL THANKS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunServer

func RunServer(ctx context.Context, mainFunc MainFunc) error

RunServer runs a cli web server

func RunServerWithOption

func RunServerWithOption(ctx context.Context, opt *server.Options, mainFunc MainFunc) error

func RunServerWithPersistParams

func RunServerWithPersistParams(ctx context.Context, opt *server.Options, mainFunc MainFunc, persistParams map[string][]string) error

Types

type MainFunc

type MainFunc func(ctx context.Context, params url.Values, std Std)

MainFunc is CLI main loop function.

type Std

type Std struct {
	Stdin  *os.File
	Stdout *os.File
	Stderr *os.File
}

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL