本文整理汇总了Golang中github.com/kisielk/vigo/editor.Editor.Quit方法的典型用法代码示例。如果您正苦于以下问题:Golang Editor.Quit方法的具体用法?Golang Editor.Quit怎么用?Golang Editor.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kisielk/vigo/editor.Editor
的用法示例。
在下文中一共展示了Editor.Quit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: execCommand
// Interpret command and apply changes to editor.
func execCommand(e *editor.Editor, command string) error {
fields := strings.Fields(command)
// prevent a crash if no commands are given
if len(fields) == 0 {
return nil
}
cmd, args := fields[0], fields[1:]
switch cmd {
case "q":
// TODO if more than one split, close active one only.
e.Quit()
case "w":
b := e.ActiveView().Buffer()
switch len(args) {
case 0:
b.Save()
case 1:
b.SaveAs(args[0])
default:
return fmt.Errorf("too many arguments to :w")
}
case "e":
var filename string
switch len(args) {
case 0:
return fmt.Errorf("TODO re-read current file, if any")
case 1:
filename = args[0]
default:
return fmt.Errorf("too many arguments for :e")
}
// TODO: Don't replace the current buffer if it has been modified
buffer, err := e.NewBufferFromFile(filename)
if err != nil {
return err
}
e.ActiveView().Attach(buffer)
case "sp", "split":
e.SplitHorizontally()
// TODO file argument | shell command argument
case "vsp", "vsplit":
e.SplitVertically()
case "nohls":
e.ActiveView().ShowHighlights(false)
case "hls":
e.ActiveView().ShowHighlights(true)
}
if lineNum, err := strconv.Atoi(cmd); err == nil {
// cmd is a number, we should move to that line
e.ActiveView().MoveCursorToLine(lineNum)
}
return nil
}