Dan Anglin
ccdd8b6530
Add a new internal printer package for printing resources to the screen or pager. With the new printer in place, most of the settings such as the pager command, colour theme, whether or not colour output is disabled, etc are defined in one place which saves us the trouble of passing an increasing number of parameters to an increasing number of Display methods throughout the code base. The old Displayer interface and associated Display methods in the model package are removed as this is now handled by the printer. The format functions in the utilities package has essentially been rewritten as methods to the Printer type. Additional changes: - All indentation when displaying information about resources (e.g. statuses, instance, accounts) are removed. - The application's build information now has colour output.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package printer
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
|
)
|
|
|
|
func (p Printer) PrintList(list model.List) {
|
|
var builder strings.Builder
|
|
|
|
builder.WriteString("\n" + p.headerFormat("LIST TITLE:") + "\n")
|
|
builder.WriteString(list.Title + "\n\n")
|
|
builder.WriteString(p.headerFormat("LIST ID:") + "\n")
|
|
builder.WriteString(list.ID + "\n\n")
|
|
builder.WriteString(p.headerFormat("REPLIES POLICY:") + "\n")
|
|
builder.WriteString(list.RepliesPolicy.String() + "\n\n")
|
|
builder.WriteString(p.headerFormat("ADDED ACCOUNTS:"))
|
|
|
|
if len(list.Accounts) > 0 {
|
|
for acct, name := range list.Accounts {
|
|
builder.WriteString("\n" + p.bullet + " " + p.fullDisplayNameFormat(name, acct))
|
|
}
|
|
} else {
|
|
builder.WriteString("\n" + "None")
|
|
}
|
|
|
|
builder.WriteString("\n")
|
|
|
|
printToStdout(builder.String())
|
|
}
|
|
|
|
func (p Printer) PrintLists(lists []model.List) {
|
|
var builder strings.Builder
|
|
|
|
builder.WriteString("\n" + p.headerFormat("LISTS"))
|
|
|
|
for i := range lists {
|
|
builder.WriteString("\n" + p.bullet + " " + lists[i].Title + " (" + lists[i].ID + ")")
|
|
}
|
|
|
|
builder.WriteString("\n")
|
|
|
|
printToStdout(builder.String())
|
|
}
|