Updated README.md and some comments.

This commit is contained in:
Daniel Schmidt 2023-05-12 13:32:53 +02:00
parent 16b7c6c4e9
commit 00a668b21b
2 changed files with 9 additions and 3 deletions

View File

@ -17,18 +17,19 @@ go get github.com/BigJk/crt@latest
```go
func main() {
// Load fonts for normal, bold and italic text styles.
fonts, err := crt.LoadFaces("./fonts/SomeFont-Regular.ttf", "./fonts/SomeFont-Bold.ttf", "./fonts/SomeFont-Italic.ttf", 72.0, 16.0)
if err != nil {
panic(err)
}
// Just pass your tea.Model to the bubbleadapter and it will render it to the terminal
win, err := bubbleadapter.Window(Width, Height, fonts, model{}, color.Black, tea.WithAltScreen())
// Just pass your tea.Model to the bubbleadapter, and it will render it to the terminal.
win, err := bubbleadapter.Window(1000, 600, fonts, someModel{}, color.Black, tea.WithAltScreen())
if err != nil {
panic(err)
}
// Star the terminal with the given title
// Star the terminal with the given title.
if err := win.Run("Simple"); err != nil {
panic(err)
}

View File

@ -2,11 +2,13 @@ package crt
import "io"
// ConcurrentRW is a concurrent read/write buffer via channels.
type ConcurrentRW struct {
input chan []byte
output chan []byte
}
// NewConcurrentRW creates a new concurrent read/write buffer.
func NewConcurrentRW() *ConcurrentRW {
return &ConcurrentRW{
input: make(chan []byte, 10),
@ -14,6 +16,7 @@ func NewConcurrentRW() *ConcurrentRW {
}
}
// Write writes data to the buffer.
func (rw *ConcurrentRW) Write(p []byte) (n int, err error) {
data := make([]byte, len(p))
copy(data, p)
@ -21,6 +24,7 @@ func (rw *ConcurrentRW) Write(p []byte) (n int, err error) {
return len(data), nil
}
// Read reads data from the buffer.
func (rw *ConcurrentRW) Read(p []byte) (n int, err error) {
data, ok := <-rw.output
if !ok {
@ -30,6 +34,7 @@ func (rw *ConcurrentRW) Read(p []byte) (n int, err error) {
return n, nil
}
// Run starts the concurrent read/write buffer.
func (rw *ConcurrentRW) Run() {
const bufferSize = 1024
buf := make([]byte, 0, bufferSize)