示例#1
0
func events(win *acme.Win, rerun chan<- struct{}) {
	for e := range win.EventChan() {
		debugPrint("Acme event: %+v\n", e)
		switch e.C2 {
		case 'x', 'X':
			switch string(e.Text) {
			case "Get":
				kill()
				rerun <- struct{}{}

			case "Del":
				kill()
				if err := win.Ctl("delete"); err != nil {
					log.Fatalln("Failed to delete the window:", err)
				}

			default:
				win.WriteEvent(e)
			}

		default:
			win.WriteEvent(e)
		}
	}
	os.Exit(0)
}
示例#2
0
文件: main.go 项目: aoeu/acme
func reloadShowAddr(win *acme.Win, off int) error {
	if err := win.Ctl("get"); err != nil {
		return err
	}
	if err := win.Addr("#%d", off); err != nil {
		return err
	}
	return win.Ctl("dot=addr\nshow")
}
示例#3
0
文件: main.go 项目: aoeu/acme
func readAddr(win *acme.Win) (q0, q1 int, err error) {
	if _, _, err := win.ReadAddr(); err != nil {
		return 0, 0, err
	}
	if err := win.Ctl("addr=dot"); err != nil {
		return 0, 0, err
	}
	return win.ReadAddr()
}
示例#4
0
文件: main.go 项目: uluyol/tools
func readAddr(win *acme.Win) (q0, q1 int, err error) {
	// This first read is bogus.
	// Acme zeroes the win's address the first time addr is opened.
	// So, we need to open it before setting addr=dot,
	// lest we just read back a zero address.
	if _, _, err := win.ReadAddr(); err != nil {
		return 0, 0, err
	}
	if err := win.Ctl("addr=dot\n"); err != nil {
		return 0, 0, err
	}
	return win.ReadAddr()
}
示例#5
0
文件: main.go 项目: uluyol/tools
func writeBody(win *acme.Win, ffile string) error {
	if err := win.Ctl("nomark"); err != nil {
		fmt.Fprintf(os.Stderr, "failed to set nomark: %s", err)
	}
	defer func() {
		if err := win.Ctl("mark"); err != nil {
			fmt.Fprintf(os.Stderr, "failed to set mark: %s", err)
		}
	}()
	tf, err := os.Open(ffile)
	if err != nil {
		return err
	}
	defer tf.Close()
	if err := win.Addr("0,$"); err != nil {
		return err
	}
	_, err = io.Copy(dataWriter{win}, tf)
	return err
}
示例#6
0
文件: Dict.go 项目: rjkroege/go
func events(w *acme.Win) <-chan string {
	c := make(chan string, 10)
	go func() {
		for e := range w.EventChan() {
			switch e.C2 {
			case 'x', 'X': // execute
				if string(e.Text) == "Del" {
					w.Ctl("delete")
				}
				w.WriteEvent(e)
			case 'l', 'L': // look
				w.Ctl("clean")
				c <- string(e.Text)
			}
		}
		w.CloseFiles()
		close(c)
	}()
	return c
}
示例#7
0
文件: guru.go 项目: davidrjenni/Guru
func selection(win *acme.Win, body []byte) (int, int, error) {
	if _, _, err := win.ReadAddr(); err != nil {
		return 0, 0, err
	}
	if err := win.Ctl("addr=dot"); err != nil {
		return 0, 0, err
	}
	q0, q1, err := win.ReadAddr()
	if err != nil {
		return 0, 0, err
	}
	off0, err := byteOff(q0, bytes.NewReader(body))
	if err != nil {
		return 0, 0, err
	}
	off1, err := byteOff(q1, bytes.NewReader(body))
	if err != nil {
		return 0, 0, err
	}
	return off0, off1, nil
}
示例#8
0
文件: main.go 项目: uluyol/tools
func showAddr(win *acme.Win, q0, q1 int) error {
	if err := win.Addr("#%d,#%d", q0, q1); err != nil {
		return err
	}
	return win.Ctl("dot=addr\nshow\n")
}