summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-05-31 17:16:38 -0500
committercitrons <citrons@mondecitronne.com>2025-05-31 17:16:57 -0500
commitb11c892158772f508e494b2726a5d4db1bb74d23 (patch)
tree16113353422520259ccc7937e9085a68ac6663a6 /client
parent0a58e68ad438ff43fa5bbecdb8914aa00cab5099 (diff)
text input box
Diffstat (limited to 'client')
-rw-r--r--client/application.go29
-rw-r--r--client/buffer/buffer.go12
-rw-r--r--client/client/client.go10
-rw-r--r--client/clipboard/clipboard.go34
-rw-r--r--client/main.go7
5 files changed, 71 insertions, 21 deletions
diff --git a/client/application.go b/client/application.go
index fdb0216..72ec078 100644
--- a/client/application.go
+++ b/client/application.go
@@ -7,6 +7,7 @@ import (
"citrons.xyz/talk/proto"
"citrons.xyz/talk/tui"
"zgo.at/termfo/keys"
+ "os"
)
type application struct {
@@ -23,7 +24,6 @@ func newApplication(serverAddress string) *application {
var app application
app.Client = client.New(serverAddress)
app.cache = object.NewCache(&app)
- app.cmdBuffer.Buffer = buffer.New("buffer")
app.currentBuffer = &app.cmdBuffer.Buffer
app.cmdBuffer.info("connecting to %s", app.Client.Address)
@@ -105,13 +105,18 @@ func (a *application) auth(name string) {
}
func (a *application) onInput(ev tui.Event) {
+ tui.Selected = "input"
+
a.currentBuffer.Scroll(-ev.Mouse.Scroll * 2)
+ scroll := tui.Size().Height - 5
switch ev.Key {
- case keys.Up:
- a.currentBuffer.Scroll(1)
- case keys.Down:
- a.currentBuffer.Scroll(-1)
+ case keys.PageUp:
+ a.currentBuffer.Scroll(scroll)
+ case keys.PageDown:
+ a.currentBuffer.Scroll(-scroll)
}
+
+ a.currentBuffer.TextInput.Update(ev)
}
func (a *application) show() {
@@ -120,8 +125,18 @@ func (a *application) show() {
tui.Push("", tui.Box {
Width: tui.BoxSize(s.Width), Height: tui.BoxSize(s.Height),
})
- a.currentBuffer.Show()
+
+ a.currentBuffer.Show("buffer")
+ tui.Push("status", tui.Box {
+ Width: tui.Fill, Height: tui.BoxSize(1), Dir: tui.Right,
+ Style: &tui.Style {Bg: tui.White, Fg: tui.Black},
+ })
+ tui.Pop()
+ a.currentBuffer.TextInput.Show("input")
+
tui.Pop()
tui.DrawLayout()
- tui.Present()
+ if tui.Present() != nil {
+ os.Exit(-1)
+ }
}
diff --git a/client/buffer/buffer.go b/client/buffer/buffer.go
index bb782fb..230fba9 100644
--- a/client/buffer/buffer.go
+++ b/client/buffer/buffer.go
@@ -5,10 +5,10 @@ import (
)
type Buffer struct {
- id string
top *bufList
bottom *bufList
scroll tui.ScrollState
+ TextInput tui.TextInput
Closed bool
}
@@ -24,10 +24,6 @@ type bufList struct {
next *bufList
}
-func New(id string) Buffer {
- return Buffer {id: id}
-}
-
func (b *Buffer) Add(msg Message) {
l := &bufList {msg: msg}
if b.bottom != nil {
@@ -70,8 +66,8 @@ func (b *Buffer) AtTop() bool {
return b.scroll.AtLast()
}
-func (b *Buffer) Show() (atTop bool) {
- tui.Push(b.id, tui.Box {
+func (b *Buffer) Show(id string) (atTop bool) {
+ tui.Push(id, tui.Box {
Width: tui.Fill, Height: tui.Fill, Dir: tui.Up, Overflow: true,
Scroll: &b.scroll,
})
@@ -90,5 +86,5 @@ func (b *Buffer) Show() (atTop bool) {
tui.Pop()
}
- return atTop
+ return b.scroll.AtLast()
}
diff --git a/client/client/client.go b/client/client/client.go
index afbafbe..e32e02c 100644
--- a/client/client/client.go
+++ b/client/client/client.go
@@ -50,16 +50,12 @@ func (c *Client) RunClient() {
defer conn.Close()
sleep = time.Second
- c.message <- Message {func(mh MessageHandler) {
- mh.OnConnect()
- }}
-
recv, recvErr := proto.ReadLines(bufio.NewReader(conn))
send := make(chan proto.Line, 1)
defer close(send)
sendErr := proto.WriteLines(bufio.NewWriter(conn), send)
- c.send = make(chan proto.Line)
+ c.send = make(chan proto.Line, 1)
go func() {
buf := make([]proto.Line, 0, 8)
for {
@@ -83,6 +79,10 @@ func (c *Client) RunClient() {
}()
defer close(c.send)
+ c.message <- Message {func(mh MessageHandler) {
+ mh.OnConnect()
+ }}
+
run: for {
select {
case line := <-recv:
diff --git a/client/clipboard/clipboard.go b/client/clipboard/clipboard.go
new file mode 100644
index 0000000..b110378
--- /dev/null
+++ b/client/clipboard/clipboard.go
@@ -0,0 +1,34 @@
+package tui
+
+import (
+ "sync"
+)
+
+type Clipboard interface {
+ Copy(text string)
+ Paste() <-chan string
+}
+
+type virtualClipboard string
+
+func (clip *virtualClipboard) Copy(text string) {
+ *clip = text
+}
+
+var ch = make(chan string)
+func (clip *virtualClipboard) Paste() <-chan string {
+ go func() {
+ ch <- *clip
+ }()
+ return ch
+}
+
+var clipboard Clipboard = virtualClipboard {}
+var mut RWMutex
+
+func Get() {
+ mut.RLock()
+ c := clipboard
+ mut.RUnlock()
+ return c
+}
diff --git a/client/main.go b/client/main.go
index 1f46a00..4c65752 100644
--- a/client/main.go
+++ b/client/main.go
@@ -3,10 +3,15 @@ package main
import (
"citrons.xyz/talk/tui"
"time"
+ "fmt"
+ "os"
)
func main() {
- tui.Start()
+ err := tui.Start()
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "error initializing terminal: ", err)
+ }
app := newApplication("localhost:27508")
go app.RunClient()