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 }
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 } } }
/** * 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) }
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, "" }
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, "" }
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) }
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, "" }
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() } }
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, "" }
func UpdateHistory(liner *liner.State, currentUser *user.User, line string) { liner.AppendHistory(line) if currentUser != nil && currentUser.HomeDir != "" { WriteHistoryToFile(liner, currentUser.HomeDir+"/.tuq_history") } }
/* If ^C is pressed then Abort the shell. This is provided by the liner package. */ func signalCatcher(liner *liner.State) { liner.SetCtrlCAborts(false) }
func UpdateHistory(liner *liner.State, dir, line string) { liner.AppendHistory(line) if dir != "" { WriteHistoryToFile(liner, dir+"/.cbq_history") } }