コード例 #1
0
ファイル: client.go プロジェクト: uvelichitel/compl
func cmd_auto_complete(c *rpc.Client) {
	var env gocode_env
	env.get()
	var args, reply int
	var err error
	args = 0
	err = c.Call("RPC.RPC_setid", &args, &reply)
	compl_id = reply
	compl_win, err = acme.Open(compl_id, nil)
	if err != nil {
		compl_win, _ = acme.New()
		args = compl_win.GetId()
		err = c.Call("RPC.RPC_setid", &args, &reply)
	}
	//for acme

	var src []byte
	var searchpos int
	var fname string

	if afile, err = acmeCurrentFile(); err != nil {
		fmt.Printf("%v", err)
	}
	fname, src, searchpos = afile.name, afile.body, afile.offset
	compl_win.Name("%v+completions", fname)
	compl_win.Addr(",")
	compl_win.Write("data", nil)
	//for acme

	write_candidates(client_auto_complete(c, src, fname, searchpos, env))
}
コード例 #2
0
ファイル: client.go プロジェクト: uvelichitel/compl
func cmd_cursor_type_pkg(c *rpc.Client) {
	var args, reply int
	var err error
	args = 0
	err = c.Call("RPC.RPC_setid", &args, &reply)
	compl_id = reply
	compl_win, err = acme.Open(compl_id, nil)
	if err != nil {
		compl_win, _ = acme.New()
		args = compl_win.GetId()
		err = c.Call("RPC.RPC_setid", &args, &reply)
	}
	//for acme

	var src []byte
	var searchpos int
	var fname string

	if afile, err = acmeCurrentFile(); err != nil {
		fmt.Printf("%v", err)
	}
	fname, src, searchpos = afile.name, afile.body, afile.offset
	//for acme
	typ, pkg := client_cursor_type_pkg(c, src, fname, searchpos)
	fmt.Printf("%s,,%s\n", typ, pkg)
}
コード例 #3
0
ファイル: main.go プロジェクト: Rudloff/platform
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
}
コード例 #4
0
ファイル: Dict.go プロジェクト: postfix/GoProxyHunt
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)
	}
}
コード例 #5
0
ファイル: winmux.go プロジェクト: rjkroege/winmux
func main() {
	fmt.Print("hello from winmux\n")

	//	log.Print("hello!")

	// take a window id from the command line
	// I suppose it could come from the environment too

	//	log.Print(os.Args[0])

	var q Q
	var err error

	// Actually make this correspond to the real syntax.
	var window_id = flag.Int("id", -1, "Acme window id")
	var window_name = flag.String("name", "", "Acme window name")
	flag.Parse()

	cmd := "/usr/local/plan9/bin/rc"
	// cmd := "/usr/local/plan9/bin/cat"	// Safer for now.
	if args := flag.Args(); len(args) == 1 {
		cmd = args[0]
	} else if len(args) > 1 {
		log.Fatal(usage)
	}

	// TODO(rjkroege): look up a window by name if an argument is provided
	// and connect to it.
	// Hunt down an acme window
	log.Printf("asked for window %s\n", *window_name)
	if *window_id == -1 {
		q.Win, err = acme.New()
	} /* else open the named window. */
	if err != nil {
		log.Fatal("can't open the window? ", err.Error())
	}

	q.Win.Name("winmux-%s", cmd)
	q.Win.Fprintf("body", "hi rob\n")

	// TODO(rjkroege): start the function that receives from the pty and inserts into acme
	c := exec.Command(cmd)
	f, err := pty.Start(c)
	if err != nil {
		log.Fatalf("failed to start pty up: %s", err.Error())
	}

	echo := ttypair.Makecho()
	q.Tty = ttypair.New(f, echo)

	// A goroutine to read the output
	go childtoacme(&q, f, echo)

	// Read from the acme and send to child. (Rename?)
	acmetowin(&q, f, echo)

	q.Win.CloseFiles()
	fmt.Print("bye\n")
}
コード例 #6
0
ファイル: win.go プロジェクト: vivounicorn/eaburns.todo
// New returns a new acme window.
func New(fmt string, args ...interface{}) (*Win, error) {
	w, err := acme.New()
	if err != nil {
		return nil, err
	}
	w.Name(fmt, args...)
	return &Win{
		Win:  w,
		Data: winData{w},
	}, nil
}
コード例 #7
0
ファイル: Dict.go プロジェクト: postfix/GoProxyHunt
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)
	}
}
コード例 #8
0
ファイル: acme.go プロジェクト: amrhassan/rsc
func (w *awin) new(title string) *awin {
	all.Lock()
	defer all.Unlock()
	all.numwin++
	if all.m == nil {
		all.m = make(map[string]*awin)
	}
	w1 := new(awin)
	w1.title = title
	var err error
	w1.Win, err = acme.New()
	if err != nil {
		log.Printf("creating acme window: %v", err)
		time.Sleep(10 * time.Millisecond)
		w1.Win, err = acme.New()
		if err != nil {
			log.Fatalf("creating acme window again: %v", err)
		}
	}
	w1.prefix = w.prefix
	w1.Name(w1.prefix + title)
	all.m[title] = w1
	return w1
}
コード例 #9
0
ファイル: main.go プロジェクト: rjkroege/wikitools
func (md *ExpandedArticle) Plumb() {
	win, err := acme.New()
	if err != nil {
		log.Fatal(err)
	}

	err = win.Name(md.Name)
	if err != nil {
		log.Fatal(err)
	}

	_, err = win.Write("body", md.buffy.Bytes())
	if err != nil {
		log.Fatal(err)
	}

	err = win.Fprintf("tag", "wikimake")
	if err != nil {
		log.Fatal(err)
	}
}
コード例 #10
0
ファイル: main.go プロジェクト: vivounicorn/eaburns
func main() {
	win, err := acme.New()
	if err != nil {
		panic(err)
	}

	go handleWinEvents(win)

	win.Name("+Cal")
	// Set Dump handling for the server window.
	if wd, err := os.Getwd(); err != nil {
		panic("Failed to set dump working directory: " + err.Error())
	} else {
		win.Ctl("dumpdir %s", wd)
		win.Ctl("dump %s", strings.Join(os.Args, " "))
	}
	showCal(win)

	fmt := " Font Mon Jan 2 15:04 2006"
	if len(os.Args) > 1 {
		fmt = " Font " + strings.Join(os.Args[1:], " ")
	}

	last := time.Now()
	for {
		now := time.Now()
		win.Ctl("cleartag")
		win.Write("tag", []byte(now.Format(fmt)))
		last = now

		if now.Month() != last.Month() {
			clear(win)
			showCal(win)
		}

		time.Sleep(time.Minute)
	}
}
コード例 #11
0
ファイル: main.go プロジェクト: vivounicorn/eaburns
func main() {
	flag.Parse()

	var err error
	win, err = acme.New()
	if err != nil {
		die(err)
	}

	if wd, err := os.Getwd(); err != nil {
		log.Println(err)
	} else {
		win.Ctl("dumpdir %s", wd)
	}
	win.Ctl("dump %s", strings.Join(os.Args, " "))

	abs, err := filepath.Abs(*path)
	if err != nil {
		die(err)
	}
	info, err := os.Stat(abs)
	if err != nil {
		die(err)
	}
	if info.IsDir() {
		abs += "/"
	}

	win.Name(abs + "+watch")
	win.Ctl("clean")
	win.Fprintf("tag", "Get ")

	run := make(chan runRequest)
	go events(run)
	go runner(run)
	watcher(*path, run)
}
コード例 #12
0
ファイル: main.go プロジェクト: Rudloff/platform
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")
					}
				}
			}
		}
	}
}
コード例 #13
0
ファイル: run.go プロジェクト: TheJumpCloud/rsc
func main() {
	log.SetFlags(0)
	log.SetPrefix("Run: ")

	file := os.Getenv("samfile")
	if file == "" {
		log.Fatal("not running in acme")
	}
	id, _ := strconv.Atoi(os.Getenv("winid"))
	wfile, err := acme.Open(id, nil)
	if err != nil {
		log.Fatal(err)
	}
	wfile.Ctl("put")
	wfile.CloseFiles()

	wname := "/go/run/" + strings.TrimSuffix(path.Base(file), ".go")
	windows, _ := acme.Windows()
	var w *acme.Win
	for _, info := range windows {
		if info.Name == wname {
			ww, err := acme.Open(info.ID, nil)
			if err != nil {
				log.Fatal(err)
			}
			ww.Addr(",")
			ww.Write("data", nil)
			w = ww
			break
		}
	}
	if w == nil {
		ww, err := acme.New()
		if err != nil {
			log.Fatal(err)
		}
		ww.Name(wname)
		w = ww
	}
	w.Ctl("clean")
	defer w.Ctl("clean")

	cmd := exec.Command("go", append([]string{"run", os.Getenv("samfile")}, os.Args[1:]...)...)
	cmd.Stdout = bodyWriter{w}
	cmd.Stderr = cmd.Stdout
	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	err = cmd.Start()
	if err != nil {
		w.Fprintf("body", "error starting command: %v\n", err)
		return
	}

	//stop := blinker(w)
	w.Ctl("cleartag")
	w.Fprintf("tag", " Kill Stack")

	done := make(chan bool)
	go func() {
		err := cmd.Wait()
		if err != nil {
			w.Fprintf("body", "\nerror running command: %v\n", err)
		}
		//stop <- true
		done <- true
	}()

	deleted := make(chan bool, 1)
	go func() {
		for e := range w.EventChan() {
			if e.C2 == 'x' || e.C2 == 'X' {
				switch string(e.Text) {
				case "Del":
					select {
					case deleted <- true:
					default:
					}
					syscall.Kill(-cmd.Process.Pid, 2)
					continue
				case "Kill":
					syscall.Kill(-cmd.Process.Pid, 2)
					continue
				case "Stack":
					syscall.Kill(-cmd.Process.Pid, 3)
					continue
				}
				w.WriteEvent(e)
			}
		}
	}()

	<-done
	w.Ctl("cleartag")

	select {
	case <-deleted:
		w.Ctl("delete")
	default:
	}
}
コード例 #14
0
ファイル: main.go プロジェクト: vron/acme
func main() {
	flag.Parse()
	args = flag.Args()
	if len(args) < 1 {
		fmt.Println(`Watch current dir and run the given command when something
changes, thus need at least one argument`)
		os.Exit(0)
	}

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

	// Init new watcher
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}

	// Start listening for these events
	go func() {
		for {
			select {
			case _ = <-watcher.Event:
				needrun <- true
			case err := <-watcher.Error:
				log.Fatal("error:", err)
			}
		}
	}()
	var rset func(int, int, string)
	rset = func(curdepth, totdepth int, path string) {
		err = watcher.Watch(path)

		if err != nil {
			log.Fatal(err)
		}
		if curdepth < totdepth {
			curdepth++
			files, er := ioutil.ReadDir(path)
			if er != nil {
				log.Fatal(er)
			}
			for _, v := range files {
				if v.IsDir() {
					rset(curdepth, totdepth, path+"/"+v.Name())
				}
			}
		}
	}
	lvl := 0
	if *recursive {
		lvl = 2
	}
	rset(0, lvl, ".")

	// And now wait... ./watch go install
	select {}

	log.Println("I am dead now...")
}
コード例 #15
0
ファイル: main.go プロジェクト: 0x7cc/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)
	}
}