add clipboard

添加剪切板功能
master
谢小军 5 years ago
parent 8585c30fbd
commit 82c7a46d92

@ -10,11 +10,11 @@ is_out_sql : false # 是否输出 sql 原信息
is_out_func : true # 是否输出 快捷函数
is_url_tag : true # 是否打web标记
is_foreign_key : true # 是否导出外键关联
is_gui : false # 是否ui模式显示
is_gui : true # 是否ui模式显示
mysql_info:
host : 127.0.0.1
port : 3306
username : root
password : qwer
database : oauth_db
database : apiserver_db

@ -4,12 +4,14 @@ import (
"fmt"
"log"
"strconv"
"strings"
"github.com/xxjwxc/public/tools"
"github.com/xxjwxc/gormt/data/config"
"github.com/jroimartin/gocui"
"github.com/xxjwxc/public/myclipboard"
"github.com/xxjwxc/public/mycui"
)
@ -77,7 +79,7 @@ func mainLayout(g *gocui.Gui) error {
// }
}
if v, err := g.SetView(_viewDefine, division(maxX, uiPart[0]), 1, maxX-1, maxY-1); err != nil {
if v, err := g.SetView(_viewDefine, division(maxX, uiPart[0]), 1, maxX-1, maxY-3); err != nil {
if err != gocui.ErrUnknownView {
return err
}
@ -103,6 +105,11 @@ func nemuLayOut(g *gocui.Gui) {
AddHandler(gocui.KeyArrowUp, menuDlg.prevButton).AddHandler(gocui.KeyArrowDown, menuDlg.nextButton).
AddHandler(gocui.KeyEnter, enterSet).AddHandler(gocui.MouseLeft, enterSet))
maxX, maxY := g.Size() // division(maxY, uiPart[1])
clipboardBtn = mycui.NewButton(g, _clipboardBtn, SLocalize(_clipboardBtn), division(maxX, uiPart[0])+2, maxY-3, 5).
AddHandler(gocui.KeyEnter, enterClipboard).AddHandler(gocui.MouseLeft, enterClipboard)
clipboardBtn.Draw()
menuDlg.Draw()
menuFocusButton(g)
}
@ -163,6 +170,24 @@ func addlog(g *gocui.Gui, str string) error {
return err
}
func enterClipboard(g *gocui.Gui, v *gocui.View) error {
myclipboard.Set(copyInfo)
maxX, _ := g.Size()
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).
SetTextColor(gocui.ColorRed).SetText("copy success \n 已 复 制 到 剪 切 板 ")
modal.Mouse = true
// modal.SetBgColor(gocui.ColorRed)
_handle := func(g *gocui.Gui, v *gocui.View) error {
modal.Close()
return nil
}
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
modal.Draw()
return nil
}
func enterRun(g *gocui.Gui, v *gocui.View) error {
setlog(g, "run .... ing")
generate(g, v)
@ -242,12 +267,14 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
port, err := strconv.Atoi(mp["db_port"])
if err != nil {
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).SetTextColor(gocui.ColorRed).SetText("port error")
// modal.SetBgColor(gocui.ColorRed)
modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error {
_handle := func(g *gocui.Gui, v *gocui.View) error {
modal.Close()
form.SetCurrentItem(form.GetCurrentItem())
return nil
})
}
// modal.SetBgColor(gocui.ColorRed)
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
modal.Draw()
return nil
@ -273,11 +300,12 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
config.SaveToFile()
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).SetText("save success")
modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error {
_handle := func(g *gocui.Gui, v *gocui.View) error {
modal.Close()
buttonCancel(g, v)
return nil
})
}
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
modal.Draw()
return nil
@ -306,10 +334,11 @@ func showStruct(g *gocui.Gui, v *gocui.View) error {
l = ""
}
var out []string
var out, out1 []string
for _, v := range gPkg.Structs {
if v.Name == l {
out = v.GeneratesColor()
out1 = v.Generates()
break
}
}
@ -318,6 +347,9 @@ func showStruct(g *gocui.Gui, v *gocui.View) error {
for _, v := range out {
addlog(g, v)
}
copyInfo = strings.Join(out1, "")
return nil
}

@ -6,15 +6,16 @@ import (
)
const (
_menuDefine = "menu"
_listDefine = "list"
_viewDefine = "view"
_run = "run"
_set = "set"
_menuDefine = "menu"
_listDefine = "list"
_viewDefine = "view"
_run = "run"
_set = "set"
_clipboardBtn = "clipboardBtn"
)
var (
uiPart = []float32{4, 3} // x,y 对应列表
uiPart = []float32{4, 5} // x,y 对应列表
mainViewArr = []string{_menuDefine, _listDefine, _viewDefine} // 主菜单列表
mainIndex = 0
@ -33,6 +34,9 @@ type listDetails struct {
btnList []*mycui.Button
}
var clipboardBtn *mycui.Button
var copyInfo string
var menuDlg *menuDetails
var form *mycui.Form
var gPkg genstruct.GenPackage

@ -47,6 +47,9 @@ func addChinese() error {
}, &i18n.Message{
ID: "set",
Other: "设 置 🛠 ",
}, &i18n.Message{
ID: "clipboardBtn",
Other: "复 制 到 剪 切 板 ",
}, &i18n.Message{
ID: "out_dir",
Other: " 输 出 目 录 :",
@ -135,6 +138,9 @@ func addEnglish() error {
}, &i18n.Message{
ID: "set",
Other: "Set 🛠 ",
}, &i18n.Message{
ID: "clipboardBtn",
Other: "Copy to clipboard",
}, &i18n.Message{
ID: "out_dir",
Other: "out dir:",

@ -12,7 +12,7 @@ require (
github.com/leodido/go-urn v1.2.0 // indirect
github.com/nicksnyder/go-i18n/v2 v2.0.3
github.com/spf13/cobra v0.0.5
github.com/xxjwxc/public v0.0.0-20200120133922-c61314a90a4a
github.com/xxjwxc/public v0.0.0-20200221114751-56810b3fcc29
golang.org/x/text v0.3.2
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.30.2

@ -11,6 +11,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/ant0ine/go-json-rest v3.3.2+incompatible/go.mod h1:q6aCt0GfU6LhpBsnZ/2U+mwe+0XB5WStbmwyoPfc+sk=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
@ -142,6 +144,8 @@ github.com/xxjwxc/public v0.0.0-20191107073037-ea6b812d567f/go.mod h1:j0CCXMUDty
github.com/xxjwxc/public v0.0.0-20200120133922-c61314a90a4a h1:sQ+O2UwDj1ShdZ6NLgp98cmaZLWrkFpVJB+wOzj1kDQ=
github.com/xxjwxc/public v0.0.0-20200120133922-c61314a90a4a/go.mod h1:UYQUNNJmUzNKpjY5ctz1n/XoJonmhAIgD51zS2rEsek=
github.com/xxjwxc/public v0.0.0-20200120153226-f36cf754df21 h1:1OF0Q6FGQhmziN4yvHLiF9XXOqfChL5z4rcogSQqCos=
github.com/xxjwxc/public v0.0.0-20200221114751-56810b3fcc29 h1:C0fnjiwnCBjovovCTkrjVXQtqd+UdVD2N8yaVK8LHwk=
github.com/xxjwxc/public v0.0.0-20200221114751-56810b3fcc29/go.mod h1:lhh94GsxhTweM/OaF7eFzOAgVV6fSSbBvA6zOtOVmdU=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

Loading…
Cancel
Save