diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-04 12:13:34 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-07 16:02:18 -0500 |
| commit | 8dd1c52d45ad0dedb743107bcf255b2822c9501d (patch) | |
| tree | f485b3fe3496ba0176c9430ddf358966448028cc /client | |
| parent | b0fd9a1c7848343ef378b772eb76a0e99747260c (diff) | |
default value for login prompt
Diffstat (limited to 'client')
| -rw-r--r-- | client/application.go | 8 | ||||
| -rw-r--r-- | client/login_prompt.go | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/client/application.go b/client/application.go index 2d16591..5b60ca4 100644 --- a/client/application.go +++ b/client/application.go @@ -36,12 +36,18 @@ func newApplication(serverAddress string) *application { } func (a *application) OnConnect() { + u := a.cache.Get(a.uid) + var username string + if u != nil { + username = u.Fields[""] + } + a.pushPrompt(newLoginPrompt(username)) + a.connected = true a.reconnecting = false a.cache = object.NewCache(a) a.windowCache = window.NewCache() a.cmdWindow.info("connected to %s", a.Client.Address) - a.pushPrompt(&loginPrompt{}) } func (a *application) OnDisconnect(err error) { diff --git a/client/login_prompt.go b/client/login_prompt.go index 7e38d30..c19d987 100644 --- a/client/login_prompt.go +++ b/client/login_prompt.go @@ -2,6 +2,7 @@ package main import ( "citrons.xyz/talk/tui" + "os" ) type loginPrompt struct { @@ -9,6 +10,16 @@ type loginPrompt struct { username string } +func newLoginPrompt(completeName string) *loginPrompt { + var prompt loginPrompt + username := completeName + if username == "" { + username = os.Getenv("USER") + } + prompt.input.SetText(username) + return &prompt +} + func (p *loginPrompt) Input() *tui.TextInput { return &p.input } |
