From bb224315a15271d465070c480447762bc43303cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B0=8F=E5=86=9B?= <346944475@qq.com> Date: Tue, 21 Jan 2020 17:36:22 +0800 Subject: [PATCH] update gui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新ui展示 --- config.yml | 2 +- data/config/MyIni.go | 18 ++++++++++++++++- data/config/common.go | 15 +++++++++++++- data/dlg/common.go | 8 ++++++++ data/dlg/cui.go | 44 +++++++++++++++++++++++++++++++++++++++++- data/dlg/i18n.go | 21 +++++++++++++++++++- go.mod | 1 + go.sum | 2 ++ image/.DS_Store | Bin 6148 -> 8196 bytes 9 files changed, 106 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index d9616f7..b5b41bf 100644 --- a/config.yml +++ b/config.yml @@ -2,7 +2,7 @@ base: is_dev : false out_dir : ./model # 输出目录 url_tag : json # web url tag(json,db(https://github.com/google/go-querystring)) -language : 中 文 # 语言(English,中 文) +language : # 语言(English,中 文) db_tag : gorm # 数据库标签(gorm,db) singular_table : false # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable simple : false # 简单输出(默认gorm标签不输出) diff --git a/data/config/MyIni.go b/data/config/MyIni.go index cddedcd..f95b17c 100644 --- a/data/config/MyIni.go +++ b/data/config/MyIni.go @@ -2,6 +2,8 @@ package config import ( "fmt" + + "github.com/xxjwxc/public/tools" ) // Config custom config struct @@ -76,6 +78,11 @@ func GetSimple() bool { return _map.Simple } +// SetSimple simple output.简单输出 +func SetSimple(b bool) { + _map.Simple = b +} + // GetIsJSONTag json tag.json标记 func GetIsJSONTag() bool { return _map.IsJSONTag @@ -91,6 +98,11 @@ func SetForeignKey(b bool) { _map.IsForeignKey = b } +// SetIsOutSQL if is output sql . +func SetIsOutSQL(b bool) { + _map.IsOutSQL = b +} + // GetIsOutSQL if is output sql . func GetIsOutSQL() bool { return _map.IsOutSQL @@ -133,7 +145,11 @@ func SetURLTag(s string) { // GetLG get language tag. func GetLG() string { if _map.Language != "English" && _map.Language != "中 文" { - _map.Language = "English" + if tools.GetLocalSystemLang(true) == "en" { + _map.Language = "English" + } else { + _map.Language = "中 文" + } } return _map.Language diff --git a/data/config/common.go b/data/config/common.go index 4b93253..3813dd1 100644 --- a/data/config/common.go +++ b/data/config/common.go @@ -6,7 +6,7 @@ import ( "github.com/xxjwxc/public/dev" "github.com/xxjwxc/public/tools" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // CfgBase base config struct @@ -65,3 +65,16 @@ func GetIsDev() bool { func SetIsDev(b bool) { _map.IsDev = b } + +// SaveToFile save config info to file +func SaveToFile() error { + d, err := yaml.Marshal(_map) + if err != nil { + return err + } + tools.WriteFile(tools.GetModelPath()+"/config.yml", []string{ + string(d), + }, true) + + return nil +} diff --git a/data/dlg/common.go b/data/dlg/common.go index a38120d..7ebc1e7 100644 --- a/data/dlg/common.go +++ b/data/dlg/common.go @@ -52,3 +52,11 @@ func requireValidator(value string) bool { } return true } + +func getBool(bstr string) bool { + if bstr == "true" || bstr == " 是" { + return true + } + + return false +} diff --git a/data/dlg/cui.go b/data/dlg/cui.go index 3e5a1ab..db2bc3d 100644 --- a/data/dlg/cui.go +++ b/data/dlg/cui.go @@ -3,6 +3,7 @@ package dlg import ( "fmt" "log" + "strconv" "github.com/xxjwxc/public/tools" @@ -190,6 +191,7 @@ func enterSet(g *gocui.Gui, v *gocui.View) error { // add button form.AddButton("save", SLocalize("save"), buttonSave).AddHandler(gocui.MouseLeft, buttonSave) form.AddButton("cancel", SLocalize("cancel"), buttonCancel).AddHandler(gocui.MouseLeft, buttonCancel) + form.AddButton("about", SLocalize("about"), about).AddHandler(gocui.MouseLeft, about) form.Draw() @@ -199,12 +201,52 @@ func enterSet(g *gocui.Gui, v *gocui.View) error { func buttonCancel(g *gocui.Gui, v *gocui.View) error { menuFocusButton(g) if form != nil { - return form.Close(g, nil) + err := form.Close(g, nil) + form = nil + return err } return nil } func buttonSave(g *gocui.Gui, v *gocui.View) error { + + mp := form.GetFieldTexts() + config.SetOutDir(mp["out_dir"]) + + var dbInfo config.MysqlDbInfo + dbInfo.Host = mp["db_host"] + port, err := strconv.Atoi(mp["db_port"]) + if err != nil { + modal := mycui.NewModal(g, 0, 0, 30).SetText("port error") + modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error { + modal.Close() + form.SetCurrentItem(form.GetCurrentItem()) + return nil + }) + + modal.Draw() + return nil + } + + dbInfo.Port = port + dbInfo.Username = mp["db_usename"] + dbInfo.Password = mp["db_pwd"] + dbInfo.Database = mp["db_name"] + + config.SetMysqlDbInfo(&dbInfo) + mp = form.GetSelectedOpts() + config.SetIsDev(getBool(mp["is_dev"])) + config.SetSimple(getBool(mp["is_simple"])) + config.SetSingularTable(getBool(mp["is_singular"])) + config.SetIsOutSQL(getBool(mp["is_out_sql"])) + config.SetIsOutFunc(getBool(mp["is_out_func"])) + config.SetForeignKey(getBool(mp["is_foreign_key"])) + config.SetURLTag(mp["url_tag"]) + config.SetDBTag(mp["db_tag"]) + config.SetLG(mp["language"]) + + config.SaveToFile() + buttonCancel(g, v) return nil } diff --git a/data/dlg/i18n.go b/data/dlg/i18n.go index 89a58ca..e65e70e 100644 --- a/data/dlg/i18n.go +++ b/data/dlg/i18n.go @@ -2,6 +2,7 @@ package dlg import ( "github.com/nicksnyder/go-i18n/v2/i18n" + "github.com/xxjwxc/gormt/data/config" "github.com/xxjwxc/public/myi18n" "golang.org/x/text/language" ) @@ -13,7 +14,19 @@ import ( func init() { addChinese() addEnglish() - myi18n.SetLocalLG("zh") // default + myi18n.SetLocalLG(getLG()) // default +} + +func getLG() string { + tag := config.GetLG() + // if len(tag) == 0 { + // return tools.GetLocalSystemLang(true) + // } + if tag == "English" { + return "en" + } + + return "zh" } // SLocalize 获取值 @@ -94,6 +107,9 @@ func addChinese() error { }, &i18n.Message{ ID: "cancel", Other: " 取 消 ", + }, &i18n.Message{ + ID: "about", + Other: " 关 于 作 者", }, &i18n.Message{ ID: "log_run", Other: " Enter : 执 行 \n ↑ ↓: 本 视 图 选 择 \n Tab : 多 视 图 切 换 \n 支 持 鼠 标 操 作 方 式 \n \n \033[33;7m 输 入 Enter 直 接 执 行 \033[0m\n ", @@ -176,6 +192,9 @@ func addEnglish() error { }, &i18n.Message{ ID: "cancel", Other: "Cancel", + }, &i18n.Message{ + ID: "about", + Other: "About", }, &i18n.Message{ ID: "log_run", Other: " Enter : run \n ↑ ↓: Selection of this view \n Tab : Multi view switching \n Mouse operation supported \n \n \033[33;7m Enter to execute \033[0m", diff --git a/go.mod b/go.mod index 008bd6a..cbb2419 100644 --- a/go.mod +++ b/go.mod @@ -17,4 +17,5 @@ require ( gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.30.2 gopkg.in/yaml.v2 v2.2.7 + gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 ) diff --git a/go.sum b/go.sum index bd5ea47..fc10f7c 100644 --- a/go.sum +++ b/go.sum @@ -213,6 +213,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 h1:XZx7nhd5GMaZpmDaEHFVafUZC7ya0fuo7cSJ3UCKYmM= +gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/image/.DS_Store b/image/.DS_Store index b91b279fe8b7d41ae4ff73fe5964cb93264272fe..d0b340a0a63c43d04ef20397e9bb985d390d9011 100644 GIT binary patch literal 8196 zcmeHMO>Epm6n<}$G`8Ckr?ic`31uOKwrSF4o93^iWs^;shEfvP{A}CMjdyJl3$LB7 zy_+T>)mCsUf8tMokWj^m6mcpCIB)?05)vRPQ8;ixz<~=_4hY_Oyit=h2QGjbk2Lem z%zJNV-kZ-JJud)YZ(fT6C;%W(Whif^<`#v?SzS{?{!BR`l0AT%o^@u@rk!4+8%zWd z2qF+fAc#N^fgl3^j|kA6&5E$jz0ajV8$=+8z=n(fdp|^|GK~3HtcQDCn(Db`eh< zFvc-xg9ro>SQ`QM_*B3Y*pP$liv0bH^o(gZZcEE|7%D5T*igtJIhAHsym(b`y;k(F89^+n4!<67+6-ZdjT<+iT}7&GCLG z!3BaK3SvrD78auIZB3D`*2SjCLNwae*%WDSi7qaRLQO;T=-^~_ZhqmZ#fz_Vuh4%p zK-DTQ-&pCQ=@jDp6GdpQEzi=wnyIX-YgO3B*_wDX}E*RU;TOwT!lDY?oaZwE8B zHJsC#d^}^D`K;xnOH2JFy?h9>FO6;);r_aIXCVpCJnM>b17NQJNjcf z85jkLAM z#N?CyWM`M8Br|q4ORhN8*yK+iJ*Ft<*vb#9jyp7?TePds{pEXUSEre*N7LAzg!hTi~FzCW{7H|&d zaRHyfm+%#Q6<@=*@m*ZPtN0#%fFI!}d~2Z+B_HDBQj4Eb@201YDCvJS3!S?aCByy4 z2mT{Ue!qqD@XqZ!cGvIO-_myE!R2#Yb#g1nbu*tl5^?yIsJICw9)?MLR>8=u) zSCf2{_@-YF7-{56t{n;AD-cg)!5c~qVNoP9b6G>UQ4r)1mo$eDio{;IjLQy5hXvxP zT*0LsQkO_fmdm-cTRJ8XVdYI++9Sn9_Dsp}&zW}xmf%BT-M4T9ek8{IMr`|om{y6^ z9@A>E4tL`oVp}8b$7XED4(uYv#j%eVH-N+VC?;?O$1vryPDcxEJdZhaaS< zcp0C?7w|=5;mi0IUcseRyc;Yrjw4=O$-6=#XPLG&MYAQQt~3Znw{rx_xN{22|NGbf z{(n1%An+}Sz=n?imiHz4dMOO+T>>oEj!>PX$_mpfa`a57@zQZZFC8ab{=<;^5mIF~ cF&~Q@X@<(b{vjZ^|Ch79;Qse0xFMUr0kGo99RL6T delta 131 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGqg=C6q~50D9i|C12Isnq%627FDE}QePW>| zBje^@qP$ES8}e8evvY6=GJ~`LRdE9eS0HZNSoocJGQW&2CrJMRAZD0s!z0bZ1hD~R LDZ}P?o*B#l_AVBB