本文整理汇总了Golang中github.com/sbinet/liner.State类的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: confirm
func confirm(term *liner.State, msg string) bool {
confirm, _ := term.Prompt(msg + ", Are you sure? (Y/N) > ")
if confirm == "Y" || confirm == "y" {
return true
}
return false
}
示例2: promptLoop
func promptLoop(quit chan bool, state *liner.State) {
for {
cmd, err := state.Prompt(" >>> ")
state.AppendHistory(cmd)
if err != nil {
fmt.Println()
log.Println("ERROR:", err)
quit <- true
return
}
if cmd == "exit" {
quit <- true
return
}
}
}
示例3: signalCatcher
/**
* Attempt to clean up after ctrl-C otherwise
* terminal is left in bad shape
*/
func signalCatcher(liner *liner.State) {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT)
<-ch
liner.Close()
os.Exit(0)
}
示例4: ReadHistoryFromFile
func ReadHistoryFromFile(liner *liner.State, path string) (int, string) {
var err error
f, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
f, err = os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return errors.FILE_OPEN, err.Error()
}
} else {
return errors.FILE_OPEN, err.Error()
}
}
defer f.Close()
reader := bufio.NewReader(f)
_, err = liner.ReadHistory(reader)
if err != nil {
return errors.READ_FILE, err.Error()
}
return 0, ""
}
示例5: UpdateHistory
func UpdateHistory(liner *liner.State, dir, line string) (int, string) {
liner.AppendHistory(line)
if dir != "" {
err_code, err_str := WriteHistoryToFile(liner, dir+"/.cbq_history")
if err_code != 0 {
return err_code, err_str
}
}
return 0, ""
}
示例6: ReadHistoryFromFile
func ReadHistoryFromFile(liner *liner.State, path string) {
f, err := os.Open(path)
if err != nil {
return
}
defer f.Close()
reader := bufio.NewReader(f)
liner.ReadHistory(reader)
}
示例7: ReadHistoryFromFile
func ReadHistoryFromFile(liner *liner.State, path string) (int, string) {
var err error
f, err := os.Open(path)
if err != nil {
return errors.FILE_OPEN, err.Error()
}
defer f.Close()
reader := bufio.NewReader(f)
_, err = liner.ReadHistory(reader)
if err != nil {
return errors.READ_FILE, err.Error()
}
return 0, ""
}
示例8: WriteHistoryToFile
func WriteHistoryToFile(liner *liner.State, path string) {
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return
}
defer f.Close()
writer := bufio.NewWriter(f)
_, err = liner.WriteHistory(writer)
if err != nil {
log.Printf("Error updating .tuq_history file: %v", err)
} else {
writer.Flush()
}
}
示例9: WriteHistoryToFile
func WriteHistoryToFile(liner *liner.State, path string) (int, string) {
var err error
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return errors.FILE_OPEN, err.Error()
}
defer f.Close()
writer := bufio.NewWriter(f)
_, err = liner.WriteHistory(writer)
if err != nil {
return errors.WRITE_FILE, err.Error()
} else {
err = writer.Flush()
if err != nil {
return errors.WRITER_OUTPUT, err.Error()
}
}
return 0, ""
}
示例10: UpdateHistory
func UpdateHistory(liner *liner.State, currentUser *user.User, line string) {
liner.AppendHistory(line)
if currentUser != nil && currentUser.HomeDir != "" {
WriteHistoryToFile(liner, currentUser.HomeDir+"/.tuq_history")
}
}
示例11: signalCatcher
/* If ^C is pressed then Abort the shell. This is
provided by the liner package.
*/
func signalCatcher(liner *liner.State) {
liner.SetCtrlCAborts(false)
}
示例12: UpdateHistory
func UpdateHistory(liner *liner.State, dir, line string) {
liner.AppendHistory(line)
if dir != "" {
WriteHistoryToFile(liner, dir+"/.cbq_history")
}
}