Ejemplo n.º 1
0
func showContact(you string) *Window {
	w := lookContact(you)
	if w != nil {
		w.Ctl("show\n")
		return w
	}

	ww, err := acme.New()
	if err != nil {
		log.Fatal(err)
	}

	name := "Chat/" + acct.Nick + "/" + you
	ww.Name(name)
	w = &Window{Win: ww, typ: "chat", name: name, remote: you}
	w.Fprintf("body", "\n")
	w.Addr("#1")
	w.OpenEvent()
	w.Fprintf("ctl", "cleartag\n")
	w.Fprintf("tag", " Ack")
	if p := cachedPresence(you); p != nil {
		w.status(p)
	}
	active[name] = w
	go w.readAcme()
	return w
}
Ejemplo n.º 2
0
Archivo: win.go Proyecto: aoeu/acme
func newWin(target string) *win {
	aw, err := acme.New()
	if err != nil {
		panic("Failed to create window: " + err.Error())
	}
	name := "/irc/" + server
	if target != "" {
		name += "/" + target
	}
	aw.Name(name)
	aw.Ctl("clean")
	aw.Write("body", []byte(prompt))
	if len(target) > 0 && target[0] == '#' {
		aw.Fprintf("tag", "Who ")
	}

	w := &win{
		Win:      aw,
		eAddr:    utf8.RuneCountInString(prompt),
		target:   target,
		users:    make(map[string]*user),
		lastTime: time.Now(),
	}
	go func() {
		for ev := range aw.EventChan() {
			winEvents <- winEvent{false, w, ev}
		}
	}()
	return w
}
Ejemplo n.º 3
0
Archivo: Dict.go Proyecto: rjkroege/go
func main() {
	w, err := acme.New()
	if err != nil {
		log.Fatal(err)
	}
	w.Name("/dict/")
	d, err = dict.Dial("tcp", "216.93.242.2:dict")
	if err != nil {
		w.Write("body", []byte(err.Error()))
		return
	}
	w.Ctl("clean")
	go func() {
		dicts, err = d.Dicts()
		if err != nil {
			w.Write("body", []byte(err.Error()))
			return
		}
		for _, dict := range dicts {
			w.Fprintf("body", "%s\t%s\n", dict.Name, dict.Desc)
		}
	}()
	for word := range events(w) {
		go lookup(word)
	}
}
Ejemplo n.º 4
0
func newWin(watchPath string) (ui, error) {
	win, err := acme.New()
	if err != nil {
		return nil, err
	}

	wd, err := os.Getwd()
	if err != nil {
		log.Println("Failed to get the current directory, not setting dumpdir:", err)
	} else if err := win.Ctl("dumpdir %s", wd); err != nil {
		log.Println("Failed to set the dumpdir:", err)
	}

	if err := win.Ctl("dump %s", strings.Join(os.Args, " ")); err != nil {
		log.Println("Failed to set the dump command:", err)
	}

	abs, err := filepath.Abs(watchPath)
	if err != nil {
		return nil, errors.New("Failed getting the absolute path of " + watchPath + ": " + err.Error())
	}
	if err := win.Name(abs + "/+watch"); err != nil {
		return nil, errors.New("Failed to set the win name: " + err.Error())
	}

	win.Ctl("clean")
	win.Fprintf("tag", "Get ")

	rerun := make(chan struct{})
	go events(win, rerun)

	return winUI{win, rerun}, nil
}
Ejemplo n.º 5
0
Archivo: Dict.go Proyecto: rjkroege/go
func wordwin(def *dict.Defn) {
	w, err := acme.New()
	if err != nil {
		log.Fatal(err)
	}
	w.Name("/dict/%s/%s", def.Dict.Name, def.Word)
	w.Write("body", def.Text)
	w.Ctl("clean")
	for word := range events(w) {
		go lookup(word)
	}
}
Ejemplo n.º 6
0
Archivo: main.go Proyecto: aoeu/acme
func open(filepath string) (w *acme.Win, err error) {
	if id, ok := existingWindows[filepath]; ok {
		if w, err = acme.Open(id, nil); err != nil {
			return w, err
		}
	} else if w, err = acme.New(); err == nil {
		w.Name(filepath)
		w.Write("tag", []byte("Put "))
		w.Ctl("get")
	}
	return w, err
}
Ejemplo n.º 7
0
Archivo: xplor.go Proyecto: edma2/xplor
func initWindow() error {
	var err error = nil
	w, err = acme.New()
	if err != nil {
		return err
	}

	title := "xplor-" + root
	w.Name(title)
	tag := "DotDot Win Xplor Hidden"
	w.Write("tag", []byte(tag))
	err = printDirContents(root, 0)
	return err
}
Ejemplo n.º 8
0
Archivo: main.go Proyecto: rsc/rsc
func main() {
	flag.Parse()
	args = flag.Args()

	var err error
	win, err = acme.New()
	if err != nil {
		log.Fatal(err)
	}
	pwd, _ := os.Getwd()
	win.Name(pwd + "/+watch")
	win.Ctl("clean")
	win.Fprintf("tag", "Get ")
	needrun <- true
	go events()
	go runner()

	kq.fd, err = syscall.Kqueue()
	if err != nil {
		log.Fatal(err)
	}
	kq.m = make(map[string]*os.File)
	kq.name = make(map[int]string)

	dir, err := os.Open(".")
	if err != nil {
		log.Fatal(err)
	}
	kq.dir = dir
	kadd(int(dir.Fd()))
	readdir := true

	for {
		if readdir {
			kq.dir.Seek(0, 0)
			names, err := kq.dir.Readdirnames(-1)
			if err != nil {
				log.Fatalf("readdir: %v", err)
			}
			for _, name := range names {
				if kq.m[name] != nil {
					continue
				}
				f, err := os.Open(name)
				if err != nil {
					continue
				}
				kq.m[name] = f
				fd := int(f.Fd())
				kq.name[fd] = name
				kadd(fd)
			}
		}

		kbuf := make([]syscall.Kevent_t, 1)
		var n int
		for {
			n, err = syscall.Kevent(kq.fd, nil, kbuf[:1], nil)
			if err == syscall.EINTR {
				continue
			}
			break
		}
		if err != nil {
			log.Fatalf("kevent wait: %v", err)
		}
		ev := &kbuf[0]
		if n != 1 || int(ev.Filter) != syscall.EVFILT_VNODE {
			log.Fatal("kqueue phase error")
		}

		select {
		case needrun <- true:
		default:
		}

		fd := int(ev.Ident)
		readdir = fd == int(kq.dir.Fd())
		time.Sleep(100 * time.Millisecond)
		kadd(fd)
	}
}
Ejemplo n.º 9
0
func main() {
	flag.Usage = usage
	flag.Parse()

	acct = google.Acct(*acctName)

	aw, err := acme.New()
	if err != nil {
		log.Fatal(err)
	}
	aw.Name("Chat/" + acct.Nick + "/")

	client, err = xmpp.NewClient("talk.google.com:443", acct.Email, acct.Password)
	if err != nil {
		log.Fatal(err)
	}

	w := &Window{Win: aw, typ: "main", name: "Chat/" + acct.Nick + "/"}
	data, err := ioutil.ReadFile(google.Dir() + "/chat." + acct.Nick)
	if err != nil {
		log.Fatal(err)
	}
	if err == nil {
		w.Write("body", data)
	}
	mainWin = w
	active[w.name] = w
	go w.readAcme()
	client.Roster()
	setStatus(status)
	go w.readChat()
	lastActivity = time.Now()

	tick := time.Tick(0.5e9)
Loop:
	for len(active) > 0 {
		select {
		case w := <-acmeChan:
			if w == nil {
				// Sync with reader.
				continue
			}
			if w.err != nil {
				if active[w.name] == nil {
					continue
				}
				log.Fatal(w.err)
			}
			if *acmeDebug {
				fmt.Fprintf(os.Stderr, "%s %c%c %d,%d %q\n", w.name, w.C1, w.C2, w.Q0, w.Q1, w.Text)
			}
			if w.C1 == 'M' || w.C1 == 'K' {
				lastActivity = time.Now()
				if status != xmpp.Available {
					setStatus(xmpp.Available)
				}
			}
			if (w.C2 == 'x' || w.C2 == 'X') && string(w.Text) == "Del" {
				// TODO: Hangup connection for w.typ == "acct"?
				delete(active, w.name)
				w.Del(true)
				continue Loop
			}

			switch w.typ {
			case "main":
				switch w.C2 {
				case 'L': // Button 3 in body: load chat window for contact.
					w.expand()
					fallthrough
				case 'l': // Button 3 in tag
					arg := string(w.Text)
					showContact(arg)
					continue Loop
				}
			case "chat":
				if w.C1 == 'F' && w.C2 == 'I' {
					continue Loop
				}
				if w.C1 != 'M' && w.C1 != 'K' {
					break
				}
				if w.blinky {
					w.blinky = false
					w.Fprintf("ctl", "dirty\n")
				}
				switch w.C2 {
				case 'X', 'x':
					if string(w.Text) == "Ack" {
						w.Fprintf("ctl", "clean\n")
					}
				case 'I':
					w.sendMsg()
					continue Loop
				}
			}
			w.WriteEvent(w.Event)

		case msg := <-msgChan:
			w := msg.w
			if msg.err != nil {
				w.Fprintf("body", "ERROR: %s\n", msg.err)
				continue Loop
			}
			you := msg.Remote
			if i := strings.Index(you, "/"); i >= 0 {
				you = you[:i]
			}
			switch msg.Type {
			case "chat":
				w := showContact(you)
				text := strings.TrimSpace(msg.Text)
				if text == "" {
					// Probably a composing notification.
					continue
				}
				w.message("> %s\n", text)
				w.blinky = true
				w.dirty = true

			case "presence":
				pr := msg.Presence
				pr, new := savePresence(pr, you)
				if !new {
					continue
				}
				w := lookContact(you)
				if w != nil {
					w.status(pr)
				}
				mainStatus(pr, you)
			}

		case t := <-tick:
			switch status {
			case xmpp.Available:
				if t.Sub(lastActivity) > awayTime {
					setStatus(xmpp.Away)
				}
			case xmpp.Away:
				if t.Sub(lastActivity) > extendedAwayTime {
					setStatus(xmpp.ExtendedAway)
				}
			}
			for _, w := range active {
				if w.blinky {
					w.dirty = !w.dirty
					if w.dirty {
						w.Fprintf("ctl", "dirty\n")
					} else {
						w.Fprintf("ctl", "clean\n")
					}
				}
			}
		}
	}
}