From 6685f8845583cfc2edddab7618af4ad0fe88e220 Mon Sep 17 00:00:00 2001 From: Joseph Cook <33655003+jmcook1186@users.noreply.github.com> Date: Tue, 8 Nov 2022 20:17:12 +0000 Subject: [PATCH] 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 --- signer/core/cliui.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/signer/core/cliui.go b/signer/core/cliui.go index 6278e53c0..b1bd3206e 100644 --- a/signer/core/cliui.go +++ b/signer/core/cliui.go @@ -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) {