本文整理汇总了Golang中github.com/deweerdt/gocui.Gui.View方法的典型用法代码示例。如果您正苦于以下问题:Golang Gui.View方法的具体用法?Golang Gui.View怎么用?Golang Gui.View使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/deweerdt/gocui.Gui
的用法示例。
在下文中一共展示了Gui.View方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Draw
func (m *MessageAsText) Draw(amua *Amua, g *gocui.Gui) error {
v, err := g.View(MESSAGE_VIEW)
if err != nil {
return err
}
v.Clear()
v.Wrap = true
v.SetOrigin(0, 0)
_, err = io.Copy(v, m)
if err != nil {
return err
}
return nil
}
示例2: Draw
func (m *Message) Draw(amua *Amua, g *gocui.Gui) error {
v, err := g.View(MESSAGE_VIEW)
if err != nil {
return err
}
v.Clear()
v.Wrap = true
v.SetOrigin(0, 0)
colorstring.Fprintf(v, "[green]Subject: %s\n", m.Subject)
colorstring.Fprintf(v, "[red]From: %s\n", m.From)
colorstring.Fprintf(v, "[red]To: %s\n", m.To)
colorstring.Fprintf(v, "[green]Date: %s\n", m.Date.Format("Mon, 2 Jan 2006 15:04:05 -0700"))
fmt.Fprintf(v, "\n")
_, err = io.Copy(v, m)
if err != nil {
return err
}
return nil
}
示例3: switchToMode
func switchToMode(amua *Amua, g *gocui.Gui, mode Mode) error {
/* highlight off */
if amua.mode.IsHighlighted() {
v := modeToView(g, amua.mode)
v.Highlight = false
}
amua.prevMode = amua.mode
amua.mode = mode
curview := modeToViewStr(amua.mode)
var err error
switch amua.mode {
case MessageMode:
m := amua.curMessage()
m.Flags |= Seen
err = m.Draw(amua, g)
case MessageMimeMode:
m := amua.curMessage()
err = (*MessageAsMimeTree)(m).Draw(amua, g)
case MaildirMode:
v, _ := g.View(curview)
err = amua.curMaildirView.Draw(v)
case SendMailMode:
v, _ := g.View(curview)
err = amua.sendMailDraw(v)
case CommandNewMailMode:
tos := util.ConcatAddresses(amua.newMail.to)
amua.newMail.to = []*mail.Address{}
displayPromptWithPrefill(TO_PROMPT, tos)
case CommandMailModeTo:
displayPromptWithPrefill(TO_PROMPT, util.ConcatAddresses(amua.newMail.to))
case CommandMailModeCc:
displayPromptWithPrefill(CC_PROMPT, util.ConcatAddresses(amua.newMail.cc))
case CommandMailModeBcc:
displayPromptWithPrefill(BCC_PROMPT, util.ConcatAddresses(amua.newMail.bcc))
case CommandSearchMode:
displayPrompt(SEARCH_PROMPT)
}
if err != nil {
v, _ := g.View(curview)
if v != nil {
fmt.Fprintf(v, err.Error())
}
/* we printed the error, fallback */
}
_, err = g.SetViewOnTop(curview)
if err != nil {
return err
}
err = g.SetCurrentView(curview)
if err != nil {
return err
}
/* highlight back */
if amua.mode.IsHighlighted() {
v := modeToView(g, amua.mode)
v.Highlight = true
}
return nil
}
示例4: drawSlider
func drawSlider(amua *Amua, g *gocui.Gui) {
v, err := g.View(SLIDER_VIEW)
if err != nil {
return
}
v.Clear()
_, h := v.Size()
sliderH := 1
whites := h - 1
if len(amua.curMaildirView.md.messages) > 0 {
sliderH = h * h / len(amua.curMaildirView.md.messages)
whites = amua.curMaildirView.curTop * h / len(amua.curMaildirView.md.messages)
}
if sliderH <= 0 {
sliderH = 1
}
for i := 0; i < whites; i++ {
fmt.Fprintln(v, " ")
}
for i := 0; i < sliderH; i++ {
fmt.Fprintln(v, "\u2588")
}
}
示例5: keybindings
func keybindings(amua *Amua, g *gocui.Gui) error {
switchToModeInt := func(mode Mode) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
return switchToMode(amua, g, mode)
}
}
maildirMove := func(dy int) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
amua.curMaildirView.scroll(v, dy)
drawSlider(amua, g)
return nil
}
}
maildirAllDown := func() func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
dy := len(amua.curMaildirView.md.messages) - amua.curMaildirView.cur - 1
amua.curMaildirView.scroll(v, dy)
drawSlider(amua, g)
return nil
}
}
messageModeToggle := func(g *gocui.Gui, v *gocui.View) error {
switch amua.mode {
case MessageMode:
switchToMode(amua, g, MessageMimeMode)
case MessageMimeMode:
switchToMode(amua, g, MessageMode)
}
return nil
}
search := func(forward bool) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
setStatus("Looking for: " + amua.searchPattern + " in " + amua.curMaildirView.md.path)
found := false
direction := 1
if forward == false {
direction = -1
}
for i := 0; i < len(amua.curMaildirView.md.messages); i++ {
idx := ((direction * i) + amua.curMaildirView.cur + direction) % len(amua.curMaildirView.md.messages)
if idx < 0 {
idx = len(amua.curMaildirView.md.messages) + idx
}
if idx < 0 {
panic(idx)
}
m := amua.getMessage(idx)
if strings.Contains(m.Subject, amua.searchPattern) {
setStatus("Found: " + amua.searchPattern + " in " + amua.curMaildirView.md.path)
found = true
amua.curMaildirView.curTop = idx
amua.curMaildirView.cur = idx
break
}
}
if found {
mv, err := g.View(MAILDIR_VIEW)
if err != nil {
return err
}
err = amua.curMaildirView.Draw(mv)
if err != nil {
setStatus(err.Error())
}
} else {
setStatus(amua.searchPattern + " not found")
}
return nil
}
}
enterSearch := func(forward bool) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
v.Rewind()
spbuf, err := ioutil.ReadAll(v)
if err != nil {
return err
}
prompt := amua.prompt
amua.searchPattern = strings.TrimSpace(string(spbuf[len(prompt):]))
switchToMode(amua, g, MaildirMode)
search(forward)(g, v)
return nil
}
}
cancelSearch := func(g *gocui.Gui, v *gocui.View) error {
setStatus("")
return switchToMode(amua, g, amua.prevMode)
}
setFlag := func(flag MessageFlags) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
m := amua.curMessage()
m.Flags |= flag
amua.curMaildirView.Draw(v)
return nil
}
}
unsetFlag := func(flag MessageFlags) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
m := amua.curMessage()
//.........这里部分代码省略.........
示例6: modeToView
func modeToView(g *gocui.Gui, mode Mode) *gocui.View {
v, _ := g.View(modeToViewStr(mode))
return v
}