go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

main.go (966B)


      1 // Example: Pagination of long resource result content.
      2 package main
      3 
      4 import (
      5 	"context"
      6 	"flag"
      7 	"fmt"
      8 	"os"
      9 	"path"
     10 
     11 	testdataloader "github.com/peteole/testdata-loader"
     12 
     13 	"git.defalsify.org/vise.git/engine"
     14 	"git.defalsify.org/vise.git/resource"
     15 	fsdb "git.defalsify.org/vise.git/db/fs"
     16 )
     17 var (
     18 	baseDir = testdataloader.GetBasePath()
     19 	scriptDir = path.Join(baseDir, "examples", "longmenu")
     20 )
     21 
     22 func main() {
     23 	var size uint
     24 	flag.UintVar(&size, "s", 0, "max size of output")
     25 	flag.Parse()
     26 
     27 	ctx := context.Background()
     28 	store := fsdb.NewFsDb()
     29 	err := store.Connect(ctx, scriptDir)
     30 	if err != nil {
     31 		fmt.Fprintf(os.Stderr, "db connect error: %v", err)
     32 		os.Exit(1)
     33 	}
     34 	rs := resource.NewDbResource(store)
     35 	defer rs.Close()
     36 	cfg := engine.Config {
     37 		OutputSize: uint32(size),
     38 	}
     39 	en := engine.NewEngine(cfg, rs)
     40 	err = engine.Loop(ctx, en, os.Stdin, os.Stdout, nil)
     41 	if err != nil {
     42 		fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
     43 		os.Exit(1)
     44 	}
     45 }