ソースを参照

refactor!: rename preset to set

ayn2op 11 ヶ月 前
コミット
bc1b3210e3
7 ファイル変更39 行追加110 行削除
  1. 0 14
      cmd/root.go
  2. 1 1
      go.mod
  3. 6 0
      go.sum
  4. 0 80
      internal/config/border.go
  5. 2 2
      internal/config/config.toml
  6. 28 12
      internal/config/theme.go
  7. 2 1
      internal/ui/util.go

+ 0 - 14
cmd/root.go

@@ -66,20 +66,6 @@ func Run() error {
 
 	tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(cfg.Theme.BackgroundColor)
 
-	tview.BordersSet.Horizontal = cfg.Theme.Border.Preset.Horizontal
-	tview.BordersSet.Vertical = cfg.Theme.Border.Preset.Vertical
-	tview.BordersSet.TopLeft = cfg.Theme.Border.Preset.TopLeft
-	tview.BordersSet.TopRight = cfg.Theme.Border.Preset.TopRight
-	tview.BordersSet.BottomLeft = cfg.Theme.Border.Preset.BottomLeft
-	tview.BordersSet.BottomRight = cfg.Theme.Border.Preset.BottomRight
-
-	tview.BordersSet.HorizontalFocus = tview.BordersSet.Horizontal
-	tview.BordersSet.VerticalFocus = tview.BordersSet.Vertical
-	tview.BordersSet.TopLeftFocus = tview.BordersSet.TopLeft
-	tview.BordersSet.TopRightFocus = tview.BordersSet.TopRight
-	tview.BordersSet.BottomLeftFocus = tview.BordersSet.BottomLeft
-	tview.BordersSet.BottomRightFocus = tview.BordersSet.BottomRight
-
 	app = newApp(cfg)
 	return app.run(tok)
 }

+ 1 - 1
go.mod

@@ -5,7 +5,7 @@ go 1.24.3
 require (
 	github.com/BurntSushi/toml v1.5.0
 	github.com/atotto/clipboard v0.1.4
-	github.com/ayn2op/tview v0.0.0-20250604005524-8552f0de0246
+	github.com/ayn2op/tview v0.0.0-20250604164208-f35b68433444
 	github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb
 	github.com/diamondburned/arikawa/v3 v3.5.0
 	github.com/diamondburned/ningen/v3 v3.0.1-0.20240808103805-f1a24c0da3d8

+ 6 - 0
go.sum

@@ -29,6 +29,12 @@ github.com/ayn2op/tview v0.0.0-20250603214911-09c86784a7ad h1:CHZg56bCe8yesbr3sm
 github.com/ayn2op/tview v0.0.0-20250603214911-09c86784a7ad/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
 github.com/ayn2op/tview v0.0.0-20250604005524-8552f0de0246 h1:C4r5c5yziN6T/FzQOeF3u/w3v4ljMKYcuyBl/AHBQtw=
 github.com/ayn2op/tview v0.0.0-20250604005524-8552f0de0246/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
+github.com/ayn2op/tview v0.0.0-20250604012305-921a7dd5946a h1:Gpc6yEJROflSkIcfAPDrZYrzk12qxNaoWaIkAqRI1JA=
+github.com/ayn2op/tview v0.0.0-20250604012305-921a7dd5946a/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
+github.com/ayn2op/tview v0.0.0-20250604021041-0c2f681c1fe0 h1:vH1ZANNh/0Sj3UEJRFOmVhSz4Z4uQ66F7ijFMGEj/tw=
+github.com/ayn2op/tview v0.0.0-20250604021041-0c2f681c1fe0/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
+github.com/ayn2op/tview v0.0.0-20250604164208-f35b68433444 h1:0k9W/ygZ7zmXuyzVPFitjcfcBPJoGRbJwa8SHvZXm0s=
+github.com/ayn2op/tview v0.0.0-20250604164208-f35b68433444/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
 github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

+ 0 - 80
internal/config/border.go

@@ -1,80 +0,0 @@
-package config
-
-import "github.com/ayn2op/tview"
-
-type BorderPreset struct {
-	Horizontal  rune
-	Vertical    rune
-	TopLeft     rune
-	TopRight    rune
-	BottomLeft  rune
-	BottomRight rune
-}
-
-func (p *BorderPreset) UnmarshalTOML(v any) error {
-	switch v.(string) {
-	case "double":
-		*p = borderPresetDouble()
-	case "thick":
-		*p = borderPresetThick()
-	case "round":
-		*p = borderPresetRound()
-	case "light":
-		*p = borderPresetLight()
-	case "hidden":
-		*p = BorderPreset{
-			Horizontal:  ' ',
-			Vertical:    ' ',
-			TopLeft:     ' ',
-			TopRight:    ' ',
-			BottomLeft:  ' ',
-			BottomRight: ' ',
-		}
-	}
-
-	return nil
-}
-
-func borderPresetDouble() BorderPreset {
-	return BorderPreset{
-		Horizontal:  tview.BoxDrawingsDoubleHorizontal,
-		Vertical:    tview.BoxDrawingsDoubleVertical,
-		TopLeft:     tview.BoxDrawingsDoubleDownAndRight,
-		TopRight:    tview.BoxDrawingsDoubleDownAndLeft,
-		BottomLeft:  tview.BoxDrawingsDoubleUpAndRight,
-		BottomRight: tview.BoxDrawingsDoubleUpAndLeft,
-	}
-}
-
-func borderPresetThick() BorderPreset {
-	return BorderPreset{
-		Horizontal:  tview.BoxDrawingsHeavyHorizontal,
-		Vertical:    tview.BoxDrawingsHeavyVertical,
-		TopLeft:     tview.BoxDrawingsHeavyDownAndRight,
-		TopRight:    tview.BoxDrawingsHeavyDownAndLeft,
-		BottomLeft:  tview.BoxDrawingsHeavyUpAndRight,
-		BottomRight: tview.BoxDrawingsHeavyUpAndLeft,
-	}
-}
-
-func borderPresetRound() BorderPreset {
-	return BorderPreset{
-		Horizontal:  tview.BoxDrawingsLightHorizontal,
-		Vertical:    tview.BoxDrawingsLightVertical,
-		TopLeft:     tview.BoxDrawingsLightArcDownAndRight,
-		TopRight:    tview.BoxDrawingsLightArcDownAndLeft,
-		BottomLeft:  tview.BoxDrawingsLightArcUpAndRight,
-		BottomRight: tview.BoxDrawingsLightArcUpAndLeft,
-	}
-}
-
-func borderPresetLight() BorderPreset {
-	return BorderPreset{
-		Horizontal:  tview.BoxDrawingsLightHorizontal,
-		Vertical:    tview.BoxDrawingsLightVertical,
-		TopLeft:     tview.BoxDrawingsLightDownAndRight,
-		TopRight:    tview.BoxDrawingsLightDownAndLeft,
-		BottomLeft:  tview.BoxDrawingsLightUpAndRight,
-		BottomRight: tview.BoxDrawingsLightUpAndLeft,
-	}
-}

+ 2 - 2
internal/config/config.toml

@@ -98,15 +98,15 @@ background_color = "default"
 color = "default"
 # Title color of the focused widget
 active_color = "green"
-align = "left"
+alignment = "left"
 
 [theme.border]
 enabled = true
 # [top, bottom, left, right]
 padding = [0, 0, 1, 1]
+set = "round"
 color = "default"
 active_color = "green"
-preset = "round"
 
 [theme.guilds_tree]
 auto_expand_folders = true

+ 28 - 12
internal/config/theme.go

@@ -4,16 +4,33 @@ import (
 	"github.com/ayn2op/tview"
 )
 
-type TitleAlign int
+type BorderSetWrapper struct{ tview.BorderSet }
 
-func (ta *TitleAlign) UnmarshalTOML(v any) error {
+func (bw *BorderSetWrapper) UnmarshalTOML(v any) error {
+	switch v.(string) {
+	case "plain":
+		bw.BorderSet = tview.BorderSetPlain()
+	case "round":
+		bw.BorderSet = tview.BorderSetRound()
+	case "thick":
+		bw.BorderSet = tview.BorderSetThick()
+	case "double":
+		bw.BorderSet = tview.BorderSetDouble()
+	}
+
+	return nil
+}
+
+type AlignmentWrapper struct{ tview.Alignment }
+
+func (aw *AlignmentWrapper) UnmarshalTOML(v any) error {
 	switch v.(string) {
 	case "left":
-		*ta = tview.AlignLeft
+		aw.Alignment = tview.AlignmentLeft
 	case "center":
-		*ta = tview.AlignCenter
+		aw.Alignment = tview.AlignmentCenter
 	case "right":
-		*ta = tview.AlignRight
+		aw.Alignment = tview.AlignmentRight
 	}
 
 	return nil
@@ -21,19 +38,18 @@ func (ta *TitleAlign) UnmarshalTOML(v any) error {
 
 type (
 	BorderTheme struct {
-		Enabled bool   `toml:"enabled"`
-		Padding [4]int `toml:"padding"`
+		Enabled bool             `toml:"enabled"`
+		Padding [4]int           `toml:"padding"`
+		Set     BorderSetWrapper `toml:"set"`
 
 		Color       string `toml:"color"`
 		ActiveColor string `toml:"active_color"`
-
-		Preset BorderPreset `toml:"preset"`
 	}
 
 	TitleTheme struct {
-		Color       string     `toml:"color"`
-		ActiveColor string     `toml:"active_color"`
-		Align       TitleAlign `toml:"align"`
+		Color       string           `toml:"color"`
+		ActiveColor string           `toml:"active_color"`
+		Alignment   AlignmentWrapper `toml:"alignment"`
 	}
 
 	Theme struct {

+ 2 - 1
internal/ui/util.go

@@ -11,8 +11,9 @@ func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box {
 	t := cfg.Title
 	p := b.Padding
 	box.
+		SetBorderSet(b.Set.BorderSet).
 		SetBorderPadding(p[0], p[1], p[2], p[3]).
-		SetTitleAlign(int(t.Align)).
+		SetTitleAlignment(t.Alignment.Alignment).
 		SetFocusFunc(func() {
 			borderColor := tcell.GetColor(b.ActiveColor)
 			box.SetBorderStyle(tcell.StyleDefault.Foreground(borderColor))