senpai-tty.patch

· erock's pastes · raw

expires: 01 Aug, 2024

 1From af89e73973b04816e14a041d9b55130496fd6f88 Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Fri, 3 May 2024 16:04:12 -0400
 4Subject: [PATCH] feat: provide tty as an option to `NewApp`
 5
 6---
 7 app.go    | 1 +
 8 config.go | 1 +
 9 ui/ui.go  | 8 +++++++-
10 3 files changed, 9 insertions(+), 1 deletion(-)
11
12diff --git a/app.go b/app.go
13index c57d48b..c681cbb 100644
14--- a/app.go
15+++ b/app.go
16@@ -160,6 +160,7 @@ func NewApp(cfg Config) (app *App, err error) {
17 			app.mergeLine(former, addition)
18 		},
19 		Colors: cfg.Colors,
20+		Tty:    cfg.Tty,
21 	})
22 	if err != nil {
23 		return
24diff --git a/config.go b/config.go
25index 132250f..3177f8a 100644
26--- a/config.go
27+++ b/config.go
28@@ -115,6 +115,7 @@ type Config struct {
29 
30 	Debug     bool
31 	Transient bool
32+	Tty       tcell.Tty
33 }
34 
35 func DefaultHighlightPath() (string, error) {
36diff --git a/ui/ui.go b/ui/ui.go
37index ef2790e..0c3359e 100644
38--- a/ui/ui.go
39+++ b/ui/ui.go
40@@ -22,6 +22,7 @@ type Config struct {
41 	Mouse            bool
42 	MergeLine        func(former *Line, addition Line)
43 	Colors           ConfigColors
44+	Tty              tcell.Tty
45 }
46 
47 type ConfigColors struct {
48@@ -63,7 +64,12 @@ func New(config Config) (ui *UI, err error) {
49 		ui.memberWidth = config.MemberColWidth
50 	}
51 
52-	ui.screen, err = tcell.NewScreen()
53+	if config.Tty == nil {
54+		ui.screen, err = tcell.NewScreen()
55+	} else {
56+		ui.screen, err = tcell.NewTerminfoScreenFromTty(config.Tty)
57+	}
58+
59 	if err != nil {
60 		return
61 	}
62-- 
632.43.0
64