From 907b9eb1ce6787b67599004643bfe27d1ecdbec2 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Mon, 5 Jun 2023 15:55:48 +0530 Subject: [PATCH] Switch to kong for CLI --- .../run/attachment_image.go | 4 +- guilds_tree.go => cmd/run/guilds_tree.go | 4 +- main_flex.go => cmd/run/main_flex.go | 4 +- message_input.go => cmd/run/message_input.go | 4 +- messages_text.go => cmd/run/messages_text.go | 6 +- cmd/run/run.go | 77 +++++++++++++++++ state.go => cmd/run/state.go | 4 +- {internal/config => config}/config.go | 60 +++---------- {internal/config => config}/keys.go | 0 {internal/config => config}/theme.go | 0 go.mod | 1 + go.sum | 42 ++-------- lol.yml | 37 ++++++++ main.go | 84 +++---------------- {pkg/markdown => markdown}/markdown.go | 0 {pkg/markdown => markdown}/markdown_test.go | 0 {internal/ui => ui}/login_form.go | 2 +- 17 files changed, 160 insertions(+), 169 deletions(-) rename attachment_image.go => cmd/run/attachment_image.go (95%) rename guilds_tree.go => cmd/run/guilds_tree.go (98%) rename main_flex.go => cmd/run/main_flex.go (96%) rename message_input.go => cmd/run/message_input.go (98%) rename messages_text.go => cmd/run/messages_text.go (98%) create mode 100644 cmd/run/run.go rename state.go => cmd/run/state.go (97%) rename {internal/config => config}/config.go (57%) rename {internal/config => config}/keys.go (100%) rename {internal/config => config}/theme.go (100%) create mode 100644 lol.yml rename {pkg/markdown => markdown}/markdown.go (100%) rename {pkg/markdown => markdown}/markdown_test.go (100%) rename {internal/ui => ui}/login_form.go (97%) diff --git a/attachment_image.go b/cmd/run/attachment_image.go similarity index 95% rename from attachment_image.go rename to cmd/run/attachment_image.go index 36a05f6..c9d29d8 100644 --- a/attachment_image.go +++ b/cmd/run/attachment_image.go @@ -1,4 +1,4 @@ -package main +package run import ( "image" @@ -6,7 +6,7 @@ import ( _ "image/png" "net/http" - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/diamondburned/arikawa/v3/discord" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" diff --git a/guilds_tree.go b/cmd/run/guilds_tree.go similarity index 98% rename from guilds_tree.go rename to cmd/run/guilds_tree.go index a53cce7..9cbcc0c 100644 --- a/guilds_tree.go +++ b/cmd/run/guilds_tree.go @@ -1,4 +1,4 @@ -package main +package run import ( "fmt" @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/gateway" "github.com/gdamore/tcell/v2" diff --git a/main_flex.go b/cmd/run/main_flex.go similarity index 96% rename from main_flex.go rename to cmd/run/main_flex.go index 06cb4f6..28d4776 100644 --- a/main_flex.go +++ b/cmd/run/main_flex.go @@ -1,7 +1,7 @@ -package main +package run import ( - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) diff --git a/message_input.go b/cmd/run/message_input.go similarity index 98% rename from message_input.go rename to cmd/run/message_input.go index ed234cd..3b4de65 100644 --- a/message_input.go +++ b/cmd/run/message_input.go @@ -1,4 +1,4 @@ -package main +package run import ( "log" @@ -7,7 +7,7 @@ import ( "strings" "github.com/atotto/clipboard" - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/utils/json/option" diff --git a/messages_text.go b/cmd/run/messages_text.go similarity index 98% rename from messages_text.go rename to cmd/run/messages_text.go index 6ed369f..f3244ad 100644 --- a/messages_text.go +++ b/cmd/run/messages_text.go @@ -1,4 +1,4 @@ -package main +package run import ( "fmt" @@ -7,8 +7,8 @@ import ( "time" "github.com/atotto/clipboard" - "github.com/ayn2op/discordo/internal/config" - "github.com/ayn2op/discordo/pkg/markdown" + "github.com/ayn2op/discordo/config" + "github.com/ayn2op/discordo/markdown" "github.com/diamondburned/arikawa/v3/discord" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" diff --git a/cmd/run/run.go b/cmd/run/run.go new file mode 100644 index 0000000..345f116 --- /dev/null +++ b/cmd/run/run.go @@ -0,0 +1,77 @@ +package run + +import ( + "log" + "os" + "path/filepath" + + "github.com/ayn2op/discordo/config" + "github.com/ayn2op/discordo/ui" + "github.com/rivo/tview" +) + +var ( + discordState *State + + app = tview.NewApplication() + mainFlex *MainFlex +) + +type Cmd struct { + Token string `default:"${token}" help:"The authentication token." short:"t"` + + Config string `default:"${configPath}" help:"The path of the configuration file." short:"l" type:"path"` + Log string `default:"${logPath}" help:"The path of the log file." short:"c" type:"path"` +} + +func (r *Cmd) Run() error { + err := os.MkdirAll(filepath.Dir(r.Config), os.ModePerm) + if err != nil { + return err + } + + err = config.Load(r.Config) + if err != nil { + return err + } + + err = os.MkdirAll(filepath.Dir(r.Log), os.ModePerm) + if err != nil { + return err + } + + f, err := os.OpenFile(r.Log, os.O_CREATE|os.O_WRONLY, os.ModePerm) + if err != nil { + return err + } + + log.SetOutput(f) + log.SetFlags(log.LstdFlags | log.Llongfile) + + if r.Token == "" { + lf := ui.NewLoginForm() + + go func() { + mainFlex = newMainFlex() + if err := openState(<-lf.Token); err != nil { + log.Fatal(err) + } + + app.QueueUpdateDraw(func() { + app.SetRoot(mainFlex, true) + }) + }() + + app.SetRoot(lf, true) + } else { + mainFlex = newMainFlex() + if err := openState(r.Token); err != nil { + log.Fatal(err) + } + + app.SetRoot(mainFlex, true) + } + + app.EnableMouse(config.Current.Mouse) + return app.Run() +} diff --git a/state.go b/cmd/run/state.go similarity index 97% rename from state.go rename to cmd/run/state.go index bc6d009..e0f36b2 100644 --- a/state.go +++ b/cmd/run/state.go @@ -1,4 +1,4 @@ -package main +package run import ( "context" @@ -6,7 +6,7 @@ import ( "log" "runtime" - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" diff --git a/internal/config/config.go b/config/config.go similarity index 57% rename from internal/config/config.go rename to config/config.go index 0f64b7e..1d2b744 100644 --- a/internal/config/config.go +++ b/config/config.go @@ -1,7 +1,6 @@ package config import ( - "errors" "os" "path/filepath" @@ -38,53 +37,8 @@ func defConfig() Config { } } -func getPath(optionalPath string) (string, error) { - // Trigger an error if config flag used but is empty. - if optionalPath == "" { - return "", errors.New("Optional path cannot be empty.") - } - - // Use the path provided by flags. - if optionalPath != "none" { - return optionalPath, nil - } - - // Use the default for the OS. - path, err := os.UserConfigDir() - if err != nil { - return "", err - } - - path = filepath.Join(path, Name) - if err != nil { - return "", err - } - - path = filepath.Join(path, "config.yml") - if err != nil { - return "", err - } - - return path, nil -} - -func Load(optionalPath string) error { - path, err := getPath(optionalPath) - if err != nil { - return err - } - - // Split the directory from the configuration file. - dir, file := filepath.Split(path) - - // Create the configuration directory if it does not exist already. - err = os.MkdirAll(dir, os.ModePerm) - if err != nil { - return err - } - - path = filepath.Join(dir, file) - _, err = os.Stat(path) +func Load(path string) error { + _, err := os.Stat(path) if os.IsNotExist(err) { f, err := os.Create(path) if err != nil { @@ -111,3 +65,13 @@ func Load(optionalPath string) error { return nil } + +func DefaultPath() string { + path, _ := os.UserConfigDir() + return filepath.Join(path, Name, "config.yml") +} + +func DefaultLogPath() string { + path, _ := os.UserCacheDir() + return filepath.Join(path, Name, "logs.txt") +} diff --git a/internal/config/keys.go b/config/keys.go similarity index 100% rename from internal/config/keys.go rename to config/keys.go diff --git a/internal/config/theme.go b/config/theme.go similarity index 100% rename from internal/config/theme.go rename to config/theme.go diff --git a/go.mod b/go.mod index c518575..1bb9eb4 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/ayn2op/discordo go 1.20 require ( + github.com/alecthomas/kong v0.7.1 github.com/atotto/clipboard v0.1.4 github.com/diamondburned/arikawa/v3 v3.3.0 github.com/gdamore/tcell/v2 v2.6.0 diff --git a/go.sum b/go.sum index 39799c8..2ebcf3a 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,14 @@ +github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= +github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4= +github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= +github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= -github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= -github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/diamondburned/arikawa/v3 v3.2.0 h1:aBUhg94pxblT6ks4EV7qxEk44tnl0ico67ydqjVnv9g= -github.com/diamondburned/arikawa/v3 v3.2.0/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/diamondburned/arikawa/v3 v3.3.0 h1:S85dCYFsNsyGxG3JYYiEfW31JIJgNaHgUDNsEOf/aRg= github.com/diamondburned/arikawa/v3 v3.3.0/go.mod h1:+ifmDonP/JdBiUOzZmVReEjPTHDUSkyqqRRmjSf9NE8= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= @@ -23,6 +22,7 @@ github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlI github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= @@ -30,32 +30,15 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/tview v0.0.0-20230325211341-281d14d896d7 h1:8sjyhdBA9HmxHGUeAM/43uSHfyFhFodbxekw2mYhpo0= -github.com/rivo/tview v0.0.0-20230325211341-281d14d896d7/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= -github.com/rivo/tview v0.0.0-20230330183452-5796b0cd5c1f h1:vpjWdGBgikHYD4ruBvDINMxwdh5UWVck9yOyrwFktMo= -github.com/rivo/tview v0.0.0-20230330183452-5796b0cd5c1f/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= -github.com/rivo/tview v0.0.0-20230504092913-51ba3688bcdd h1:Y79siDYMHXtNhvX1VJHW5gzfplM0IowrtomKX9TshmI= -github.com/rivo/tview v0.0.0-20230504092913-51ba3688bcdd/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= -github.com/rivo/tview v0.0.0-20230511053024-822bd067b165 h1:YMycYmUdmLI7ZTn86HUEDM8E8fCMz7twtysBW3SlG0c= -github.com/rivo/tview v0.0.0-20230511053024-822bd067b165/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= -github.com/rivo/tview v0.0.0-20230525073430-4a1f85bb2219 h1:Wt34AcMCfhtqhM8bCLKpZvIc7VNwU83B5ABooKNtFBc= -github.com/rivo/tview v0.0.0-20230525073430-4a1f85bb2219/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= github.com/rivo/tview v0.0.0-20230530133550-8bd761dda819 h1:qRMCGgwKl66uWe7Hnzl5bCvZlfrLNIxOx7K00j5XeNc= github.com/rivo/tview v0.0.0-20230530133550-8bd761dda819/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zalando/go-keyring v0.2.2 h1:f0xmpYiSrHtSNAVgwip93Cg8tuF45HJM6rHq/A5RI/4= -github.com/zalando/go-keyring v0.2.2/go.mod h1:sI3evg9Wvpw3+n4SqplGSJUMwtDeROfD4nsFz4z9PG0= github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms= github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -71,26 +54,16 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211001092434-39dca1131b70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= -golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -98,8 +71,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -111,6 +82,5 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lol.yml b/lol.yml new file mode 100644 index 0000000..0f9b177 --- /dev/null +++ b/lol.yml @@ -0,0 +1,37 @@ +mouse: true +messages_limit: 50 +timestamps: false +editor: default +keys: + cancel: Esc + guilds_tree: + focus: Alt+Rune[g] + toggle: Alt+Rune[b] + messages_text: + focus: Alt+Rune[m] + show_image: Rune[i] + copy_content: Rune[c] + reply: Rune[r] + reply_mention: Rune[R] + select_reply: Rune[s] + select_previous: Up + select_next: Down + select_first: Home + select_last: End + message_input: + focus: Alt+Rune[i] + send: Enter + paste: Ctrl+V + launch_editor: Ctrl+E +theme: + border: false + border_color: default + border_padding: [0, 0, 1, 1] + title_color: pink + background_color: violet + guilds_tree: + graphics: true + messages_text: + author_color: aqua + reply_indicator: ╭ + message_input: {} diff --git a/main.go b/main.go index 69ae5f1..bf18b3a 100644 --- a/main.go +++ b/main.go @@ -1,86 +1,28 @@ package main import ( - "flag" "log" - "os" - "path/filepath" - "github.com/ayn2op/discordo/internal/config" - "github.com/ayn2op/discordo/internal/ui" - "github.com/rivo/tview" + "github.com/alecthomas/kong" + "github.com/ayn2op/discordo/cmd/run" + "github.com/ayn2op/discordo/config" "github.com/zalando/go-keyring" ) -var ( - token string - configPath string - - discordState *State - - app = tview.NewApplication() - mainFlex *MainFlex -) - -func init() { - t, _ := keyring.Get(config.Name, "token") - flag.StringVar(&token, "token", t, "The authentication token.") - flag.StringVar(&configPath, "config", "none", "Optional alternative configuration file.") - - path, err := os.UserCacheDir() - if err != nil { - log.Fatal(err) - } - - path = filepath.Join(path, config.Name) - err = os.MkdirAll(path, os.ModePerm) - if err != nil { - log.Fatal(err) - } - - path = filepath.Join(path, "logs.txt") - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, os.ModePerm) - if err != nil { - log.Fatal(err) - } - - log.SetOutput(f) - log.SetFlags(log.LstdFlags | log.Llongfile) +var cli struct { + Run run.Cmd `cmd:"" default:"withargs"` } func main() { - flag.Parse() + t, _ := keyring.Get(config.Name, "token") + ctx := kong.Parse(&cli, kong.Vars{ + "token": t, + "configPath": config.DefaultPath(), + "logPath": config.DefaultLogPath(), + }) - if err := config.Load(configPath); err != nil { - log.Fatal(err) - } - - if token == "" { - lf := ui.NewLoginForm() - - go func() { - mainFlex = newMainFlex() - if err := openState(<-lf.Token); err != nil { - log.Fatal(err) - } - - app.QueueUpdateDraw(func() { - app.SetRoot(mainFlex, true) - }) - }() - - app.SetRoot(lf, true) - } else { - mainFlex = newMainFlex() - if err := openState(token); err != nil { - log.Fatal(err) - } - - app.SetRoot(mainFlex, true) - } - - app.EnableMouse(config.Current.Mouse) - if err := app.Run(); err != nil { + err := ctx.Run() + if err != nil { log.Fatal(err) } } diff --git a/pkg/markdown/markdown.go b/markdown/markdown.go similarity index 100% rename from pkg/markdown/markdown.go rename to markdown/markdown.go diff --git a/pkg/markdown/markdown_test.go b/markdown/markdown_test.go similarity index 100% rename from pkg/markdown/markdown_test.go rename to markdown/markdown_test.go diff --git a/internal/ui/login_form.go b/ui/login_form.go similarity index 97% rename from internal/ui/login_form.go rename to ui/login_form.go index ab61466..e182d51 100644 --- a/internal/ui/login_form.go +++ b/ui/login_form.go @@ -3,7 +3,7 @@ package ui import ( "log" - "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/config" "github.com/diamondburned/arikawa/v3/api" "github.com/gdamore/tcell/v2" "github.com/rivo/tview"