當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Gui.SetKeybinding方法代碼示例

本文整理匯總了Golang中github.com/deweerdt/gocui.Gui.SetKeybinding方法的典型用法代碼示例。如果您正苦於以下問題:Golang Gui.SetKeybinding方法的具體用法?Golang Gui.SetKeybinding怎麽用?Golang Gui.SetKeybinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/deweerdt/gocui.Gui的用法示例。


在下文中一共展示了Gui.SetKeybinding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: keybindings


//.........這裏部分代碼省略.........
	}
	replyMessage := reply(false)
	groupReplyMessage := reply(true)
	pipeMessage := func(g *gocui.Gui, v *gocui.View) error {
		m := amua.curMessage()
		cmd := exec.Command(amua.ExtEditor(), m.path)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		if err := cmd.Run(); err != nil {
			log.Fatal(err)
		}
		setStatus("")
		switchToMode(amua, g, MaildirMode)
		err := g.Sync()
		if err != nil {
			log.Fatal(err)
		}
		/* exec a command, pipe the message there */
		return nil
	}
	type keybinding struct {
		key interface{}
		fn  gocui.KeybindingHandler
		mod bool
	}
	bindings := map[string][]keybinding{
		MAILDIR_VIEW: {
			{gocui.KeyEnter, switchToModeInt(MessageMode), false},
			{'c', switchToModeInt(KnownMaildirsMode), false},
			{'v', switchToModeInt(MessageMimeMode), false},
			{'q', quit, false},
			{'d', deleteMessage, false},
			{'u', undeleteMessage, false},
			{'G', maildirAllDown(), false},
			{'k', maildirMove(-1), false},
			{gocui.KeyArrowUp, maildirMove(-1), false},
			{'j', maildirMove(1), false},
			{'n', search(true), false},
			{'N', search(false), false},
			{'$', syncMaildir, false},
			{'F', toggleFlagged, false},
			{gocui.KeyCtrlR, readMessage, false},
			{gocui.KeyCtrlN, unreadMessage, false},
			{gocui.KeyArrowDown, maildirMove(1), false},
			{gocui.KeyCtrlF, maildirMove(10), false},
			{gocui.KeyPgdn, maildirMove(10), false},
			{gocui.KeyCtrlB, maildirMove(-10), false},
			{gocui.KeyPgup, maildirMove(-10), false},
			{'/', switchToModeInt(CommandSearchMode), false},
			{'m', switchToModeInt(CommandNewMailMode), false},
			{'r', replyMessage, false},
			{'g', groupReplyMessage, false},
			{'|', pipeMessage, false},
		},
		MESSAGE_VIEW: {
			{'q', switchToModeInt(MaildirMode), false},
			{'v', messageModeToggle, false},
			{gocui.KeyPgup, scrollMessageView(-10), false},
			{gocui.KeyPgdn, scrollMessageView(10), false},
			{gocui.KeySpace, scrollMessageView(10), false},
			{'j', scrollMessageView(1), false},
			{'k', scrollMessageView(-1), false},
			{'r', replyMessage, false},
			{'g', groupReplyMessage, false},
			{'|', pipeMessage, false},
		},
		SEND_MAIL_VIEW: {
			{'q', switchToModeInt(MaildirMode), false},
			{'t', switchToModeInt(CommandMailModeTo), false},
			{'c', switchToModeInt(CommandMailModeCc), false},
			{'b', switchToModeInt(CommandMailModeBcc), false},
			{'y', sendMail, false},
			{gocui.KeyCtrlG, switchToModeInt(MaildirMode), false},
		},
		STATUS_VIEW: {
			{gocui.KeyEnter, commandEnter, false},
			{gocui.KeyCtrlG, cancelSearch, false},
		},
		SIDE_VIEW: {
			{'j', scrollSideView(amua, 1), false},
			{gocui.KeyArrowDown, scrollSideView(amua, 1), false},
			{'k', scrollSideView(amua, -1), false},
			{gocui.KeyArrowUp, scrollSideView(amua, 1), false},
			{gocui.KeyEnter, selectNewMaildir(amua), false},
		},
		"": {
			{gocui.KeyCtrlC, quit, false},
		},
	}

	for vn, binds := range bindings {
		for _, b := range binds {
			err := g.SetKeybinding(vn, b.key, gocui.ModNone, b.fn)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
開發者ID:deweerdt,項目名稱:amua,代碼行數:101,代碼來源:amua.go


注:本文中的github.com/deweerdt/gocui.Gui.SetKeybinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。