Esempio n. 1
0
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
}
Esempio n. 2
0
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
		}
	}
}
Esempio n. 3
0
/**
 *  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)
}
Esempio n. 4
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, ""
}
Esempio n. 5
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, ""
}
Esempio n. 6
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)
}
Esempio n. 7
0
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, ""
}
Esempio n. 8
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()
	}

}
Esempio n. 9
0
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, ""

}
Esempio n. 10
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")
	}
}
Esempio n. 11
0
/* If ^C is pressed then Abort the shell. This is
   provided by the liner package.
*/
func signalCatcher(liner *liner.State) {
	liner.SetCtrlCAborts(false)

}
Esempio n. 12
0
func UpdateHistory(liner *liner.State, dir, line string) {
	liner.AppendHistory(line)
	if dir != "" {
		WriteHistoryToFile(liner, dir+"/.cbq_history")
	}
}