2024-03-13 23:06:13 +01:00
|
|
|
package tui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2024-03-14 01:18:51 +01:00
|
|
|
"context"
|
2024-03-13 23:06:13 +01:00
|
|
|
"crypto/tls"
|
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"golang.org/x/term"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mySignal struct {
|
|
|
|
Type int
|
|
|
|
}
|
|
|
|
|
|
|
|
var UI TUI
|
|
|
|
|
|
|
|
type dataT struct {
|
|
|
|
raw string
|
|
|
|
rawP *[]rune
|
|
|
|
op1 string
|
|
|
|
op2 string
|
|
|
|
ops []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type dataProcessHandler func(t *TUI, data dataT) error
|
|
|
|
|
|
|
|
type tuiPointPair struct {
|
|
|
|
startCol int
|
|
|
|
startRow int
|
|
|
|
endCol int
|
|
|
|
endRow int
|
|
|
|
}
|
|
|
|
|
|
|
|
type widget struct {
|
|
|
|
row int
|
|
|
|
col int
|
|
|
|
MinWidth int
|
|
|
|
MinHeight int
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
Title string
|
|
|
|
Input *[]rune
|
|
|
|
Handler dataProcessHandler
|
|
|
|
Data dataT
|
|
|
|
Next *widgetConfig
|
|
|
|
Finale dataProcessHandler
|
|
|
|
FinaleData dataT
|
|
|
|
percentPair tuiPointPair
|
|
|
|
snappedPair tuiPointPair
|
|
|
|
startupConfig widgetConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type notifier struct {
|
|
|
|
Row int
|
|
|
|
Col int
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
Buf string
|
|
|
|
}
|
|
|
|
|
2024-05-01 16:21:10 +02:00
|
|
|
type dialog struct {
|
|
|
|
Row int
|
|
|
|
Col int
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
Buf string
|
|
|
|
Catcher RuneCatcher
|
|
|
|
}
|
|
|
|
|
2024-03-13 23:06:13 +01:00
|
|
|
type widgetDraw struct {
|
|
|
|
Buf string
|
|
|
|
Row int
|
|
|
|
Col int
|
|
|
|
}
|
|
|
|
|
|
|
|
type cursorPosConfigValue int
|
|
|
|
type widgetPosConfigValue int
|
|
|
|
|
|
|
|
type widgetConfig struct {
|
|
|
|
MinWidth int
|
|
|
|
MinHeight int
|
|
|
|
Input *[]rune
|
|
|
|
CursorPosConfig cursorPosConfigValue
|
|
|
|
Title string
|
|
|
|
WidgetPosConfig widgetPosConfigValue
|
|
|
|
HasBorder bool
|
|
|
|
DataHandler dataProcessHandler
|
|
|
|
Data dataT
|
|
|
|
Next *widgetConfig
|
|
|
|
Finale dataProcessHandler
|
|
|
|
FinaleData dataT
|
|
|
|
}
|
|
|
|
|
2024-03-14 01:18:51 +01:00
|
|
|
type closeData struct {
|
|
|
|
wg *sync.WaitGroup
|
|
|
|
cancel context.CancelFunc
|
|
|
|
}
|
|
|
|
|
2024-05-01 16:21:10 +02:00
|
|
|
type RuneCatcher func(runes chan (rune)) error
|
|
|
|
|
2024-03-13 23:06:13 +01:00
|
|
|
type TUI struct {
|
|
|
|
width int
|
|
|
|
height int
|
|
|
|
cursorPosRow int
|
|
|
|
cursorPosCol int
|
|
|
|
writeMu sync.Mutex
|
|
|
|
sizeMutex sync.Mutex
|
|
|
|
oldState *term.State
|
2024-05-01 16:21:10 +02:00
|
|
|
inputChannel chan (rune)
|
|
|
|
inputCatcher RuneCatcher
|
2024-03-13 23:06:13 +01:00
|
|
|
printRunes chan (rune)
|
|
|
|
mySignals chan (mySignal)
|
|
|
|
osSignals chan (os.Signal)
|
2024-05-01 16:21:10 +02:00
|
|
|
errorsChannel chan (error)
|
2024-03-13 23:06:13 +01:00
|
|
|
readInputState chan (bool)
|
|
|
|
readEnterState chan (bool)
|
|
|
|
stateChannel chan (string)
|
2024-03-13 23:24:00 +01:00
|
|
|
messageChannel chan ([]byte)
|
2024-03-13 23:06:13 +01:00
|
|
|
widgets []*widget
|
|
|
|
widgetsMutext sync.Mutex
|
|
|
|
writer *bufio.Writer
|
|
|
|
isConnected bool
|
|
|
|
selectedWidget *widget
|
|
|
|
selectedNotifier *notifier
|
|
|
|
storage map[string]string
|
|
|
|
tlsConnection *tls.Conn
|
2024-03-14 01:18:51 +01:00
|
|
|
tlsConnCloseData closeData
|
2024-03-13 23:06:13 +01:00
|
|
|
}
|