Esempio n. 1
0
func dst(name string) (zx.Dir, error) {
	if strings.Contains(name, ",") {
		return nil, errors.New("destination can't be a predicate")
	}
	d, err := cmd.Stat(name)
	if zx.IsNotExist(err) {
		path := cmd.AbsPath(name)
		ppath := fpath.Dir(path)
		pd, err := cmd.Stat(ppath)
		if err != nil {
			return nil, err
		}
		if pd["type"] != "d" {
			return nil, fmt.Errorf("%s: %s", pd["path"], zx.ErrNotDir)
		}
		base := fpath.Base(path)
		pd["path"] = fpath.Join(pd["path"], base)
		pd["Upath"] = name
		pd["Rpath"] = "/"
		if pd["addr"] != "" {
			pd["addr"] += "/" + base
		}
		return pd, nil
	}
	return d, nil
}
Esempio n. 2
0
func main() {
	opts := opt.New("[file]")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	rdonly := false
	opts.NewFlag("r", "read only", &rdonly)
	opts.NewFlag("e", "do edits for testing", &doedits)
	cmd.UnixIO("err")
	args := opts.Parse()
	var t *ink.Txt
	inkout := cmd.Out("ink")
	if inkout == nil {
		cmd.UnixIO()
	}
	if len(args) == 0 {
		t = ink.NewTxt("1234", "abc")
	} else {
		dat, err := zx.GetAll(cmd.NS(), cmd.AbsPath(args[0]))
		if err != nil {
			cmd.Fatal(err)
		}
		t = ink.NewTxt(args[0]+" Del", string(dat))
	}
	go edit(t)
	if rdonly {
		t.NoEdits()
	}
	ink.UsePort("8182")
	bs := ink.NewButtonSet(&ink.Button{Tag: "One", Name: "one"},
		&ink.Button{Tag: "Two", Name: "two"},
		&ink.Button{Tag: "B", Name: "b", Value: &bold},
		&ink.Button{Tag: "I", Name: "i", Value: &italic})
	rs := ink.NewRadioSet(&style, &ink.Button{Tag: "R", Name: "r"},
		&ink.Button{Tag: "T", Name: "t"})
	go buttons(bs, rs, t)

	pg := ink.NewPg("/", "Example text editing:", bs, rs, t)
	pg.Tag = "Clive's iedit"
	if doedits {
		go edits(t)
	}
	go ink.Serve()
	if inkout != nil {
		// TODO: ctlrs must use unique ids sytem-wide, or
		// controls written won't work because of their ids.
		inkout <- []byte(`<tt>Hi there, this is HTML</tt>`)
		var buf bytes.Buffer
		bs.WriteTo(&buf)
		inkout <- buf.Bytes()
		inkout <- []byte("https://localhost:8182")
	}
	t.Wait()
	for rs := range t.Get(0, -1) {
		cmd.Printf("%s", string(rs))
	}
}
Esempio n. 3
0
// Run path in the current app context.
func main() {
	cmd.UnixIO("err")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("r", "dir: print paths relative to dir", &dir)
	opts.NewFlag("d", "print parent directories", &dflag)
	opts.NewFlag("b", "print base names", &bflag)
	args := opts.Parse()
	if ux {
		cmd.UnixIO()
	}
	if dir != "" && (dflag || bflag) {
		cmd.Warn("incompatible flags")
		opts.Usage()
	}
	if dflag && bflag {
		cmd.Warn("incompatible flags")
		opts.Usage()
	}
	if dir != "" {
		dir = cmd.AbsPath(dir)
	}
	var sts error
	for _, n := range args {
		n = cmd.AbsPath(n)
		switch {
		case dir != "":
			r, err := filepath.Rel(dir, n)
			if err != nil {
				sts = err
				cmd.Warn("%s: %s", n, err)
			} else {
				n = r
			}
		case dflag:
			n = fpath.Dir(n)
		case bflag:
			n = fpath.Base(n)
		}
		cmd.Printf("%s\n", n)
	}
	cmd.Exit(sts)
}