~taiite/senpai

70d519af99ea82a9552189980ccad6f8c29d2d94 — Alexey Yerin 11 months ago eafb0dd
Add colors.prompt option to set prompt color
3 files changed, 71 insertions(+), 2 deletions(-)

M app.go
M config.go
M doc/senpai.5.scd
M app.go => app.go +10 -2
@@ 70,7 70,11 @@ func NewApp(cfg Config) (app *App, err error) {
	if err != nil {
		return
	}
	app.win.SetPrompt(ui.PlainString(">"))
	app.win.SetPrompt(ui.Styled(">",
		tcell.
			StyleDefault.
			Foreground(tcell.Color(app.cfg.Colors.Prompt))),
	)

	app.initWindow()



@@ 787,7 791,11 @@ func (app *App) updatePrompt() {
	command := app.win.InputIsCommand()
	var prompt ui.StyledString
	if buffer == Home || command {
		prompt = ui.PlainString(">")
		prompt = ui.Styled(">",
			tcell.
				StyleDefault.
				Foreground(tcell.Color(app.cfg.Colors.Prompt)),
		)
	} else {
		prompt = identString(app.s.Nick())
	}

M config.go => config.go +42 -0
@@ 4,10 4,48 @@ import (
	"errors"
	"fmt"
	"io/ioutil"
	"strings"
	"strconv"

	"github.com/gdamore/tcell/v2"

	"gopkg.in/yaml.v2"
)

type Color tcell.Color

func (c *Color) UnmarshalText(data []byte) error {
	s := string(data)

	if strings.HasPrefix(s, "#") {
		hex, err := strconv.ParseInt(s[1:], 16, 32)
		if err != nil {
			return err
		}

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

	code, err := strconv.Atoi(s)
	if err != nil {
		return err
	}

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

	if code < 0 || code > 255 {
		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))

	return nil
}

type Config struct {
	Addr     string
	Nick     string


@@ 24,6 62,10 @@ type Config struct {
	NickColWidth int    `yaml:"nick-column-width"`
	ChanColWidth int    `yaml:"chan-column-width"`

	Colors struct {
		Prompt Color
	}

	Debug bool
}


M doc/senpai.5.scd => doc/senpai.5.scd +19 -0
@@ 70,6 70,25 @@ Some settings are required, the others are optional.
*mouse*
	Enable or disable mouse support.  Defaults to true.

*colors*
	Settings for colors of different UI elements.

	Colors are represented as numbers from 0 to 255 for 256 default terminal
	colors respectively. -1 has special meaning of default terminal color. To
	use true colors, *#*_rrggbb_ notation is supported.

	Colors are set as sub-options of the main *colors* option:

```
colors:
    prompt: 3 # green
```

[[ *Sub-option*
:< *Description*
|  prompt
:  color for ">"-prompt that appears in command mode

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