https://github.com/borud/chatui
Chat like user interface
https://github.com/borud/chatui
Last synced: over 1 year ago
JSON representation
Chat like user interface
- Host: GitHub
- URL: https://github.com/borud/chatui
- Owner: borud
- License: apache-2.0
- Created: 2022-04-11T17:19:10.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-12T10:43:26.000Z (about 2 years ago)
- Last Synced: 2025-01-19T09:09:50.528Z (over 1 year ago)
- Language: Go
- Size: 47.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: history.go
- License: LICENSE
Awesome Lists containing this project
README
# chatui
`chatui` is a simple chat-like user interface that can be used to create chat-like user interfaces. You communicate with the UI via two channels: the `OutputCh` which is used to display output in the
main display area and `CommandCh` which is used to receive commands entered by the user in the input area of the UI.

## Sample usage
```go
package main
import (
"log"
"strings"
"time"
"github.com/borud/chatui"
)
func main() {
outputCh := make(chan string, 10)
commandCh := make(chan string)
chatui := chatui.New(chatui.Config{
OutputCh: outputCh,
CommandCh: commandCh,
DynamicColor: false,
BlockCtrlC: true,
HistorySize: 10,
})
go func() {
for {
outputCh <- "hey there, the time is now " + time.Now().Format("15:04:05.00")
time.Sleep(time.Second)
}
}()
go func() {
for command := range commandCh {
if strings.ToLower(command) == "/quit" {
chatui.Stop()
}
outputCh <- "command was: " + command
chatui.SetStatus("last command was: " + command)
}
}()
go func() {
// this is done in a goroutine because it will block if the UI is not running.
chatui.SetStatus("type /quit to exit")
}()
err := chatui.Run()
if err != nil {
log.Fatal(err)
}
}
```