cmd/clef: only print first N accounts on startup (#26128)

PR #26082 added account listing to OnSignerStartup but did not consider the case where a user has a large number of accounts which would be annoying to display.

This PR updates showAccounts() so that if there are more than 20 accounts available the user sees the first 20 displayed in the console followed by: First 20 accounts listed (N more available).

Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
Joseph Cook 2022-11-08 20:17:12 +00:00 committed by GitHub
parent ee9ff06469
commit 6685f88455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -253,12 +253,17 @@ func (ui *CommandlineUI) showAccounts() {
fmt.Print("No accounts found\n")
return
}
var msg string
var out = new(strings.Builder)
if limit := 20; len(accounts) > limit {
msg = fmt.Sprintf("\nFirst %d accounts listed (%d more available).\n", limit, len(accounts)-limit)
accounts = accounts[:limit]
}
fmt.Fprint(out, "\n------- Available accounts -------\n")
for i, account := range accounts {
fmt.Fprintf(out, "%d. %s at %s\n", i, account.Address, account.URL)
}
fmt.Print(out.String())
fmt.Print(out.String(), msg)
}
func (ui *CommandlineUI) OnSignerStartup(info StartupInfo) {