From: Adam Shamblin Date: Mon, 16 Jan 2023 18:21:59 +0000 (-0700) Subject: wip, misc X-Git-Url: https://git.vexinglabs.com/?a=commitdiff_plain;h=fc7a19448591289c72ea34cde46c12aa6c810250;p=dead-tooter.git wip, misc --- diff --git a/cmd/list.go b/cmd/list.go index 82f3dc3..a7cab4d 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -51,7 +51,7 @@ var listAccountsCmd = &cobra.Command{ log.Fatal(err.Error()) } - accounts.Display() + print(accounts) }, } diff --git a/pkg/mastodon/account.go b/pkg/mastodon/account.go index 0a630a9..e01b018 100644 --- a/pkg/mastodon/account.go +++ b/pkg/mastodon/account.go @@ -67,11 +67,8 @@ type Emoji struct { Category string `json:"category"` } -// AccountCollection is a group of Accounts -type AccountCollection []Account - // Display a single Account -func (a *Account) Display() string { +func (a *Account) String() string { return strings.Join([]string{a.ID, a.Acct}, "\t") } @@ -93,15 +90,30 @@ func (a *Account) DisplayLong() (err error) { return err } +// AccountCollection is a group of Accounts +type AccountCollection []Account + // Display a collection of Accounts func (ac AccountCollection) Display() { w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) for _, value := range ac { - fmt.Fprintln(w, value.Display()) + fmt.Fprintln(w, value.String()) } w.Flush() } +func (ac AccountCollection) Len() int { + return len(ac) +} + +func (ac AccountCollection) Less(i, j int) bool { + return ac[i].ID < ac[j].ID +} + +func (ac AccountCollection) Swap(i, j int) { + ac[i], ac[j] = ac[j], ac[i] +} + // Authorize opens the default browser to initiate the authorization flow // for the current user. func (a *Account) Authorize(host string, app Application) (code string, err error) { diff --git a/pkg/mastodon/display.go b/pkg/mastodon/display.go deleted file mode 100644 index 9bd233f..0000000 --- a/pkg/mastodon/display.go +++ /dev/null @@ -1,23 +0,0 @@ -package mastodon - -import ( - "fmt" - "os" - "text/tabwriter" -) - -// DisplayItem interface provides a means to display a single item. -type DisplayItem interface { - Display() string -} - -// DisplayItemCollection provides a means to display a collection of items. -type DisplayItemCollection []DisplayItem - -func (c DisplayItemCollection) Display() { - w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) - for _, item := range c { - fmt.Fprintln(w, item.Display()) - } - w.Flush() -} diff --git a/pkg/mastodon/display/display.go b/pkg/mastodon/display/display.go new file mode 100644 index 0000000..b5c7688 --- /dev/null +++ b/pkg/mastodon/display/display.go @@ -0,0 +1,26 @@ +package display + +import ( + "fmt" + "os" + "text/tabwriter" +) + +// DisplayItem interface provides a means to display a single item. +type Item interface { + Display() string +} + +// DisplayItemCollection provides a means to display a collection of items. +type ItemCollection []Item + +func AsTable(c ItemCollection) { + w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) + for _, item := range c { + fmt.Fprintln(w, item.Display()) + } + w.Flush() +} + +func AsJSON(c ItemCollection) { +}