From 99be800e9820b80e8f567c8fec84b6491ef8a370 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Wed, 24 Dec 2025 19:49:54 -0500 Subject: [PATCH] refactor: replace tview application methods with direct screen initialization - Replace EnableMouse, SetInputCapture, EnablePaste with direct screen setup - Add explicit screen creation and initialization in run method - Move mouse enablement, title setting, and focus/paste features to screen level - Update SetRoot calls to remove fullscreen parameter --- cmd/application.go | 30 +++++++++++++++++++++++------- go.mod | 4 +++- go.sum | 6 ++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cmd/application.go b/cmd/application.go index 21a653a..2503dc1 100644 --- a/cmd/application.go +++ b/cmd/application.go @@ -1,10 +1,12 @@ package cmd import ( + "fmt" "log/slog" "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/discordo/internal/config" + "github.com/ayn2op/discordo/internal/consts" "github.com/ayn2op/discordo/internal/login" "github.com/ayn2op/tview" "github.com/gdamore/tcell/v3" @@ -27,28 +29,42 @@ func newApplication(cfg *config.Config) *application { slog.Error("failed to init clipboard", "err", err) } - app. - EnableMouse(cfg.Mouse). - SetInputCapture(app.onInputCapture). - EnablePaste(true) + app.SetInputCapture(app.onInputCapture) return app } func (a *application) run(token string) error { + screen, err := tcell.NewScreen() + if err != nil { + return fmt.Errorf("failed to create screen: %w", err) + } + + if err := screen.Init(); err != nil { + return fmt.Errorf("failed to init screen: %w", err) + } + + if a.cfg.Mouse { + screen.EnableMouse() + } + + screen.SetTitle(consts.Name) + screen.EnablePaste() + screen.EnableFocus() + a.SetScreen(screen) + if token == "" { loginForm := login.NewForm(a.Application, a.cfg, func(token string) { if err := a.run(token); err != nil { slog.Error("failed to run application", "err", err) } }) - a.SetRoot(loginForm, true) + a.SetRoot(loginForm) } else { a.chatView = newChatView(a.Application, a.cfg) if err := openState(token); err != nil { return err } - - a.SetRoot(a.chatView, true) + a.SetRoot(a.chatView) } return a.Run() diff --git a/go.mod b/go.mod index b1c0153..d569f41 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,12 @@ module github.com/ayn2op/discordo go 1.25.3 +// replace github.com/ayn2op/tview => ../tview + require ( github.com/BurntSushi/toml v1.6.0 github.com/andybalholm/brotli v1.2.0 - github.com/ayn2op/tview v0.0.0-20251223015859-f555ac780c93 + github.com/ayn2op/tview v0.0.0-20251225004535-05fe7a1d5ec7 github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb github.com/diamondburned/arikawa/v3 v3.6.1-0.20250928004212-a891a653eb26 github.com/diamondburned/ningen/v3 v3.0.1-0.20250920191746-98fbd92e134d diff --git a/go.sum b/go.sum index f1a216e..63b6003 100644 --- a/go.sum +++ b/go.sum @@ -27,10 +27,12 @@ github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ= github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= -github.com/ayn2op/tview v0.0.0-20251221223224-6c423ddda063 h1:vhHyOG5KRHCupPzFT0cw6nww3O4mzaKowW4LoP9zpVg= -github.com/ayn2op/tview v0.0.0-20251221223224-6c423ddda063/go.mod h1:UW4EyJvaPc0vQMzlE5eJe4KVpeQ2cq091kfQCYHGsLI= github.com/ayn2op/tview v0.0.0-20251223015859-f555ac780c93 h1:CLqahwq0StRQrUMPIzWgJD7zeKotQOftZpJ4Tjn2z2I= github.com/ayn2op/tview v0.0.0-20251223015859-f555ac780c93/go.mod h1:UW4EyJvaPc0vQMzlE5eJe4KVpeQ2cq091kfQCYHGsLI= +github.com/ayn2op/tview v0.0.0-20251225003719-d628ee1dee08 h1:pyo+tn/yBdJsWmuWfO9aW7mbDa0jeZJi8kGyFoZdQoo= +github.com/ayn2op/tview v0.0.0-20251225003719-d628ee1dee08/go.mod h1:UW4EyJvaPc0vQMzlE5eJe4KVpeQ2cq091kfQCYHGsLI= +github.com/ayn2op/tview v0.0.0-20251225004535-05fe7a1d5ec7 h1:K9l9ZxGjTFVNX5KTfI3y7m+6Y5utOjJsBBoi320wPmY= +github.com/ayn2op/tview v0.0.0-20251225004535-05fe7a1d5ec7/go.mod h1:UW4EyJvaPc0vQMzlE5eJe4KVpeQ2cq091kfQCYHGsLI= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=