Skip to content

Latest commit

History

96 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

startprompt

start build prompt commandline application

开始构建提示符命令行应用

复刻划掉参考 python-prompt-toolkit

支持 Linux MacOS

hello world

CommandLine

package main
/*读取用户输入并将其打印出来*/import (
"fmt""github.com/yetsing/startprompt"
)
funcmain() {
c, err:=startprompt.NewCommandLine(nil)
iferr!=nil {
fmt.Printf("failed to startprompt.NewCommandLine: %v\n", err)
return
}
line, err:=c.ReadInput()
iferr!=nil {
fmt.Printf("ReadInput error: %v\n", err)
}
fmt.Println("echo:", line)
}

TCommandLine

package main
/*helloworld 例子,读取用户输入并将其打印出来*/import (
"fmt""github.com/yetsing/startprompt"
)
funcmain() {
c, err:=startprompt.NewTCommandLine(nil)
iferr!=nil {
fmt.Printf("failed to startprompt.NewTCommandLine: %v\n", err)
return
}
deferc.Close()
c.Println("Type some text. Press Enter confirm or Ctrl-D exit")
line, err:=c.ReadInput()
iferr!=nil {
return
}
c.Println("echo:", line)
}

实现特性

  • 支持常用快捷键操作,可看 keybinding
  • 支持输入历史(提供内存和文件两种实现)
  • 支持语法高亮(通过自定义分词器实现)
  • 支持鼠标操作,可看 mouse (TCommandLine 支持)

有两个实现 CommandLineTCommandLine这两个在细节行为上有差异TCommandLine 基于 tcell 实现,增加鼠标支持

更多例子

examples 文件夹有一些简单的例子,其中以 t 开头的是使用 TCommandLine 的例子。

开启 Debug 日志

日志内容会输出到当前目录下的 startprompt.log 文件中

c, err:=startprompt.NewTCommandLine(&startprompt.CommandLineOption{
EnableDebug: true,
})

参考

python-prompt-toolkit

pygments

词法分析主要参考下面

Let's Build A Simple Interpreter

《用Go语言自制解释器》

About

start build prompt commandline application like python-prompt-toolkit

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages