update gui

更新ui展示
master
谢小军 5 years ago
parent b72a40e40e
commit bb224315a1

@ -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标签不输出)

@ -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

@ -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
}

@ -52,3 +52,11 @@ func requireValidator(value string) bool {
}
return true
}
func getBool(bstr string) bool {
if bstr == "true" || bstr == " 是" {
return true
}
return false
}

@ -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
}

@ -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",

@ -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
)

@ -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=

BIN
image/.DS_Store vendored

Binary file not shown.
Loading…
Cancel
Save