Coder Social home page Coder Social logo

startprompt's Introduction

startprompt

start build prompt commandline application

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

复刻划掉参考 python-prompt-toolkit

支持 Linux MacOS

hello world

CommandLine

package main

/*
读取用户输入并将其打印出来
*/

import (
	"fmt"

	"github.com/yetsing/startprompt"
)

func main() {
	c, err := startprompt.NewCommandLine(nil)
	if err != nil {
		fmt.Printf("failed to startprompt.NewCommandLine: %v\n", err)
		return
	}
	line, err := c.ReadInput()
	if err != nil {
		fmt.Printf("ReadInput error: %v\n", err)
	}
	fmt.Println("echo:", line)
}

TCommandLine

package main

/*
helloworld 例子,读取用户输入并将其打印出来
*/

import (
	"fmt"

	"github.com/yetsing/startprompt"
)

func main() {
	c, err := startprompt.NewTCommandLine(nil)
	if err != nil {
		fmt.Printf("failed to startprompt.NewTCommandLine: %v\n", err)
		return
	}
	defer c.Close()
	c.Println("Type some text. Press Enter confirm or Ctrl-D exit")
	line, err := c.ReadInput()
	if err != nil {
		return
	}
	c.Println("echo:", line)
}

实现特性

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

有两个实现 CommandLine TCommandLine这两个在细节行为上有差异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语言自制解释器》

startprompt's People

Contributors

yetsing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.