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) }
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") }
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() }
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() }
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 }
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 }
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 }
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") }