本文整理汇总了Golang中github.com/peterh/liner.NewLiner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLiner函数的具体用法?Golang NewLiner怎么用?Golang NewLiner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLiner函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewICli
// NewICli creates a new ICli object and initializes it.
func NewICli(name, prompt, version, history, desc string) (*ICli, error) {
// Initialize the clif interfaces
//clif.DefaultStyles = clif.SunburnStyles
icli := &ICli{
Cli: clif.New(name, version, desc),
term: liner.NewLiner(),
prompt: prompt,
history: history,
optionSet: make(map[string]string),
}
f, err := os.Open(history)
if err != nil {
f, err = os.Create(history)
if err != nil {
return nil, fmt.Errorf("could not open or create history file %s :: %v",
history, err)
}
}
defer f.Close()
_, err = icli.term.ReadHistory(f)
if err != nil {
return nil, fmt.Errorf("could not read history file %s :: %v", history, err)
}
// set ctrl-c to abort the input.
icli.term.SetCtrlCAborts(true)
return icli, nil
}
开发者ID:zerostackinc,项目名称:icli,代码行数:30,代码来源:icli.go
示例2: NewShell
func NewShell() *Shell {
sh := &Shell{
shell: liner.NewLiner(),
prompt: "mbus> ",
hist: filepath.Join(".", ".fcs_lpc_motor_history"),
motor: m702.New("134.158.125.223:502"),
}
sh.shell.SetCtrlCAborts(true)
sh.shell.SetCompleter(func(line string) (c []string) {
for n := range sh.cmds {
if strings.HasPrefix(n, strings.ToLower(line)) {
c = append(c, n)
}
}
return
})
if f, err := os.Open(sh.hist); err == nil {
sh.shell.ReadHistory(f)
f.Close()
}
sh.cmds = map[string]shellCmd{
"dump": sh.cmdDump,
"get": sh.cmdGet,
"motor": sh.cmdMotor,
"quit": sh.cmdQuit,
"set": sh.cmdSet,
}
return sh
}
开发者ID:go-lsst,项目名称:fcs-lpc-motor,代码行数:32,代码来源:shell.go
示例3: New
func New(args []string) *cli {
if len(args) > 1 {
return nil
}
// We assume the terminal starts in cooked mode.
cooked, _ = liner.TerminalMode()
if cooked == nil {
return nil
}
i := &cli{liner.NewLiner()}
if history_path, err := task.GetHistoryFilePath(); err == nil {
if f, err := os.Open(history_path); err == nil {
i.ReadHistory(f)
f.Close()
}
}
uncooked, _ = liner.TerminalMode()
i.SetCtrlCAborts(true)
i.SetTabCompletionStyle(liner.TabPrints)
i.SetWordCompleter(complete)
return i
}
开发者ID:shaunstanislaus,项目名称:oh,代码行数:28,代码来源:ui.go
示例4: NewCLI
// NewCLI create CLI from Config.
func NewCLI(conf *Config) (*CLI, error) {
origin := "http://127.0.0.1"
if conf.Origin != "" {
origin = conf.Origin
}
conn, err := websocket.Dial(conf.URL, "", origin)
if err != nil {
return nil, err
}
template := EmptyTemplate
if _, err := os.Stat(conf.Template); err == nil {
template, err = NewTemplateFile(conf.Template)
if err != nil {
return nil, err
}
}
cli := &CLI{
conn,
liner.NewLiner(),
template,
conf.Debug,
}
cli.liner.SetCtrlCAborts(true)
cli.liner.SetCompleter(Completer(template))
return cli, nil
}
开发者ID:morikuni,项目名称:weso,代码行数:30,代码来源:cli.go
示例5: terminal
func terminal(path string) (*liner.State, error) {
term := liner.NewLiner()
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
<-c
err := persist(term, history)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to properly clean up terminal: %v\n", err)
os.Exit(1)
}
os.Exit(0)
}()
f, err := os.Open(path)
if err != nil {
return term, err
}
defer f.Close()
_, err = term.ReadHistory(f)
return term, err
}
开发者ID:dennwc,项目名称:cayley,代码行数:25,代码来源:repl.go
示例6: main
func main() {
flag.Parse()
line := liner.NewLiner()
line.SetCtrlCAborts(true)
defer line.Close()
for {
cmd, err := line.Prompt("> ")
if err == liner.ErrPromptAborted || err == io.EOF {
break
} else if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
args := shlex.Parse(cmd)
switch strings.ToLower(args[0]) {
case "search":
if err := search(args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
case "magnet":
if err := magnet(args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
}
}
}
开发者ID:vrischmann,项目名称:katcrawl,代码行数:30,代码来源:main.go
示例7: TestParseCommand_HistoryWithBlankCommand
func TestParseCommand_HistoryWithBlankCommand(t *testing.T) {
t.Parallel()
c := cli.CommandLine{Line: liner.NewLiner()}
defer c.Line.Close()
// append one entry to history
c.Line.AppendHistory("x")
tests := []struct {
cmd string
}{
{cmd: "history"},
{cmd: " history"},
{cmd: "history "},
{cmd: "History "},
{cmd: ""}, // shouldn't be persisted in history
{cmd: " "}, // shouldn't be persisted in history
}
// don't validate because blank commands are never executed
for _, test := range tests {
c.ParseCommand(test.cmd)
}
// buf shall not contain empty commands
var buf bytes.Buffer
c.Line.WriteHistory(&buf)
scanner := bufio.NewScanner(&buf)
for scanner.Scan() {
if scanner.Text() == "" || scanner.Text() == " " {
t.Fatal("Empty commands should not be persisted in history.")
}
}
}
开发者ID:ThiruKumar,项目名称:go_ws,代码行数:34,代码来源:cli_test.go
示例8: PromptConfirm
func PromptConfirm(prompt string) (bool, error) {
var (
input string
err error
)
prompt = prompt + " [y/N] "
if liner.TerminalSupported() {
lr := liner.NewLiner()
defer lr.Close()
input, err = lr.Prompt(prompt)
} else {
fmt.Print(prompt)
input, err = bufio.NewReader(os.Stdin).ReadString('\n')
fmt.Println()
}
if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" {
return true, nil
} else {
return false, nil
}
return false, err
}
开发者ID:ruflin,项目名称:go-ethereum,代码行数:25,代码来源:cmd.go
示例9: TestParseCommand_History
func TestParseCommand_History(t *testing.T) {
t.Parallel()
c := cli.CommandLine{Line: liner.NewLiner()}
defer c.Line.Close()
// append one entry to history
c.Line.AppendHistory("abc")
tests := []struct {
cmd string
}{
{cmd: "history"},
{cmd: " history"},
{cmd: "history "},
{cmd: "History "},
}
for _, test := range tests {
if err := c.ParseCommand(test.cmd); err != nil {
t.Fatalf(`Got error %v for command %q, expected nil.`, err, test.cmd)
}
}
// buf size should be at least 1
var buf bytes.Buffer
c.Line.WriteHistory(&buf)
if buf.Len() < 1 {
t.Fatal("History is borked")
}
}
开发者ID:bwolf,项目名称:influxdb,代码行数:30,代码来源:cli_test.go
示例10: New
func New(client service.Client) *Term {
return &Term{
prompt: "(dlv) ",
line: liner.NewLiner(),
client: client,
}
}
开发者ID:rsrsps,项目名称:delve,代码行数:7,代码来源:terminal.go
示例11: RunRepl
func RunRepl(store *Secstore) {
var sections []string
var line string
var err error
liner := liner.NewLiner()
defer liner.Close()
liner.SetCompleter(completer)
for {
line, err = liner.Prompt("> ")
if err != nil {
break
}
liner.AppendHistory(line)
sections = splitSections(line)
if len(sections) == 0 {
} else if strings.HasPrefix("quit", sections[0]) {
break
} else {
err = EvalCommand(store, sections)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
}
fmt.Fprintln(os.Stderr, "Exiting...")
}
开发者ID:mytchel,项目名称:pass,代码行数:34,代码来源:repl.go
示例12: commandLoop
func commandLoop() error {
in := liner.NewLiner()
defer in.Close()
in.SetCtrlCAborts(true)
f := NewForther()
in.SetCompleter(f.Complete)
for {
line, err := in.Prompt(f.Prompt())
if err == io.EOF || err == liner.ErrPromptAborted {
return nil
} else if err != nil {
return err
}
in.AppendHistory(line)
for i, cmd := range strings.Fields(line) {
if err := f.Process(cmd); err == io.EOF {
return nil
} else if err != nil {
fmt.Printf("Cannot run op %d (%q): %v\n", i+1, cmd, err)
break
}
}
}
}
开发者ID:augustoroman,项目名称:forther,代码行数:27,代码来源:main.go
示例13: runTerm
func runTerm(cmd *cobra.Command, args []string) {
if len(args) != 0 {
cmd.Usage()
return
}
db := makeSQLClient()
liner := liner.NewLiner()
defer func() {
_ = liner.Close()
}()
for {
l, err := liner.Prompt("> ")
if err != nil {
if err != io.EOF {
fmt.Fprintf(os.Stderr, "Input error: %s\n", err)
}
break
}
if len(l) == 0 {
continue
}
liner.AppendHistory(l)
if err := processOneLine(db, l); err != nil {
fmt.Printf("Error: %s\n", err)
}
}
}
开发者ID:shitfSign,项目名称:cockroach,代码行数:31,代码来源:sql.go
示例14: uiLoop
func uiLoop() {
line := liner.NewLiner()
line.SetCtrlCAborts(true)
fmt.Print("\n\nFlow v0.1.0\n\nPress Ctrl+C to exit\n\n")
for {
if input, err := line.Prompt("flow> "); err == nil {
inputs := strings.SplitN(input, " ", 2)
if len(inputs) > 1 {
cmd := inputs[0]
args := inputs[1]
checkCmd(cmd, args)
} else {
checkCmd(input, "")
}
} else if err == liner.ErrPromptAborted {
break
} else {
log.Printf("error de terminal: %s\n", err.Error())
}
}
line.Close()
out <- Event{
Type: UserExit,
Data: nil,
}
}
开发者ID:ArturoVM,项目名称:flow,代码行数:28,代码来源:ui.go
示例15: newLightweightJSRE
func newLightweightJSRE(libPath string, client comms.EthereumClient, interactive bool) *jsre {
js := &jsre{ps1: "> "}
js.wait = make(chan *big.Int)
js.client = client
js.ds = docserver.New("/")
// update state in separare forever blocks
js.re = re.New(libPath)
if err := js.apiBindings(js); err != nil {
utils.Fatalf("Unable to initialize console - %v", err)
}
if !liner.TerminalSupported() || !interactive {
js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
} else {
lr := liner.NewLiner()
js.withHistory(func(hist *os.File) { lr.ReadHistory(hist) })
lr.SetCtrlCAborts(true)
js.loadAutoCompletion()
lr.SetWordCompleter(apiWordCompleter)
lr.SetTabCompletionStyle(liner.TabPrints)
js.prompter = lr
js.atexit = func() {
js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
lr.Close()
close(js.wait)
}
}
return js
}
开发者ID:codeaudit,项目名称:shift,代码行数:30,代码来源:js.go
示例16: Init
// Initialise the shell
func (sh *Shell) Init(editorName string) error {
// create directory
dir := path.Join(os.TempDir(), "bshell")
if _, err := os.Stat(dir); err != nil {
if err = os.Mkdir(dir, 0777); err != nil {
return err
}
}
// create files
sh.editorFileBQL = path.Join(dir, "bql_editor.txt")
if err := sh.touchFile(sh.editorFileBQL); err != nil {
return err
}
sh.editorFileJS = path.Join(dir, "js_editor.js")
if err := sh.touchFile(sh.editorFileJS); err != nil {
return err
}
sh.historyFile = path.Join(dir, "history")
if err := sh.touchFile(sh.historyFile); err != nil {
return err
}
// create shell
sh.line = liner.NewLiner()
// setup history
if f, err := os.Open(sh.historyFile); err == nil {
sh.line.ReadHistory(f)
f.Close()
}
// set editor
sh.editorName = editorName
return nil
}
开发者ID:carriercomm,项目名称:bytengine,代码行数:36,代码来源:shell.go
示例17: New
func New(client service.Client, conf *config.Config) *Term {
return &Term{
prompt: "(dlv) ",
line: liner.NewLiner(),
client: client,
conf: conf,
}
}
开发者ID:jeffallen,项目名称:delve,代码行数:8,代码来源:terminal.go
示例18: main
func main() {
flag.Parse()
common.SetupLogger()
config := common.LoadConfig()
cassandraConfig := cassandra.CassandraMetricMetadataConfig{
Hosts: config.MetricMetadataConfig.Hosts,
Keyspace: config.MetricMetadataConfig.Keyspace,
}
apiInstance := common.NewMetricMetadataAPI(cassandraConfig)
ruleset, err := util.LoadRules(config.MetricMetadataConfig.ConversionRulesPath)
if err != nil {
//Blah
}
graphite := util.RuleBasedGraphiteConverter{Ruleset: ruleset}
config.Blueflood.GraphiteMetricConverter = &graphite
blueflood := blueflood.NewBlueflood(config.Blueflood)
l := liner.NewLiner()
defer l.Close()
for {
input, err := l.Prompt("> ")
if err != nil {
return
}
l.AppendHistory(input)
cmd, err := query.Parse(input)
if err != nil {
fmt.Println("parsing error", err.Error())
continue
}
n, ok := cmd.(query.Node)
if !ok {
fmt.Printf("error: %#v doesn't implement Node\n", cmd)
continue
}
fmt.Println(query.PrintNode(n))
result, err := cmd.Execute(query.ExecutionContext{TimeseriesStorageAPI: blueflood, MetricMetadataAPI: apiInstance, FetchLimit: 1000})
if err != nil {
fmt.Println("execution error:", err.Error())
continue
}
encoded, err := json.MarshalIndent(result, "", " ")
if err != nil {
fmt.Println("encoding error:", err.Error())
return
}
fmt.Println("success:")
fmt.Println(string(encoded))
}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:58,代码来源:query.go
示例19: New
// New returns a new Term.
func New(client service.Client, conf *config.Config) *Term {
return &Term{
prompt: "(dlv) ",
line: liner.NewLiner(),
client: client,
conf: conf,
dumb: strings.ToLower(os.Getenv("TERM")) == "dumb",
}
}
开发者ID:CedarLogic,项目名称:delve,代码行数:10,代码来源:terminal.go
示例20: main
func main() {
flag.Parse()
line := liner.NewLiner()
defer line.Close()
line.SetCtrlCAborts(true)
line.SetCompleter(lineCompleter)
if f, err := os.Open(historyf); err == nil {
line.ReadHistory(f)
f.Close()
}
client := Client{
vdirect: *vdirect,
gdirect: *gdirect,
gmode: *groupmode,
}
sm := "value"
if client.gmode {
sm = "group"
}
fmt.Printf("\u2728 oort-cli - in %s mode \u2728\n\n", sm)
for {
if cmd, err := line.Prompt(prompt); err == nil {
if client.gmode {
res, err := client.parseGroupCmd(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(res)
line.AppendHistory(cmd)
} else {
res, err := client.parseValueCmd(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(res)
line.AppendHistory(cmd)
}
} else if err == liner.ErrPromptAborted {
log.Print("Aborted")
return
} else {
log.Print("Error reading line: ", err)
return
}
if f, err := os.Create(historyf); err != nil {
log.Print("Error writing history file: ", err)
} else {
line.WriteHistory(f)
f.Close()
}
}
}
开发者ID:getcfs,项目名称:cfs-binary-release,代码行数:56,代码来源:main.go
注:本文中的github.com/peterh/liner.NewLiner函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论