mirror of
https://github.com/BigJk/crt.git
synced 2026-02-06 10:47:25 +00:00
Updated README.md and some comments.
This commit is contained in:
parent
16b7c6c4e9
commit
00a668b21b
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user