summaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-04-16 11:44:28 +0200
committerxengineering <me@xengineering.eu>2023-04-16 11:44:28 +0200
commit59c7f02ad05af0223a08f47e3193c331a86445d5 (patch)
tree0079097fd9eea7c09067c2acf7cc978322db3fc2 /go
parent70456216ebbcc7e5006b6a005c571457e60be6e7 (diff)
downloadlimox-59c7f02ad05af0223a08f47e3193c331a86445d5.tar
limox-59c7f02ad05af0223a08f47e3193c331a86445d5.tar.zst
limox-59c7f02ad05af0223a08f47e3193c331a86445d5.zip
Switch completely to Go and Gio UI
The properties of the Go language, standard library and the Gio UI library are well suited for this project. The existing experimental Go code exceeds the GTK4 and SDL attempts by far with respect to quality and code simplicity.
Diffstat (limited to 'go')
-rw-r--r--go/go.mod17
-rw-r--r--go/go.sum34
-rw-r--r--go/main.go249
3 files changed, 0 insertions, 300 deletions
diff --git a/go/go.mod b/go/go.mod
deleted file mode 100644
index de2e3d7..0000000
--- a/go/go.mod
+++ /dev/null
@@ -1,17 +0,0 @@
-module xengineering.eu/limox
-
-go 1.20
-
-require gioui.org v0.0.0-20230206180804-32c6a9b10d0b
-
-require (
- gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
- gioui.org/shader v1.0.6 // indirect
- github.com/benoitkugler/textlayout v0.3.0 // indirect
- github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 // indirect
- golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
- golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect
- golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect
- golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
- golang.org/x/text v0.3.7 // indirect
-)
diff --git a/go/go.sum b/go/go.sum
deleted file mode 100644
index 4d42bf4..0000000
--- a/go/go.sum
+++ /dev/null
@@ -1,34 +0,0 @@
-eliasnaur.com/font v0.0.0-20220124212145-832bb8fc08c3 h1:djFprmHZgrSepsHAIRMp5UJn3PzsoTg9drI+BDmif5Q=
-gioui.org v0.0.0-20230206180804-32c6a9b10d0b h1:ghRvtb24ItyA7QffjaG38gH5f7bzagcz0OPq3T3FyHI=
-gioui.org v0.0.0-20230206180804-32c6a9b10d0b/go.mod h1:3lLo7xMHYnnHTrgKNNctBjEKKH3wQCO2Sn7ti5Jy8mU=
-gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
-gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc=
-gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
-gioui.org/shader v1.0.6 h1:cvZmU+eODFR2545X+/8XucgZdTtEjR3QWW6W65b0q5Y=
-gioui.org/shader v1.0.6/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
-github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE=
-github.com/benoitkugler/textlayout v0.3.0 h1:2ehWXEkgb6RUokTjXh1LzdGwG4dRP6X3dqhYYDYhUVk=
-github.com/benoitkugler/textlayout v0.3.0/go.mod h1:o+1hFV+JSHBC9qNLIuwVoLedERU7sBPgEFcuSgfvi/w=
-github.com/benoitkugler/textlayout-testdata v0.1.1 h1:AvFxBxpfrQd8v55qH59mZOJOQjtD6K2SFe9/HvnIbJk=
-github.com/benoitkugler/textlayout-testdata v0.1.1/go.mod h1:i/qZl09BbUOtd7Bu/W1CAubRwTWrEXWq6JwMkw8wYxo=
-github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 h1:iOA0HmtpANn48hX2nlDNMu0VVaNza35HJG0WeetBVzQ=
-github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5/go.mod h1:/cmOXaoTiO+lbCwkTZBgCvevJpbFsZ5reXIpEJVh5MI=
-golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg=
-golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
-golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0=
-golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
-golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
-golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
-golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 h1:/eM0PCrQI2xd471rI+snWuu251/+/jpBpZqir2mPdnU=
-golang.org/x/image v0.0.0-20220722155232-062f8c9fd539/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
-golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
-golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
-golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/go/main.go b/go/main.go
deleted file mode 100644
index 2803e68..0000000
--- a/go/main.go
+++ /dev/null
@@ -1,249 +0,0 @@
-package main
-
-import (
- "image/color"
- "log"
- "net"
- "os"
- "reflect"
-
- "gioui.org/app"
- "gioui.org/font/gofont"
- "gioui.org/io/system"
- "gioui.org/layout"
- "gioui.org/op"
- "gioui.org/text"
- "gioui.org/unit"
- "gioui.org/widget"
- "gioui.org/widget/material"
-)
-
-type XmppEvent uint8
-
-const (
- XmppDisconnect XmppEvent = iota
- XmppConnect
-)
-
-type GuiEvent uint8
-
-const (
- Disconnect GuiEvent = iota
-)
-
-type LimoxState uint8
-
-const (
- Disconnected LimoxState = iota
- Connecting
- Connected
-)
-
-type Limox struct {
- JidEditor widget.Editor
- PwdEditor widget.Editor
- MainButton widget.Clickable
- XmppEvents chan any
- GuiEvents chan GuiEvent
- State LimoxState
- Window *app.Window
- Operations op.Ops
- Theme *material.Theme
-}
-
-func main() {
- limox := NewLimox()
-
- go func() {
- err := limox.run()
- if err != nil {
- log.Fatal(err)
- }
- os.Exit(0)
- }()
-
- app.Main()
-}
-
-func NewLimox() Limox {
- return Limox{
- Window: app.NewWindow(
- app.Title("LimoX"),
- app.Size(unit.Dp(400), unit.Dp(600)),
- ),
- Operations: op.Ops{},
- Theme: material.NewTheme(gofont.Collection()),
- XmppEvents: make(chan any),
- GuiEvents: make(chan GuiEvent),
- State: Disconnected,
- }
-}
-
-func (l *Limox) run() error {
- for {
- select {
- case e := <-l.Window.Events():
- switch e := e.(type) {
- case system.DestroyEvent:
- return e.Err
- case system.FrameEvent:
- if l.MainButton.Clicked() {
- l.buttonCallback()
- }
- l.draw(e)
- }
- case ev := <-l.XmppEvents:
- switch ev.(type) {
- case error:
- log.Print(ev)
- l.State = Disconnected
- case XmppEvent:
- switch ev {
- case XmppDisconnect:
- l.State = Disconnected
- case XmppConnect:
- l.State = Connected
- default:
- log.Fatalf("Unknown XmppEvent '%d'\n", ev)
- }
- default:
- log.Fatalf("Unknown event type '%s'.\n", reflect.TypeOf(ev))
- }
- }
- }
-}
-
-func (l *Limox) buttonCallback() {
- switch l.State {
- case Disconnected:
- log.Println("Starting connection establishment")
- go l.xmpp(l.JidEditor.Text(), l.PwdEditor.Text())
- l.State = Connecting
- case Connecting:
- log.Println("Aborted connection establishment")
- l.State = Disconnected
- case Connected:
- log.Println("Disconnected")
- l.GuiEvents <- Disconnect
- l.State = Disconnected
- }
-}
-
-func (l *Limox) xmpp(jid string, pwd string) {
- log.Printf("JID: '%s' PWD: '%s'\n", jid, pwd)
-
- domain := domainpart(jid)
- log.Printf("Domain: '%s'\n", domain)
-
- tcpServer, err := net.ResolveTCPAddr("tcp", domain+":"+"5222")
- if err != nil {
- l.XmppEvents <- err
- return
- }
- log.Printf("Server: %s\n", tcpServer)
-
- conn, err := net.DialTCP("tcp", nil, tcpServer)
- if err != nil {
- l.XmppEvents <- err
- return
- }
- l.XmppEvents <- XmppConnect
-
- var closing bool = false
- for {
- ev := <-l.GuiEvents
- switch ev {
- case Disconnect:
- closing = true
- default:
- log.Fatalf("Unknown GuiEvent '%d'!\n", ev)
- }
- if closing {
- break
- }
- }
-
- conn.Close()
- l.XmppEvents <- XmppDisconnect
-}
-
-// domainpart extracts the domain name from a JID / XMPP address. See
-// https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details.
-func domainpart(jid string) string {
- list := []rune(jid)
-
- for i, v := range list {
- if v == '/' {
- list = list[:i]
- break
- }
- }
-
- for i, v := range list {
- if v == '@' {
- list = list[i+1:]
- break
- }
- }
-
- return string(list)
-}
-
-func (l *Limox) draw(e system.FrameEvent) {
- gtx := layout.NewContext(&l.Operations, e)
-
- flex := layout.Flex{
- Axis: layout.Vertical,
- Spacing: layout.SpaceBetween,
- }
-
- flex.Layout(gtx,
- layout.Rigid(
- func(gtx layout.Context) layout.Dimensions {
- h2 := material.H2(l.Theme, "LimoX")
- h2.Color = color.NRGBA{R: 20, G: 20, B: 20, A: 255}
- h2.Alignment = text.Middle
- return h2.Layout(gtx)
- },
- ),
- layout.Rigid(
- func(gtx layout.Context) layout.Dimensions {
- jid := material.Editor(l.Theme, &l.JidEditor, "user@example.com")
- jid.Editor.Alignment = text.Middle
- return jid.Layout(gtx)
- },
- ),
- layout.Rigid(
- func(gtx layout.Context) layout.Dimensions {
- pwd := material.Editor(l.Theme, &l.PwdEditor, "mySafePassword")
- pwd.Editor.Alignment = text.Middle
- pwd.Editor.Mask = '*'
- return pwd.Layout(gtx)
- },
- ),
- layout.Rigid(
- func(gtx layout.Context) layout.Dimensions {
- btn := material.Button(l.Theme, &l.MainButton,
- l.buttonLabel())
- return btn.Layout(gtx)
- },
- ),
- )
-
- e.Frame(gtx.Ops)
-}
-
-func (l *Limox) buttonLabel() string {
- var label string
- switch l.State {
- case Disconnected:
- label = "Connect"
- case Connecting:
- label = "Abort"
- case Connected:
- label = "Disconnect"
- default:
- log.Fatalf("Unknown Limox state '%d'\n", l.State)
- }
- return label
-}