From 8901983ccc118b45af03f7e4b43676b38f585cee Mon Sep 17 00:00:00 2001 From: eeeXun Date: Mon, 24 Oct 2022 16:49:49 +0800 Subject: [PATCH] check borderColor changed --- color.go | 8 ++++++++ config.go | 14 +++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/color.go b/color.go index eac7abe..52fbf8f 100644 --- a/color.go +++ b/color.go @@ -95,6 +95,14 @@ func (s Style) DstBorderColor() tcell.Color { return Themes[theme][s.dst.borderColor] } +func (s Style) SrcBorderStr() string { + return s.src.borderColor +} + +func (s Style) DstBorderStr() string { + return s.dst.borderColor +} + func (s *Style) SetSrcBorderColor(color string) *Style { s.src.borderColor = color return s diff --git a/config.go b/config.go index 2f556e0..e54f3bc 100644 --- a/config.go +++ b/config.go @@ -23,8 +23,8 @@ func configInit() { config.Set("transparent", false) config.Set("theme", "Gruvbox") config.Set("source.language", "English") - config.Set("destination.language", "Chinese (Traditional)") config.Set("source.borderColor", "red") + config.Set("destination.language", "Chinese (Traditional)") config.Set("destination.borderColor", "blue") if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) { os.Mkdir(defaultConfigPath, os.ModePerm) @@ -37,8 +37,8 @@ func configInit() { transparent = config.GetBool("transparent") translator.srcLang = config.GetString("source.language") translator.dstLang = config.GetString("destination.language") - style.SetSrcBorderColor(config.GetString("source.borderColor")) - style.SetDstBorderColor(config.GetString("destination.borderColor")) + style.SetSrcBorderColor(config.GetString("source.borderColor")). + SetDstBorderColor(config.GetString("destination.borderColor")) } // Check if need to modify config file when quit program @@ -57,10 +57,18 @@ func updateConfig() { changed = true config.Set("source.language", translator.srcLang) } + if config.GetString("source.borderColor") != style.SrcBorderStr() { + changed = true + config.Set("source.borderColor", style.SrcBorderStr()) + } if config.GetString("destination.language") != translator.dstLang { changed = true config.Set("destination.language", translator.dstLang) } + if config.GetString("destination.borderColor") != style.DstBorderStr() { + changed = true + config.Set("destination.borderColor", style.DstBorderStr()) + } if changed { config.WriteConfig()