中文 | English
- 提供一系列开箱即用的组件
- autocomplete
- progress bar / progress-bar group
- multi/single select
- spinner
- confirm
- input
- 支持 window/linux (我现在只有这两种操作系统)
- 可定制,你可以替换组件中的某些选项或方法为你自己的实现
- 可组合,你可以将一个或多个基础组件联合在一起使用
autocomplete
由input
和selection
组成selection
通过嵌入input
来实现过滤功能.- ...
- 通过消息来更新状态,也就是通过
program.Send(msg)
来发送消息,Update
监听并进行状态更新,最后通过View
来反馈结果. - ...
go get github.com/fzdwx/infinite
一个 progress
和 spinner
组合使用的demo
代码
package main
import (
"github.com/fzdwx/infinite/components"
"github.com/fzdwx/infinite/components/progress"
"time"
)
func main() {
cnt := 10
group := progress.NewGroupWithCount(10).
AppendRunner(func(progress *components.Progress) func() {
total := cnt
cnt += 1
progress.WithTotal(int64(total)).
WithDefaultGradient()
return func() {
for i := 0; i < total+1; i++ {
progress.IncrOne()
sleep()
}
for i := 0; i < total; i++ {
progress.DecrOne()
sleep()
}
for i := 0; i < total+1; i++ {
progress.IncrOne()
sleep()
}
}
})
group.Display()
}
func sleep() {
time.Sleep(time.Millisecond * 100)
}
代码
package main
import (
inf "github.com/fzdwx/infinite"
"github.com/fzdwx/infinite/color"
"github.com/fzdwx/infinite/components"
"github.com/fzdwx/infinite/components/selection/multiselect"
"github.com/fzdwx/infinite/style"
)
func main() {
input := components.NewInput()
input.Prompt = "Filtering: "
input.PromptStyle = style.New().Bold().Italic().Fg(color.LightBlue)
_, _ = inf.NewMultiSelect([]string{
"Buy carrots",
"Buy celery",
"Buy kohlrabi",
"Buy computer",
"Buy something",
"Buy car",
"Buy subway",
},
multiselect.WithFilterInput(input),
).Display("select your items!")
}
代码
package main
import (
inf "github.com/fzdwx/infinite"
"github.com/fzdwx/infinite/components"
"github.com/fzdwx/infinite/components/spinner"
"time"
)
func main() {
_ = inf.NewSpinner(
spinner.WithShape(components.Dot),
//spinner.WithDisableOutputResult(),
).Display(func(spinner *spinner.Spinner) {
for i := 0; i < 10; i++ {
time.Sleep(time.Millisecond * 100)
spinner.Refreshf("hello world %d", i)
}
spinner.Finish("finish")
spinner.Refresh("is finish?")
})
time.Sleep(time.Millisecond * 100 * 15)
}
代码
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.WithPlaceholder(" fzdwx (maybe)"),
)
_ = i.Display()
fmt.Printf("you input: %s\n", i.Value())
}
代码
package main
import (
"fmt"
inf "github.com/fzdwx/infinite"
"github.com/fzdwx/infinite/components/input/confirm"
)
func main() {
c := inf.NewConfirm(
confirm.WithDefaultYes(),
confirm.WithDisplayHelp(),
)
c.Display()
if c.Value() {
fmt.Println("yes, you are.")
} else {
fmt.Println("no,you are not.")
}
}
代码
package main
import (
"fmt"
inf "github.com/fzdwx/infinite"
)
func main() {
val, _ := inf.NewConfirmWithSelection(
//confirm.WithDisOutResult(),
).Display()
fmt.Println(val)
}
- https://github.com/charmbracelet/bubbletea
- https://github.com/charmbracelet/bubbles
- https://github.com/charmbracelet/lipgloss
- https://github.com/muesli/termenv
- https://github.com/sahilm/fuzzy
- ...
MIT