Giter Club home page Giter Club logo

infinite's Introduction

infinite

gif

Help you to create interactive command line applications in Go.

Features

  • multi/single select
  • progress-bar group
  • spinner
  • confirm(input/selection)
  • input

Install

go get github.com/fzdwx/infinite@main

Examples

func main() {
	input := components.NewInput()
	input.Prompt = "Filtering: "
	input.PromptStyle = style.New().Bold().Italic().Fg(color.LightBlue)

	keymap := components.DefaultMultiKeyMap()
	keymap.Choice = key.NewBinding(
		key.WithKeys(tea.KeySpace.String()),
	)
	_, _ = inf.NewMultiSelect([]string{
		"a", "b", "c",
		"d", "e",
		"f",
		"g",
		"h",
	},
		multiselect.WithKeyMap(keymap),
		multiselect.WithHintSymbol("x"),
		multiselect.WithUnHintSymbol("√"),
		multiselect.WithPageSize(3),
		multiselect.WithFilterInput(input),
	).
		Display("select your items!")
}

More: https://github.com/fzdwx/infinite/tree/main/_examples

License

MIT

infinite's People

Contributors

fzdwx avatar qwe7002 avatar wangzhiy avatar whatwewant avatar zhyipeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

infinite's Issues

运行程序后方向键不可用

  • 在使用仓库提供的demo,执行前方向键可以正常使用,执行后方向键不可用,会被识别成[[A字符
    image

  • windows终端,winterm, cmd下都出现了这个问题。

  • 编译成可执行文件后在执行同样出现。

  • go version go1.18.1 windows/amd64

`input text` 新增特性

  • 新增默认值, 如果直接回车就使用该默认值, 通过改造 placeholder 这个字段, 这个名称可能也要变
  • 新增 required , 为 true 则必须要填写, 并附带一句错误信息, 为 false 则直接使用默认值
  • 新增 required msg, 当 requiredtrue 时有效

Win7 环境下无法使用

在win7环境下无法使用,控制台返回错误信息:?[?25l (就是这个报错信息,我也不知道为啥)
go版本1.20.6 和 1.19.11 都无法使用。

多选时增加方向键的一些控制

多选时:

  1. 如果将choice改为空格键,则tab和方向左右键会回到第一个选项,建议去掉
  • 增加pgup pgon键翻页功能 a0d6330
  • 增加左右键全选/取消功能 0acad7a

方向键的控制应该会依赖github.com/charmbracelet/bubbles

progress

  • progress
  • progress group
  • progress title,并且能动态刷新

请问后续会支持简单的ansi输出吗

先感谢作者的这个项目👍🏻

描述可能不太准,就是ansi输出一句话,带符号,比如下图,

fmt.Println("√ 服务器启动成功!") 如果 符号可以按照正常的ansi颜色输出就更好了,比如不用fmt,用包里的Print

image

`selection` 增加quit key

Quit 其实是用户第一需要的东西,在任何状态下都能够直接退出.

现在只能选择,没有退出的功能。

查看其他组件是否还有未提供quit key。

autocomplete 卡住了

环境: linux go 1.18
当输入的单词命中后会卡住,比如说options 中有java这一个单词,然后输入j就会卡住

demo

但是用windows的 1.18就没有问题。

增强style

  • 提供 Align 的快速方法
  • 提供 lipgloss.style 原有的功能

confirm 组件

example:

to day is sunday? (Y/N)

press key y or input yes

New Text 问题

NewText 如果不加 WithPure,则 Prompt 始终是 input,加了 WithPure 则默认样式没了

官网的例子:

package main

import (
	"fmt"
	inf "github.com/fzdwx/infinite"
	"github.com/fzdwx/infinite/components/input/text"
	"github.com/fzdwx/infinite/theme"
)

func main() {

	i := inf.NewText(
		text.WithPrompt("what's your name?"),
		text.WithPromptStyle(theme.DefaultTheme.PromptStyle),
		text.WithDefaultValue("fzdwx (maybe)"),
	)

	val, _ := i.Display()

	fmt.Printf("you input: %s\n", val)
}

然而 NewText:

func New(ops ...Option) *Text {
	inner := components.NewInput()

	i := &Text{inner: inner, startUp: components.NewStartUp(inner)}

	i.Apply(ops...)

	if !i.pure {
		i.inner.Prompt = "input" // 这里把 Prompt 覆盖了?不管 WithPrompt 设置了什么 都显示的 input!
		i.inner.FocusSymbol = theme.DefaultTheme.FocusSymbol
		i.inner.UnFocusSymbol = theme.DefaultTheme.UnFocusSymbol
		i.inner.FocusInterval = theme.DefaultTheme.FocusInterval
		i.inner.UnFocusInterval = theme.DefaultTheme.UnFocusInterval
		i.inner.FocusSymbolStyle = theme.DefaultTheme.FocusSymbolStyle
		i.inner.UnFocusSymbolStyle = theme.DefaultTheme.UnFocusSymbolStyle
		i.inner.FocusIntervalStyle = theme.DefaultTheme.FocusIntervalStyle
		i.inner.UnFocusIntervalStyle = theme.DefaultTheme.UnFocusIntervalStyle
	}

	return i
}

linux系统上,confirm 组件在Ctrl+C退出后,后续字符输入不可见

code:

package main

import (
	"fmt"

	inf "github.com/fzdwx/infinite"
	"github.com/fzdwx/infinite/components/input/confirm"
)

func main() {
	val, _ := inf.NewConfirm(
		confirm.WithDefaultYes(),
		confirm.WithDisplayHelp(),
		confirm.WithPrompt("are you rich?"),
	).Display()

	if val {
		fmt.Println("yes, you are.")
	} else {
		fmt.Println("no,you are not.")
	}
}

system info:
在CentOS 7.7上率先发现的此问题,一下是开发环境的信息

root@57f903fda34c:~/xuzm/goWorkspace# cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

root@57f903fda34c:~/xuzm/goWorkspace# go version
go version go1.18.5 linux/amd64

question:
当我Ctrl+C退出后,输入的字符(echo "cannot see echo cmd")皆不可见,执行之后的输出显示在输入命令的那一行

root@57f903fda34c:~/xuzm/goWorkspace# go run awesome/prac2/main.go 
root@57f903fda34c:~/xuzm/goWorkspace# ^C
cannot see echo cmd/xuzm/goWorkspace#

是否有类似于placeholder的组件来实现输入提示

我尝试使用withdefaultvalue来当做placeholder,但是如果不进行输入 使用command+c进行程序退出,会默认传递defaultvalue
目前是强制在我使用的过程中增加了退出触发键,但是这无法保证其他使用我程序的人也是用退出触发键

confirm 组件在串口使用会导致乱码

ssh

#reboot
? The configuration file has not been saved since the last modification.
 Do you want to save the configuration?                               
                                                                       » No / Yes
tab/left/right switch item • enter status item

console(ttyS0,115200)

#rebooty޷top/w+opop/p{tt+`.sWm{{.{p{.{doq{G{Oo.n{{.{/sy
                  reboot  reboot the system                      {/{csf�+`
                                                                          sn�s+`
                                                                                sm#ios{m[S{/{y tsecsf�m```````````````mmop``````````````````````````````````b{/{opotoyYkjbceFo.;hsiWmbbe�tm[S{paoq{\{/aoxdorMh{/{csf�+`
                                                                                                                                                                                                                       sn�s+`
                                                                                                                                                                                                                             sm#ios{m[S{/boq```````````````````````````````````bf{/{opotoyYkjoql{p{qp�ysn.vt+`Vrm{rrtYs{m[S{/{-e.+_`,+{+bc�e+d{+```[S{/{ޫ`++c_+e{m````````[S{/{```````````````````b{/{opotoyao.;hsiWmbbe�tm[S{poq{\{/aoq{nrtYs{m[S{/boql{�````````````````````bno{/{opot[q{+n{m[S{/boxoq{\{/aoq{nrtYs{m[S{/boql{�````````````````````b{/{opotoy{{pick�F√ Warn:You are about to reboot the system.
                                         … No / Yes

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.