示例#1
0
文件: prompt.go 项目: pascience/foci
func newPrompts() AllPrompts {
	cycleConfig := prompt.CycleConfig{
		Grab:       true,
		CancelKey:  Config.CancelKey,
		ConfirmKey: Config.ConfirmKey,
	}
	selectConfig := prompt.SelectConfig{
		CancelKey:    Config.CancelKey,
		BackspaceKey: Config.BackspaceKey,
		ConfirmKey:   Config.ConfirmKey,
		TabKey:       Config.TabKey,
	}
	inputConfig := prompt.InputConfig{
		CancelKey:    Config.CancelKey,
		BackspaceKey: Config.BackspaceKey,
		ConfirmKey:   Config.ConfirmKey,
	}
	msgConfig := prompt.MessageConfig{
		CancelKey:  Config.CancelKey,
		ConfirmKey: Config.ConfirmKey,
	}
	ps := AllPrompts{
		Cycle:   prompt.NewCycle(X, Theme.Prompt.CycleTheme(), cycleConfig),
		Slct:    prompt.NewSelect(X, Theme.Prompt.SelectTheme(), selectConfig),
		Input:   prompt.NewInput(X, Theme.Prompt.InputTheme(), inputConfig),
		Message: prompt.NewMessage(X, Theme.Prompt.MessageTheme(), msgConfig),
	}
	ps.slctVisible = ps.Slct.AddGroup(ps.Slct.NewStaticGroup("Visible"))
	ps.slctHidden = ps.Slct.AddGroup(ps.Slct.NewStaticGroup("Hidden"))
	return ps
}
示例#2
0
文件: main.go 项目: pascience/foci
func main() {
	X, err := xgbutil.NewConn()
	fatal(err)

	keybind.Initialize(X)

	slct := prompt.NewSelect(X,
		prompt.DefaultSelectTheme, prompt.DefaultSelectConfig)

	// Create some artifical groups to use.
	artGroups := []prompt.SelectGroup{
		slct.NewStaticGroup("Group 1"),
		slct.NewStaticGroup("Group 2"),
		slct.NewStaticGroup("Group 3"),
		slct.NewStaticGroup("Group 4"),
		slct.NewStaticGroup("Group 5"),
	}

	// And now create some artificial items.
	items := []*item{
		newItem("andrew", 1), newItem("bruce", 2),
		newItem("kaitlyn", 3),
		newItem("cauchy", 4), newItem("plato", 1),
		newItem("platonic", 2),
		newItem("andrew gallant", 3),
		newItem("Andrew Gallant", 4), newItem("Andrew", 1),
		newItem("jim", 1), newItem("jimmy", 2),
		newItem("jimbo", 3),
	}

	groups := make([]*prompt.SelectGroupItem, len(artGroups))
	for i, artGroup := range artGroups {
		groups[i] = slct.AddGroup(artGroup)
	}
	for _, item := range items {
		item.promptItem = slct.AddChoice(item)
	}

	geom := headGeom(X)
	keybind.KeyPressFun(
		func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
			showGroups := newGroups(groups, items)
			slct.Show(geom, prompt.TabCompletePrefix, showGroups, nil)
		}).Connect(X, X.RootWin(), selectActivate, true)

	println("Loaded...")
	xevent.Main(X)
}