2016-10-24 09:44:56 +09:00
|
|
|
package tui
|
|
|
|
|
|
|
|
import (
|
2017-01-11 23:01:56 +09:00
|
|
|
"fmt"
|
2017-01-11 02:12:32 +09:00
|
|
|
"os"
|
2017-01-10 02:16:12 +09:00
|
|
|
"strconv"
|
2016-10-24 09:44:56 +09:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Types of user action
|
2020-12-30 01:59:18 +09:00
|
|
|
type EventType int
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
const (
|
2020-12-30 01:59:18 +09:00
|
|
|
Rune EventType = iota
|
2016-10-24 09:44:56 +09:00
|
|
|
|
|
|
|
CtrlA
|
|
|
|
CtrlB
|
|
|
|
CtrlC
|
|
|
|
CtrlD
|
|
|
|
CtrlE
|
|
|
|
CtrlF
|
|
|
|
CtrlG
|
|
|
|
CtrlH
|
|
|
|
Tab
|
|
|
|
CtrlJ
|
|
|
|
CtrlK
|
|
|
|
CtrlL
|
|
|
|
CtrlM
|
|
|
|
CtrlN
|
|
|
|
CtrlO
|
|
|
|
CtrlP
|
|
|
|
CtrlQ
|
|
|
|
CtrlR
|
|
|
|
CtrlS
|
|
|
|
CtrlT
|
|
|
|
CtrlU
|
|
|
|
CtrlV
|
|
|
|
CtrlW
|
|
|
|
CtrlX
|
|
|
|
CtrlY
|
|
|
|
CtrlZ
|
|
|
|
ESC
|
2017-01-28 02:54:47 +09:00
|
|
|
CtrlSpace
|
2016-10-24 09:44:56 +09:00
|
|
|
|
2019-11-14 22:39:25 +09:00
|
|
|
// https://apple.stackexchange.com/questions/24261/how-do-i-send-c-that-is-control-slash-to-the-terminal
|
|
|
|
CtrlBackSlash
|
|
|
|
CtrlRightBracket
|
|
|
|
CtrlCaret
|
|
|
|
CtrlSlash
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
Invalid
|
2016-11-23 01:58:46 +09:00
|
|
|
Resize
|
2016-10-24 09:44:56 +09:00
|
|
|
Mouse
|
|
|
|
DoubleClick
|
2017-12-01 02:11:20 +09:00
|
|
|
LeftClick
|
|
|
|
RightClick
|
2016-10-24 09:44:56 +09:00
|
|
|
|
|
|
|
BTab
|
|
|
|
BSpace
|
|
|
|
|
|
|
|
Del
|
|
|
|
PgUp
|
|
|
|
PgDn
|
|
|
|
|
|
|
|
Up
|
|
|
|
Down
|
|
|
|
Left
|
|
|
|
Right
|
|
|
|
Home
|
|
|
|
End
|
2020-02-24 01:43:19 +09:00
|
|
|
Insert
|
2016-10-24 09:44:56 +09:00
|
|
|
|
2018-02-15 19:56:11 +09:00
|
|
|
SUp
|
|
|
|
SDown
|
2016-10-24 09:44:56 +09:00
|
|
|
SLeft
|
|
|
|
SRight
|
|
|
|
|
|
|
|
F1
|
|
|
|
F2
|
|
|
|
F3
|
|
|
|
F4
|
|
|
|
F5
|
|
|
|
F6
|
|
|
|
F7
|
|
|
|
F8
|
|
|
|
F9
|
|
|
|
F10
|
2016-11-19 22:40:28 +09:00
|
|
|
F11
|
|
|
|
F12
|
2016-10-24 09:44:56 +09:00
|
|
|
|
2017-05-22 17:07:05 +09:00
|
|
|
Change
|
2020-06-07 23:07:03 +09:00
|
|
|
BackwardEOF
|
2022-10-27 00:33:05 +09:00
|
|
|
Start
|
2022-12-29 20:01:50 +09:00
|
|
|
Load
|
2017-05-22 17:07:05 +09:00
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
AltBS
|
2016-11-19 22:40:28 +09:00
|
|
|
|
2018-04-12 17:39:28 +09:00
|
|
|
AltUp
|
|
|
|
AltDown
|
|
|
|
AltLeft
|
|
|
|
AltRight
|
|
|
|
|
2020-11-24 19:36:58 +09:00
|
|
|
AltSUp
|
|
|
|
AltSDown
|
|
|
|
AltSLeft
|
|
|
|
AltSRight
|
|
|
|
|
2020-12-30 01:59:18 +09:00
|
|
|
Alt
|
|
|
|
CtrlAlt
|
2016-11-19 22:40:28 +09:00
|
|
|
)
|
|
|
|
|
2020-12-30 01:59:18 +09:00
|
|
|
func (t EventType) AsEvent() Event {
|
|
|
|
return Event{t, 0, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t EventType) Int() int {
|
|
|
|
return int(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t EventType) Byte() byte {
|
|
|
|
return byte(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Event) Comparable() Event {
|
|
|
|
// Ignore MouseEvent pointer
|
|
|
|
return Event{e.Type, e.Char, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Key(r rune) Event {
|
|
|
|
return Event{Rune, r, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func AltKey(r rune) Event {
|
|
|
|
return Event{Alt, r, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CtrlAltKey(r rune) Event {
|
|
|
|
return Event{CtrlAlt, r, nil}
|
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
|
|
|
|
const (
|
|
|
|
doubleClickDuration = 500 * time.Millisecond
|
|
|
|
)
|
|
|
|
|
2016-11-26 00:36:38 +09:00
|
|
|
type Color int32
|
|
|
|
|
2020-12-04 19:27:43 +09:00
|
|
|
func (c Color) IsDefault() bool {
|
|
|
|
return c == colDefault
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:36:38 +09:00
|
|
|
func (c Color) is24() bool {
|
|
|
|
return c > 0 && (c&(1<<24)) > 0
|
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
type ColorAttr struct {
|
|
|
|
Color Color
|
|
|
|
Attr Attr
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewColorAttr() ColorAttr {
|
|
|
|
return ColorAttr{Color: colUndefined, Attr: AttrUndefined}
|
|
|
|
}
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
const (
|
|
|
|
colUndefined Color = -2
|
Improvements to code quality and readability (#1737)
* Remove 1 unused field and 3 unused functions
unused elements fount by running
golangci-lint run --disable-all --enable unused
src/result.go:19:2: field `index` is unused (unused)
index int32
^
src/tui/light.go:716:23: func `(*LightWindow).stderr` is unused (unused)
func (w *LightWindow) stderr(str string) {
^
src/terminal.go:1015:6: func `numLinesMax` is unused (unused)
func numLinesMax(str string, max int) int {
^
src/tui/tui.go:167:20: func `ColorPair.is24` is unused (unused)
func (p ColorPair) is24() bool {
^
* Address warnings from "gosimple" linter
src/options.go:389:83: S1003: should use strings.Contains(str, ",,,") instead (gosimple)
if str == "," || strings.HasPrefix(str, ",,") || strings.HasSuffix(str, ",,") || strings.Index(str, ",,,") >= 0 {
^
src/options.go:630:18: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
executeRegexp = regexp.MustCompile(
^
src/terminal.go:29:16: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
placeholder = regexp.MustCompile("\\\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\\+?f?nf?})")
^
src/terminal_test.go:92:10: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
regex = regexp.MustCompile("\\w+")
^
* Address warnings from "staticcheck" linter
src/algo/algo.go:374:2: SA4006: this value of `offset32` is never used (staticcheck)
offset32, T := alloc32(offset32, slab, N)
^
src/algo/algo.go:456:2: SA4006: this value of `offset16` is never used (staticcheck)
offset16, C := alloc16(offset16, slab, width*M)
^
src/tui/tui.go:119:2: SA9004: only the first constant in this group has an explicit type (staticcheck)
colUndefined Color = -2
^
2019-11-05 03:46:51 +03:00
|
|
|
colDefault Color = -1
|
2016-10-24 09:44:56 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
colBlack Color = iota
|
|
|
|
colRed
|
|
|
|
colGreen
|
|
|
|
colYellow
|
|
|
|
colBlue
|
|
|
|
colMagenta
|
|
|
|
colCyan
|
|
|
|
colWhite
|
|
|
|
)
|
|
|
|
|
2017-01-11 22:13:40 +09:00
|
|
|
type FillReturn int
|
|
|
|
|
|
|
|
const (
|
|
|
|
FillContinue FillReturn = iota
|
|
|
|
FillNextLine
|
|
|
|
FillSuspend
|
|
|
|
)
|
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
type ColorPair struct {
|
2020-10-25 19:29:37 +09:00
|
|
|
fg Color
|
|
|
|
bg Color
|
|
|
|
attr Attr
|
2017-01-08 01:30:31 +09:00
|
|
|
}
|
|
|
|
|
2017-01-10 02:16:12 +09:00
|
|
|
func HexToColor(rrggbb string) Color {
|
|
|
|
r, _ := strconv.ParseInt(rrggbb[1:3], 16, 0)
|
|
|
|
g, _ := strconv.ParseInt(rrggbb[3:5], 16, 0)
|
|
|
|
b, _ := strconv.ParseInt(rrggbb[5:7], 16, 0)
|
|
|
|
return Color((1 << 24) + (r << 16) + (g << 8) + b)
|
|
|
|
}
|
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
func NewColorPair(fg Color, bg Color, attr Attr) ColorPair {
|
|
|
|
return ColorPair{fg, bg, attr}
|
2017-01-08 01:30:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) Fg() Color {
|
|
|
|
return p.fg
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) Bg() Color {
|
|
|
|
return p.bg
|
|
|
|
}
|
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
func (p ColorPair) Attr() Attr {
|
|
|
|
return p.attr
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:27:43 +09:00
|
|
|
func (p ColorPair) HasBg() bool {
|
|
|
|
return p.attr&Reverse == 0 && p.bg != colDefault ||
|
|
|
|
p.attr&Reverse > 0 && p.fg != colDefault
|
|
|
|
}
|
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
func (p ColorPair) merge(other ColorPair, except Color) ColorPair {
|
|
|
|
dup := p
|
|
|
|
dup.attr = dup.attr.Merge(other.attr)
|
|
|
|
if other.fg != except {
|
|
|
|
dup.fg = other.fg
|
|
|
|
}
|
|
|
|
if other.bg != except {
|
|
|
|
dup.bg = other.bg
|
|
|
|
}
|
|
|
|
return dup
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) WithAttr(attr Attr) ColorPair {
|
|
|
|
dup := p
|
|
|
|
dup.attr = dup.attr.Merge(attr)
|
|
|
|
return dup
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) MergeAttr(other ColorPair) ColorPair {
|
|
|
|
return p.WithAttr(other.attr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) Merge(other ColorPair) ColorPair {
|
|
|
|
return p.merge(other, colUndefined)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ColorPair) MergeNonDefault(other ColorPair) ColorPair {
|
|
|
|
return p.merge(other, colDefault)
|
|
|
|
}
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
type ColorTheme struct {
|
2020-10-25 19:29:37 +09:00
|
|
|
Colored bool
|
|
|
|
Input ColorAttr
|
2021-01-03 00:00:40 +09:00
|
|
|
Disabled ColorAttr
|
2020-10-25 19:29:37 +09:00
|
|
|
Fg ColorAttr
|
|
|
|
Bg ColorAttr
|
|
|
|
PreviewFg ColorAttr
|
|
|
|
PreviewBg ColorAttr
|
|
|
|
DarkBg ColorAttr
|
|
|
|
Gutter ColorAttr
|
|
|
|
Prompt ColorAttr
|
|
|
|
Match ColorAttr
|
|
|
|
Current ColorAttr
|
|
|
|
CurrentMatch ColorAttr
|
|
|
|
Spinner ColorAttr
|
|
|
|
Info ColorAttr
|
|
|
|
Cursor ColorAttr
|
|
|
|
Selected ColorAttr
|
|
|
|
Header ColorAttr
|
2022-10-30 16:28:58 +09:00
|
|
|
Separator ColorAttr
|
2023-01-01 14:48:14 +09:00
|
|
|
Scrollbar ColorAttr
|
2020-10-25 19:29:37 +09:00
|
|
|
Border ColorAttr
|
2022-10-30 00:12:01 +09:00
|
|
|
BorderLabel ColorAttr
|
2022-12-09 12:05:27 +09:00
|
|
|
PreviewLabel ColorAttr
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
type Event struct {
|
2020-12-30 01:59:18 +09:00
|
|
|
Type EventType
|
2016-10-24 09:44:56 +09:00
|
|
|
Char rune
|
|
|
|
MouseEvent *MouseEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
type MouseEvent struct {
|
|
|
|
Y int
|
|
|
|
X int
|
|
|
|
S int
|
2017-12-01 02:11:20 +09:00
|
|
|
Left bool
|
2016-10-24 09:44:56 +09:00
|
|
|
Down bool
|
|
|
|
Double bool
|
|
|
|
Mod bool
|
|
|
|
}
|
|
|
|
|
2019-03-29 02:11:03 +09:00
|
|
|
type BorderShape int
|
2017-02-04 21:51:22 +09:00
|
|
|
|
|
|
|
const (
|
2019-03-29 02:11:03 +09:00
|
|
|
BorderNone BorderShape = iota
|
2020-03-05 20:15:15 +09:00
|
|
|
BorderRounded
|
|
|
|
BorderSharp
|
2022-11-06 14:38:31 +09:00
|
|
|
BorderBold
|
|
|
|
BorderDouble
|
2017-02-04 21:51:22 +09:00
|
|
|
BorderHorizontal
|
2020-10-26 22:33:41 +09:00
|
|
|
BorderVertical
|
|
|
|
BorderTop
|
|
|
|
BorderBottom
|
|
|
|
BorderLeft
|
|
|
|
BorderRight
|
2017-02-04 21:51:22 +09:00
|
|
|
)
|
|
|
|
|
2019-03-29 02:11:03 +09:00
|
|
|
type BorderStyle struct {
|
|
|
|
shape BorderShape
|
|
|
|
horizontal rune
|
|
|
|
vertical rune
|
|
|
|
topLeft rune
|
|
|
|
topRight rune
|
|
|
|
bottomLeft rune
|
|
|
|
bottomRight rune
|
|
|
|
}
|
|
|
|
|
2019-11-15 18:27:08 +09:00
|
|
|
type BorderCharacter int
|
|
|
|
|
2019-03-29 02:11:03 +09:00
|
|
|
func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
|
2022-11-06 14:38:31 +09:00
|
|
|
if !unicode {
|
|
|
|
return BorderStyle{
|
|
|
|
shape: shape,
|
|
|
|
horizontal: '-',
|
|
|
|
vertical: '|',
|
|
|
|
topLeft: '+',
|
|
|
|
topRight: '+',
|
|
|
|
bottomLeft: '+',
|
|
|
|
bottomRight: '+',
|
2020-03-05 20:15:15 +09:00
|
|
|
}
|
2022-11-06 14:38:31 +09:00
|
|
|
}
|
|
|
|
switch shape {
|
|
|
|
case BorderSharp:
|
2019-03-29 02:11:03 +09:00
|
|
|
return BorderStyle{
|
|
|
|
shape: shape,
|
|
|
|
horizontal: '─',
|
|
|
|
vertical: '│',
|
2020-03-05 20:15:15 +09:00
|
|
|
topLeft: '┌',
|
|
|
|
topRight: '┐',
|
|
|
|
bottomLeft: '└',
|
|
|
|
bottomRight: '┘',
|
2019-03-29 02:11:03 +09:00
|
|
|
}
|
2022-11-06 14:38:31 +09:00
|
|
|
case BorderBold:
|
|
|
|
return BorderStyle{
|
|
|
|
shape: shape,
|
|
|
|
horizontal: '━',
|
|
|
|
vertical: '┃',
|
|
|
|
topLeft: '┏',
|
|
|
|
topRight: '┓',
|
|
|
|
bottomLeft: '┗',
|
|
|
|
bottomRight: '┛',
|
|
|
|
}
|
|
|
|
case BorderDouble:
|
|
|
|
return BorderStyle{
|
|
|
|
shape: shape,
|
|
|
|
horizontal: '═',
|
|
|
|
vertical: '║',
|
|
|
|
topLeft: '╔',
|
|
|
|
topRight: '╗',
|
|
|
|
bottomLeft: '╚',
|
|
|
|
bottomRight: '╝',
|
|
|
|
}
|
2019-03-29 02:11:03 +09:00
|
|
|
}
|
|
|
|
return BorderStyle{
|
|
|
|
shape: shape,
|
2022-11-06 14:38:31 +09:00
|
|
|
horizontal: '─',
|
|
|
|
vertical: '│',
|
|
|
|
topLeft: '╭',
|
|
|
|
topRight: '╮',
|
|
|
|
bottomLeft: '╰',
|
|
|
|
bottomRight: '╯',
|
2019-03-29 02:11:03 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-15 18:27:08 +09:00
|
|
|
func MakeTransparentBorder() BorderStyle {
|
|
|
|
return BorderStyle{
|
2020-03-05 20:15:15 +09:00
|
|
|
shape: BorderRounded,
|
2019-11-15 18:27:08 +09:00
|
|
|
horizontal: ' ',
|
|
|
|
vertical: ' ',
|
|
|
|
topLeft: ' ',
|
|
|
|
topRight: ' ',
|
|
|
|
bottomLeft: ' ',
|
|
|
|
bottomRight: ' '}
|
|
|
|
}
|
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
type Renderer interface {
|
|
|
|
Init()
|
2022-09-08 01:01:22 +09:00
|
|
|
Resize(maxHeightFunc func(int) int)
|
2017-04-28 22:58:08 +09:00
|
|
|
Pause(clear bool)
|
2020-05-18 02:33:37 +09:00
|
|
|
Resume(clear bool, sigcont bool)
|
2017-01-08 01:30:31 +09:00
|
|
|
Clear()
|
|
|
|
RefreshWindows(windows []Window)
|
|
|
|
Refresh()
|
|
|
|
Close()
|
|
|
|
|
|
|
|
GetChar() Event
|
|
|
|
|
|
|
|
MaxX() int
|
|
|
|
MaxY() int
|
|
|
|
|
2019-12-12 23:03:17 +09:00
|
|
|
NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window
|
2017-01-08 01:30:31 +09:00
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
type Window interface {
|
|
|
|
Top() int
|
|
|
|
Left() int
|
|
|
|
Width() int
|
|
|
|
Height() int
|
|
|
|
|
|
|
|
Refresh()
|
|
|
|
FinishFill()
|
|
|
|
Close()
|
|
|
|
|
|
|
|
X() int
|
2017-07-19 22:46:16 +09:00
|
|
|
Y() int
|
2017-01-08 01:30:31 +09:00
|
|
|
Enclose(y int, x int) bool
|
|
|
|
|
|
|
|
Move(y int, x int)
|
|
|
|
MoveAndClear(y int, x int)
|
|
|
|
Print(text string)
|
2020-10-25 19:29:37 +09:00
|
|
|
CPrint(color ColorPair, text string)
|
2017-01-11 22:13:40 +09:00
|
|
|
Fill(text string) FillReturn
|
|
|
|
CFill(fg Color, bg Color, attr Attr, text string) FillReturn
|
2017-01-08 01:30:31 +09:00
|
|
|
Erase()
|
|
|
|
}
|
|
|
|
|
|
|
|
type FullscreenRenderer struct {
|
2021-10-01 16:59:02 +02:00
|
|
|
theme *ColorTheme
|
|
|
|
mouse bool
|
|
|
|
forceBlack bool
|
|
|
|
prevDownTime time.Time
|
2023-01-03 01:21:40 +09:00
|
|
|
clicks [][2]int
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
|
|
|
|
r := &FullscreenRenderer{
|
2021-10-01 16:59:02 +02:00
|
|
|
theme: theme,
|
|
|
|
mouse: mouse,
|
|
|
|
forceBlack: forceBlack,
|
|
|
|
prevDownTime: time.Unix(0, 0),
|
2023-01-03 01:21:40 +09:00
|
|
|
clicks: [][2]int{}}
|
2017-01-08 01:30:31 +09:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
Default16 *ColorTheme
|
|
|
|
Dark256 *ColorTheme
|
|
|
|
Light256 *ColorTheme
|
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
ColPrompt ColorPair
|
|
|
|
ColNormal ColorPair
|
|
|
|
ColInput ColorPair
|
2021-01-03 00:00:40 +09:00
|
|
|
ColDisabled ColorPair
|
2020-10-25 19:29:37 +09:00
|
|
|
ColMatch ColorPair
|
|
|
|
ColCursor ColorPair
|
|
|
|
ColCursorEmpty ColorPair
|
|
|
|
ColSelected ColorPair
|
|
|
|
ColCurrent ColorPair
|
|
|
|
ColCurrentMatch ColorPair
|
|
|
|
ColCurrentCursor ColorPair
|
|
|
|
ColCurrentCursorEmpty ColorPair
|
|
|
|
ColCurrentSelected ColorPair
|
|
|
|
ColCurrentSelectedEmpty ColorPair
|
|
|
|
ColSpinner ColorPair
|
|
|
|
ColInfo ColorPair
|
|
|
|
ColHeader ColorPair
|
2022-10-30 16:28:58 +09:00
|
|
|
ColSeparator ColorPair
|
2023-01-01 14:48:14 +09:00
|
|
|
ColScrollbar ColorPair
|
2020-10-25 19:29:37 +09:00
|
|
|
ColBorder ColorPair
|
|
|
|
ColPreview ColorPair
|
|
|
|
ColPreviewBorder ColorPair
|
2022-10-30 00:12:01 +09:00
|
|
|
ColBorderLabel ColorPair
|
2022-12-09 12:05:27 +09:00
|
|
|
ColPreviewLabel ColorPair
|
2017-01-08 01:30:31 +09:00
|
|
|
)
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
func EmptyTheme() *ColorTheme {
|
|
|
|
return &ColorTheme{
|
2020-10-25 19:29:37 +09:00
|
|
|
Colored: true,
|
|
|
|
Input: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Fg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Bg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
DarkBg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Prompt: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Match: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Current: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
CurrentMatch: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Spinner: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Info: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Cursor: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Selected: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Header: ColorAttr{colUndefined, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
Border: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
BorderLabel: ColorAttr{colUndefined, AttrUndefined},
|
2022-12-10 16:55:19 +09:00
|
|
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
2022-12-09 12:05:27 +09:00
|
|
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
2023-01-01 17:38:34 +09:00
|
|
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
}
|
2020-10-25 19:29:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func NoColorTheme() *ColorTheme {
|
|
|
|
return &ColorTheme{
|
|
|
|
Colored: false,
|
|
|
|
Input: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Fg: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Bg: ColorAttr{colDefault, AttrRegular},
|
|
|
|
DarkBg: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Prompt: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Match: ColorAttr{colDefault, Underline},
|
|
|
|
Current: ColorAttr{colDefault, Reverse},
|
|
|
|
CurrentMatch: ColorAttr{colDefault, Reverse | Underline},
|
|
|
|
Spinner: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Info: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Cursor: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Selected: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Header: ColorAttr{colDefault, AttrRegular},
|
2022-10-30 00:12:01 +09:00
|
|
|
Border: ColorAttr{colDefault, AttrRegular},
|
|
|
|
BorderLabel: ColorAttr{colDefault, AttrRegular},
|
2022-12-10 16:55:19 +09:00
|
|
|
Disabled: ColorAttr{colDefault, AttrRegular},
|
|
|
|
PreviewFg: ColorAttr{colDefault, AttrRegular},
|
|
|
|
PreviewBg: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Gutter: ColorAttr{colDefault, AttrRegular},
|
2022-12-09 12:05:27 +09:00
|
|
|
PreviewLabel: ColorAttr{colDefault, AttrRegular},
|
2023-01-01 17:38:34 +09:00
|
|
|
Separator: ColorAttr{colDefault, AttrRegular},
|
|
|
|
Scrollbar: ColorAttr{colDefault, AttrRegular},
|
2022-10-30 00:12:01 +09:00
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
|
|
|
|
2017-01-11 23:01:56 +09:00
|
|
|
func errorExit(message string) {
|
|
|
|
fmt.Fprintln(os.Stderr, message)
|
2017-01-11 02:12:32 +09:00
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
|
2016-10-24 09:44:56 +09:00
|
|
|
func init() {
|
|
|
|
Default16 = &ColorTheme{
|
2020-10-25 19:29:37 +09:00
|
|
|
Colored: true,
|
|
|
|
Input: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
DarkBg: ColorAttr{colBlack, AttrUndefined},
|
|
|
|
Prompt: ColorAttr{colBlue, AttrUndefined},
|
|
|
|
Match: ColorAttr{colGreen, AttrUndefined},
|
|
|
|
Current: ColorAttr{colYellow, AttrUndefined},
|
|
|
|
CurrentMatch: ColorAttr{colGreen, AttrUndefined},
|
|
|
|
Spinner: ColorAttr{colGreen, AttrUndefined},
|
|
|
|
Info: ColorAttr{colWhite, AttrUndefined},
|
|
|
|
Cursor: ColorAttr{colRed, AttrUndefined},
|
|
|
|
Selected: ColorAttr{colMagenta, AttrUndefined},
|
|
|
|
Header: ColorAttr{colCyan, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
Border: ColorAttr{colBlack, AttrUndefined},
|
|
|
|
BorderLabel: ColorAttr{colWhite, AttrUndefined},
|
2022-12-10 16:55:19 +09:00
|
|
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
2023-01-01 17:38:34 +09:00
|
|
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
Dark256 = &ColorTheme{
|
2020-10-25 19:29:37 +09:00
|
|
|
Colored: true,
|
|
|
|
Input: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
DarkBg: ColorAttr{236, AttrUndefined},
|
|
|
|
Prompt: ColorAttr{110, AttrUndefined},
|
|
|
|
Match: ColorAttr{108, AttrUndefined},
|
|
|
|
Current: ColorAttr{254, AttrUndefined},
|
|
|
|
CurrentMatch: ColorAttr{151, AttrUndefined},
|
|
|
|
Spinner: ColorAttr{148, AttrUndefined},
|
|
|
|
Info: ColorAttr{144, AttrUndefined},
|
|
|
|
Cursor: ColorAttr{161, AttrUndefined},
|
|
|
|
Selected: ColorAttr{168, AttrUndefined},
|
|
|
|
Header: ColorAttr{109, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
Border: ColorAttr{59, AttrUndefined},
|
|
|
|
BorderLabel: ColorAttr{145, AttrUndefined},
|
2022-12-10 16:55:19 +09:00
|
|
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
2023-01-01 17:38:34 +09:00
|
|
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
Light256 = &ColorTheme{
|
2020-10-25 19:29:37 +09:00
|
|
|
Colored: true,
|
|
|
|
Input: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
|
|
|
DarkBg: ColorAttr{251, AttrUndefined},
|
|
|
|
Prompt: ColorAttr{25, AttrUndefined},
|
|
|
|
Match: ColorAttr{66, AttrUndefined},
|
|
|
|
Current: ColorAttr{237, AttrUndefined},
|
|
|
|
CurrentMatch: ColorAttr{23, AttrUndefined},
|
|
|
|
Spinner: ColorAttr{65, AttrUndefined},
|
|
|
|
Info: ColorAttr{101, AttrUndefined},
|
|
|
|
Cursor: ColorAttr{161, AttrUndefined},
|
|
|
|
Selected: ColorAttr{168, AttrUndefined},
|
|
|
|
Header: ColorAttr{31, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
Border: ColorAttr{145, AttrUndefined},
|
|
|
|
BorderLabel: ColorAttr{59, AttrUndefined},
|
2022-12-10 16:55:19 +09:00
|
|
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
2023-01-01 17:38:34 +09:00
|
|
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
|
|
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
2022-10-30 00:12:01 +09:00
|
|
|
}
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
|
|
|
|
if forceBlack {
|
2020-10-25 19:29:37 +09:00
|
|
|
theme.Bg = ColorAttr{colBlack, AttrUndefined}
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
|
|
|
|
2020-10-25 19:29:37 +09:00
|
|
|
o := func(a ColorAttr, b ColorAttr) ColorAttr {
|
|
|
|
c := a
|
|
|
|
if b.Color != colUndefined {
|
|
|
|
c.Color = b.Color
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
2020-10-25 19:29:37 +09:00
|
|
|
if b.Attr != AttrUndefined {
|
|
|
|
c.Attr = b.Attr
|
|
|
|
}
|
|
|
|
return c
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|
2020-10-25 19:29:37 +09:00
|
|
|
theme.Input = o(baseTheme.Input, theme.Input)
|
2016-10-24 09:44:56 +09:00
|
|
|
theme.Fg = o(baseTheme.Fg, theme.Fg)
|
|
|
|
theme.Bg = o(baseTheme.Bg, theme.Bg)
|
|
|
|
theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg)
|
|
|
|
theme.Prompt = o(baseTheme.Prompt, theme.Prompt)
|
|
|
|
theme.Match = o(baseTheme.Match, theme.Match)
|
|
|
|
theme.Current = o(baseTheme.Current, theme.Current)
|
|
|
|
theme.CurrentMatch = o(baseTheme.CurrentMatch, theme.CurrentMatch)
|
|
|
|
theme.Spinner = o(baseTheme.Spinner, theme.Spinner)
|
|
|
|
theme.Info = o(baseTheme.Info, theme.Info)
|
|
|
|
theme.Cursor = o(baseTheme.Cursor, theme.Cursor)
|
|
|
|
theme.Selected = o(baseTheme.Selected, theme.Selected)
|
|
|
|
theme.Header = o(baseTheme.Header, theme.Header)
|
|
|
|
theme.Border = o(baseTheme.Border, theme.Border)
|
2022-10-30 00:12:01 +09:00
|
|
|
theme.BorderLabel = o(baseTheme.BorderLabel, theme.BorderLabel)
|
2017-01-08 01:30:31 +09:00
|
|
|
|
2022-12-09 12:05:27 +09:00
|
|
|
// These colors are not defined in the base themes
|
|
|
|
theme.Disabled = o(theme.Input, theme.Disabled)
|
|
|
|
theme.Gutter = o(theme.DarkBg, theme.Gutter)
|
|
|
|
theme.PreviewFg = o(theme.Fg, theme.PreviewFg)
|
|
|
|
theme.PreviewBg = o(theme.Bg, theme.PreviewBg)
|
|
|
|
theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel)
|
2023-01-01 17:38:34 +09:00
|
|
|
theme.Separator = o(theme.Border, theme.Separator)
|
|
|
|
theme.Scrollbar = o(theme.Border, theme.Scrollbar)
|
2022-12-09 12:05:27 +09:00
|
|
|
|
2017-01-08 01:30:31 +09:00
|
|
|
initPalette(theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initPalette(theme *ColorTheme) {
|
2020-10-25 19:29:37 +09:00
|
|
|
pair := func(fg, bg ColorAttr) ColorPair {
|
2020-11-03 20:51:44 +09:00
|
|
|
if fg.Color == colDefault && (fg.Attr&Reverse) > 0 {
|
|
|
|
bg.Color = colDefault
|
|
|
|
}
|
2020-10-25 19:29:37 +09:00
|
|
|
return ColorPair{fg.Color, bg.Color, fg.Attr}
|
2017-01-08 01:30:31 +09:00
|
|
|
}
|
2020-10-25 19:29:37 +09:00
|
|
|
blank := theme.Fg
|
|
|
|
blank.Attr = AttrRegular
|
|
|
|
|
|
|
|
ColPrompt = pair(theme.Prompt, theme.Bg)
|
|
|
|
ColNormal = pair(theme.Fg, theme.Bg)
|
|
|
|
ColInput = pair(theme.Input, theme.Bg)
|
2021-01-03 00:00:40 +09:00
|
|
|
ColDisabled = pair(theme.Disabled, theme.Bg)
|
2020-10-25 19:29:37 +09:00
|
|
|
ColMatch = pair(theme.Match, theme.Bg)
|
|
|
|
ColCursor = pair(theme.Cursor, theme.Gutter)
|
|
|
|
ColCursorEmpty = pair(blank, theme.Gutter)
|
|
|
|
ColSelected = pair(theme.Selected, theme.Gutter)
|
|
|
|
ColCurrent = pair(theme.Current, theme.DarkBg)
|
|
|
|
ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)
|
|
|
|
ColCurrentCursor = pair(theme.Cursor, theme.DarkBg)
|
|
|
|
ColCurrentCursorEmpty = pair(blank, theme.DarkBg)
|
|
|
|
ColCurrentSelected = pair(theme.Selected, theme.DarkBg)
|
|
|
|
ColCurrentSelectedEmpty = pair(blank, theme.DarkBg)
|
|
|
|
ColSpinner = pair(theme.Spinner, theme.Bg)
|
|
|
|
ColInfo = pair(theme.Info, theme.Bg)
|
|
|
|
ColHeader = pair(theme.Header, theme.Bg)
|
2022-10-30 16:28:58 +09:00
|
|
|
ColSeparator = pair(theme.Separator, theme.Bg)
|
2023-01-01 14:48:14 +09:00
|
|
|
ColScrollbar = pair(theme.Scrollbar, theme.Bg)
|
2020-10-25 19:29:37 +09:00
|
|
|
ColBorder = pair(theme.Border, theme.Bg)
|
2022-10-30 00:12:01 +09:00
|
|
|
ColBorderLabel = pair(theme.BorderLabel, theme.Bg)
|
2022-12-09 12:05:27 +09:00
|
|
|
ColPreviewLabel = pair(theme.PreviewLabel, theme.PreviewBg)
|
2020-10-25 19:29:37 +09:00
|
|
|
ColPreview = pair(theme.PreviewFg, theme.PreviewBg)
|
|
|
|
ColPreviewBorder = pair(theme.Border, theme.PreviewBg)
|
2016-10-24 09:44:56 +09:00
|
|
|
}
|