当前位置: 首页>>代码示例>>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;未经允许,请勿转载。