~taiite/senpai

80d5d8b35b450f7183fd46beedd7316f307c2b8d — Tim Culverhouse a month ago 7c18ce7
Add a config option for unread buffer text color

This patch adds the ability to set a config option for changing the
foreground text color of unread buffers

(This was refactored slightly by delthas.)
5 files changed, 37 insertions(+), 20 deletions(-)

M app.go
M config.go
M doc/senpai.5.scd
M ui/buffers.go
M ui/ui.go
M app.go => app.go +3 -0
@@ 134,6 134,9 @@ func NewApp(cfg Config) (app *App, err error) {
		MergeLine: func(former *ui.Line, addition ui.Line) {
			app.mergeLine(former, addition)
		},
		Colors: ui.ConfigColors{
			Unread: cfg.Colors.Unread,
		},
	})
	if err != nil {
		return

M config.go => config.go +20 -16
@@ 14,16 14,14 @@ import (
	"git.sr.ht/~emersion/go-scfg"
)

type Color tcell.Color

func parseColor(s string, c *Color) error {
func parseColor(s string, c *tcell.Color) error {
	if strings.HasPrefix(s, "#") {
		hex, err := strconv.ParseInt(s[1:], 16, 32)
		if err != nil {
			return err
		}

		*c = Color(tcell.NewHexColor(int32(hex)))
		*c = tcell.NewHexColor(int32(hex))
		return nil
	}



@@ 33,7 31,7 @@ func parseColor(s string, c *Color) error {
	}

	if code == -1 {
		*c = Color(tcell.ColorDefault)
		*c = tcell.ColorDefault
		return nil
	}



@@ 41,13 39,14 @@ func parseColor(s string, c *Color) error {
		return fmt.Errorf("color code must be between 0-255. If you meant to use true colors, use #aabbcc notation")
	}

	*c = Color(tcell.PaletteColor(code))
	*c = tcell.PaletteColor(code)

	return nil
}

type ConfigColors struct {
	Prompt Color
	Prompt tcell.Color
	Unread tcell.Color
}

type Config struct {


@@ 102,7 101,8 @@ func Defaults() (cfg Config, err error) {
		MemberColWidth:   16,
		MemberColEnabled: true,
		Colors: ConfigColors{
			Prompt: Color(tcell.ColorDefault),
			Prompt: tcell.ColorDefault,
			Unread: tcell.ColorDefault,
		},
		Debug: false,
	}


@@ 268,16 268,20 @@ func unmarshal(filename string, cfg *Config) (err error) {
			}
		case "colors":
			for _, child := range d.Children {
				var colorStr string
				if err := child.ParseParams(&colorStr); err != nil {
					return err
				}

				var color tcell.Color
				if err = parseColor(colorStr, &color); err != nil {
					return err
				}
				switch child.Name {
				case "prompt":
					var prompt string
					if err := child.ParseParams(&prompt); err != nil {
						return err
					}

					if err = parseColor(prompt, &cfg.Colors.Prompt); err != nil {
						return err
					}
					cfg.Colors.Prompt = color
				case "unread":
					cfg.Colors.Unread = color
				default:
					return fmt.Errorf("unknown directive %q", child.Name)
				}

M doc/senpai.5.scd => doc/senpai.5.scd +2 -0
@@ 150,6 150,8 @@ colors {
:< *Description*
|  prompt
:  color for ">"-prompt that appears in command mode
|  unread
:  foreground color for unread buffer names in buffer lists

*debug*
	Dump all sent and received data to the home buffer, useful for debugging.

M ui/buffers.go => ui/buffers.go +6 -3
@@ 195,6 195,8 @@ type buffer struct {
}

type BufferList struct {
	colors ConfigColors

	list    []buffer
	overlay *buffer
	current int


@@ 210,8 212,9 @@ type BufferList struct {

// NewBufferList returns a new BufferList.
// Call Resize() once before using it.
func NewBufferList(mergeLine func(*Line, Line)) BufferList {
func NewBufferList(colors ConfigColors, mergeLine func(*Line, Line)) BufferList {
	return BufferList{
		colors:      colors,
		list:        []buffer{},
		clicked:     -1,
		doMergeLine: mergeLine,


@@ 550,7 553,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
		y := y0 + i
		st := tcell.StyleDefault
		if b.unread {
			st = st.Bold(true)
			st = st.Bold(true).Foreground(bs.colors.Unread)
		}
		if bi == bs.current || bi == bs.clicked {
			st = st.Reverse(true)


@@ 644,7 647,7 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt
		}
		st := tcell.StyleDefault
		if b.unread {
			st = st.Bold(true)
			st = st.Bold(true).Foreground(bs.colors.Unread)
		} else if i == bs.current {
			st = st.Underline(true)
		}

M ui/ui.go => ui/ui.go +6 -1
@@ 19,6 19,11 @@ type Config struct {
	AutoComplete     func(cursorIdx int, text []rune) []Completion
	Mouse            bool
	MergeLine        func(former *Line, addition Line)
	Colors           ConfigColors
}

type ConfigColors struct {
	Unread tcell.Color
}

type UI struct {


@@ 84,7 89,7 @@ func New(config Config) (ui *UI, err error) {
		close(ui.Events)
	}()

	ui.bs = NewBufferList(ui.config.MergeLine)
	ui.bs = NewBufferList(config.Colors, ui.config.MergeLine)
	ui.e = NewEditor(ui.config.AutoComplete)
	ui.Resize()