當前位置: 首頁>>代碼示例>>Golang>>正文


Golang liner.State類代碼示例

本文整理匯總了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
}
開發者ID:ClarityServices,項目名稱:skynet2,代碼行數:8,代碼來源:cli.go

示例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
		}
	}
}
開發者ID:yeerkkiller1,項目名稱:buildblast,代碼行數:16,代碼來源:prompt.go

示例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)
}
開發者ID:bcui6611,項目名稱:go-unql-couchbase,代碼行數:11,代碼來源:main.go

示例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, ""
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:25,代碼來源:history.go

示例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, ""
}
開發者ID:couchbaselabs,項目名稱:go_cbq,代碼行數:10,代碼來源:history.go

示例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)
}
開發者ID:steveyen,項目名稱:tuqqedin,代碼行數:12,代碼來源:history.go

示例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, ""
}
開發者ID:couchbaselabs,項目名稱:go_cbq,代碼行數:17,代碼來源:history.go

示例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()
	}

}
開發者ID:steveyen,項目名稱:tuqqedin,代碼行數:18,代碼來源:history.go

示例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, ""

}
開發者ID:couchbaselabs,項目名稱:go_cbq,代碼行數:23,代碼來源:history.go

示例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")
	}
}
開發者ID:steveyen,項目名稱:tuqqedin,代碼行數:6,代碼來源:history.go

示例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)

}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:7,代碼來源:interactive.go

示例12: UpdateHistory

func UpdateHistory(liner *liner.State, dir, line string) {
	liner.AppendHistory(line)
	if dir != "" {
		WriteHistoryToFile(liner, dir+"/.cbq_history")
	}
}
開發者ID:amarantha-k,項目名稱:query,代碼行數:6,代碼來源:history.go


注:本文中的github.com/sbinet/liner.State類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。