From 00a668b21b6a81a9574c27b8b017315b43598cce Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 12 May 2023 13:32:53 +0200 Subject: [PATCH] Updated README.md and some comments. --- README.md | 7 ++++--- read_writer.go | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 95491ee..6890dbf 100644 --- a/README.md +++ b/README.md @@ -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) } diff --git a/read_writer.go b/read_writer.go index 3686654..9e8664a 100644 --- a/read_writer.go +++ b/read_writer.go @@ -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)