最近想搞一搞 agent cli 开发。UI 层面,node 有比较成熟的 ink 方案。

但是看了下 go TUI 相关的解决方案,描述 UI 的方式有点别扭。当然可能是我没找到更好的实现思路。

所以实现了 rego ,取 react + go 的意思。

话不多说,先上代码。

package main

import (
    "fmt"
    "github.com/erweixin/rego"
)

func App(c rego.C) rego.Node {
    count := rego.Use(c, "count", 0)
    
    rego.UseKey(c, func(key rego.Key, r rune) {
        switch r {
        case '+': count.Set(count.Val + 1)
        case '-': count.Set(count.Val - 1)
        case 'q': c.Quit()
        }
    })
    
    return rego.VStack(
        rego.Text("Rego Counter").Bold(),
        rego.Text(fmt.Sprintf("Count: %d", count.Val)),
        rego.Spacer(),
        rego.Text("[+] 增加  [-] 减少  [q] 退出").Dim(),
    )
}

func main() {
    rego.Run(App)
}

运行效果:

Rego Counter
Count: 0

[+] 增加  [-] 减少  [q] 退出

仓库: https://github.com/erweixin/rego

对于多组件的使用可以参考: https://github.com/erweixin/rego/tree/main/examples/gallery

再贴一个 stream 组件的 demo 吧。

https://github.com/erweixin/rego/blob/main/examples/stream/stream_demo.gif

欢迎各位大佬试用、提 Issue 或 PR 。如果你也喜欢这种“在终端写 React”的思路,欢迎给个 Star 支持一下!👏


📌 转载信息
原作者:
weixind
转载时间:
2025/12/26 11:51:48