author | Mikael Berthe <mikael@lilotux.net> |
Fri, 26 May 2017 23:04:46 +0200 | |
changeset 148 | 6c763fa86e9a |
parent 147 | d9b02148d24c |
child 150 | 7f46bcaf240c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
2 |
// |
|
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package printer |
|
7 |
||
8 |
import ( |
|
9 |
"fmt" |
|
10 |
"io" |
|
11 |
"os" |
|
12 |
"reflect" |
|
13 |
"time" |
|
14 |
||
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
15 |
"github.com/m0t0k1ch1/gomif" |
0 | 16 |
|
17 |
"github.com/McKael/madon" |
|
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
121
diff
changeset
|
18 |
"github.com/McKael/madonctl/printer/html2text" |
0 | 19 |
) |
20 |
||
21 |
// PlainPrinter is the default "plain text" printer |
|
22 |
type PlainPrinter struct { |
|
23 |
Indent string |
|
24 |
NoSubtitles bool |
|
25 |
} |
|
26 |
||
27 |
// NewPrinterPlain returns a plaintext ResourcePrinter |
|
28 |
// For PlainPrinter, the option parameter contains the indent prefix. |
|
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
77
diff
changeset
|
29 |
func NewPrinterPlain(options Options) (*PlainPrinter, error) { |
0 | 30 |
indentInc := " " |
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
77
diff
changeset
|
31 |
if i, ok := options["indent"]; ok { |
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
77
diff
changeset
|
32 |
indentInc = i |
0 | 33 |
} |
34 |
return &PlainPrinter{Indent: indentInc}, nil |
|
35 |
} |
|
36 |
||
37 |
// PrintObj sends the object as text to the writer |
|
38 |
// If the writer w is nil, standard output will be used. |
|
39 |
// For PlainPrinter, the option parameter contains the initial indent. |
|
40 |
func (p *PlainPrinter) PrintObj(obj interface{}, w io.Writer, initialIndent string) error { |
|
41 |
if w == nil { |
|
42 |
w = os.Stdout |
|
43 |
} |
|
44 |
switch o := obj.(type) { |
|
45 |
case []madon.Account, []madon.Attachment, []madon.Card, []madon.Context, |
|
46 |
[]madon.Instance, []madon.Mention, []madon.Notification, |
|
47 |
[]madon.Relationship, []madon.Report, []madon.Results, |
|
38
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
48 |
[]madon.Status, []madon.StreamEvent, []madon.Tag, |
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
49 |
[]*gomif.InstanceStatus: |
0 | 50 |
return p.plainForeach(o, w, initialIndent) |
51 |
case *madon.Account: |
|
52 |
return p.plainPrintAccount(o, w, initialIndent) |
|
53 |
case madon.Account: |
|
54 |
return p.plainPrintAccount(&o, w, initialIndent) |
|
55 |
case *madon.Attachment: |
|
56 |
return p.plainPrintAttachment(o, w, initialIndent) |
|
57 |
case madon.Attachment: |
|
58 |
return p.plainPrintAttachment(&o, w, initialIndent) |
|
59 |
case *madon.Card: |
|
60 |
return p.plainPrintCard(o, w, initialIndent) |
|
61 |
case madon.Card: |
|
62 |
return p.plainPrintCard(&o, w, initialIndent) |
|
63 |
case *madon.Context: |
|
64 |
return p.plainPrintContext(o, w, initialIndent) |
|
65 |
case madon.Context: |
|
66 |
return p.plainPrintContext(&o, w, initialIndent) |
|
67 |
case *madon.Instance: |
|
68 |
return p.plainPrintInstance(o, w, initialIndent) |
|
69 |
case madon.Instance: |
|
70 |
return p.plainPrintInstance(&o, w, initialIndent) |
|
71 |
case *madon.Notification: |
|
72 |
return p.plainPrintNotification(o, w, initialIndent) |
|
73 |
case madon.Notification: |
|
74 |
return p.plainPrintNotification(&o, w, initialIndent) |
|
75 |
case *madon.Relationship: |
|
76 |
return p.plainPrintRelationship(o, w, initialIndent) |
|
77 |
case madon.Relationship: |
|
78 |
return p.plainPrintRelationship(&o, w, initialIndent) |
|
79 |
case *madon.Report: |
|
80 |
return p.plainPrintReport(o, w, initialIndent) |
|
81 |
case madon.Report: |
|
82 |
return p.plainPrintReport(&o, w, initialIndent) |
|
83 |
case *madon.Results: |
|
84 |
return p.plainPrintResults(o, w, initialIndent) |
|
85 |
case madon.Results: |
|
86 |
return p.plainPrintResults(&o, w, initialIndent) |
|
87 |
case *madon.Status: |
|
88 |
return p.plainPrintStatus(o, w, initialIndent) |
|
89 |
case madon.Status: |
|
90 |
return p.plainPrintStatus(&o, w, initialIndent) |
|
91 |
case *madon.UserToken: |
|
92 |
return p.plainPrintUserToken(o, w, initialIndent) |
|
93 |
case madon.UserToken: |
|
94 |
return p.plainPrintUserToken(&o, w, initialIndent) |
|
38
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
95 |
case *gomif.InstanceStatus: |
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
96 |
return p.plainPrintInstanceStatistics(o, w, initialIndent) |
38
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
97 |
case gomif.InstanceStatus: |
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
98 |
return p.plainPrintInstanceStatistics(&o, w, initialIndent) |
0 | 99 |
} |
100 |
// TODO: Mention |
|
101 |
// TODO: StreamEvent |
|
102 |
// TODO: Tag |
|
103 |
||
104 |
return fmt.Errorf("PlainPrinter not yet implemented for %T (try json or yaml...)", obj) |
|
105 |
} |
|
106 |
||
107 |
func (p *PlainPrinter) plainForeach(ol interface{}, w io.Writer, ii string) error { |
|
108 |
switch reflect.TypeOf(ol).Kind() { |
|
109 |
case reflect.Slice: |
|
110 |
s := reflect.ValueOf(ol) |
|
111 |
||
112 |
for i := 0; i < s.Len(); i++ { |
|
113 |
o := s.Index(i).Interface() |
|
114 |
if err := p.PrintObj(o, w, ii); err != nil { |
|
115 |
return err |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
return nil |
|
120 |
} |
|
121 |
||
122 |
func html2string(h string) string { |
|
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
121
diff
changeset
|
123 |
t, err := html2text.Textify(h) |
0 | 124 |
if err == nil { |
125 |
return t |
|
126 |
} |
|
127 |
return h // Failed: return initial string |
|
128 |
} |
|
129 |
||
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
130 |
// unix2time convert a UNIX timestamp to a time.Time |
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
131 |
func unix2time(ts interface{}) (time.Time, error) { |
41
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
132 |
switch t := ts.(type) { |
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
133 |
case int64: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
134 |
return time.Unix(t, 0), nil |
41
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
135 |
case int: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
136 |
return time.Unix(int64(t), 0), nil |
41
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
137 |
case float64: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
138 |
return time.Unix(int64(t), 0), nil |
41
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
139 |
} |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
140 |
return time.Time{}, fmt.Errorf("invalid timestamp type") |
41
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
141 |
} |
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
142 |
|
0 | 143 |
func indentedPrint(w io.Writer, indent string, title, skipIfEmpty bool, label string, format string, args ...interface{}) { |
144 |
prefix := indent |
|
145 |
if title { |
|
146 |
prefix += "- " |
|
147 |
} else { |
|
148 |
prefix += " " |
|
149 |
} |
|
150 |
value := fmt.Sprintf(format, args...) |
|
151 |
if !title && skipIfEmpty && len(value) == 0 { |
|
152 |
return |
|
153 |
} |
|
154 |
fmt.Fprintf(w, "%s%s: %s\n", prefix, label, value) |
|
155 |
} |
|
156 |
||
157 |
func (p *PlainPrinter) plainPrintAccount(a *madon.Account, w io.Writer, indent string) error { |
|
158 |
indentedPrint(w, indent, true, false, "Account ID", "%d (%s)", a.ID, a.Username) |
|
159 |
indentedPrint(w, indent, false, false, "User ID", "%s", a.Acct) |
|
160 |
indentedPrint(w, indent, false, false, "Display name", "%s", a.DisplayName) |
|
161 |
indentedPrint(w, indent, false, false, "Creation date", "%v", a.CreatedAt.Local()) |
|
162 |
indentedPrint(w, indent, false, false, "URL", "%s", a.URL) |
|
163 |
indentedPrint(w, indent, false, false, "Statuses count", "%d", a.StatusesCount) |
|
164 |
indentedPrint(w, indent, false, false, "Followers count", "%d", a.FollowersCount) |
|
165 |
indentedPrint(w, indent, false, false, "Following count", "%d", a.FollowingCount) |
|
166 |
if a.Locked { |
|
167 |
indentedPrint(w, indent, false, false, "Locked", "%v", a.Locked) |
|
168 |
} |
|
169 |
indentedPrint(w, indent, false, true, "User note", "%s", html2string(a.Note)) // XXX too long? |
|
170 |
return nil |
|
171 |
} |
|
172 |
||
173 |
func (p *PlainPrinter) plainPrintAttachment(a *madon.Attachment, w io.Writer, indent string) error { |
|
174 |
indentedPrint(w, indent, true, false, "Attachment ID", "%d", a.ID) |
|
175 |
indentedPrint(w, indent, false, false, "Type", "%s", a.Type) |
|
176 |
indentedPrint(w, indent, false, false, "Local URL", "%s", a.URL) |
|
177 |
indentedPrint(w, indent, false, true, "Remote URL", "%s", a.RemoteURL) |
|
178 |
indentedPrint(w, indent, false, true, "Preview URL", "%s", a.PreviewURL) |
|
179 |
indentedPrint(w, indent, false, true, "Text URL", "%s", a.PreviewURL) |
|
180 |
return nil |
|
181 |
} |
|
182 |
||
183 |
func (p *PlainPrinter) plainPrintCard(c *madon.Card, w io.Writer, indent string) error { |
|
184 |
indentedPrint(w, indent, true, false, "Card title", "%s", c.Title) |
|
185 |
indentedPrint(w, indent, false, true, "Description", "%s", c.Description) |
|
186 |
indentedPrint(w, indent, false, true, "URL", "%s", c.URL) |
|
187 |
indentedPrint(w, indent, false, true, "Image", "%s", c.Image) |
|
188 |
return nil |
|
189 |
} |
|
190 |
||
191 |
func (p *PlainPrinter) plainPrintContext(c *madon.Context, w io.Writer, indent string) error { |
|
67
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
192 |
indentedPrint(w, indent, true, false, "Context", "%d relative(s)", len(c.Ancestors)+len(c.Descendants)) |
0 | 193 |
if len(c.Ancestors) > 0 { |
194 |
indentedPrint(w, indent, false, false, "Ancestors", "") |
|
195 |
p.PrintObj(c.Ancestors, w, indent+p.Indent) |
|
196 |
} |
|
67
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
197 |
if len(c.Descendants) > 0 { |
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
198 |
indentedPrint(w, indent, false, false, "Descendants", "") |
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
199 |
p.PrintObj(c.Descendants, w, indent+p.Indent) |
0 | 200 |
} |
201 |
return nil |
|
202 |
} |
|
203 |
||
204 |
func (p *PlainPrinter) plainPrintInstance(i *madon.Instance, w io.Writer, indent string) error { |
|
205 |
indentedPrint(w, indent, true, false, "Instance title", "%s", i.Title) |
|
206 |
indentedPrint(w, indent, false, true, "Description", "%s", html2string(i.Description)) |
|
207 |
indentedPrint(w, indent, false, true, "URL", "%s", i.URI) |
|
208 |
indentedPrint(w, indent, false, true, "Email", "%s", i.Email) |
|
18
7a4b57b3e66a
Display instance version, if field is set
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
209 |
indentedPrint(w, indent, false, true, "Version", "%s", i.Version) |
0 | 210 |
return nil |
211 |
} |
|
212 |
||
213 |
func (p *PlainPrinter) plainPrintNotification(n *madon.Notification, w io.Writer, indent string) error { |
|
214 |
indentedPrint(w, indent, true, false, "Notification ID", "%d", n.ID) |
|
215 |
indentedPrint(w, indent, false, false, "Type", "%s", n.Type) |
|
216 |
indentedPrint(w, indent, false, false, "Timestamp", "%v", n.CreatedAt.Local()) |
|
217 |
if n.Account != nil { |
|
218 |
indentedPrint(w, indent+p.Indent, true, false, "Account", "(%d) @%s - %s", |
|
219 |
n.Account.ID, n.Account.Acct, n.Account.DisplayName) |
|
220 |
} |
|
221 |
if n.Status != nil { |
|
222 |
p.plainPrintStatus(n.Status, w, indent+p.Indent) |
|
223 |
} |
|
224 |
return nil |
|
225 |
} |
|
226 |
||
227 |
func (p *PlainPrinter) plainPrintRelationship(r *madon.Relationship, w io.Writer, indent string) error { |
|
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
228 |
indentedPrint(w, indent, true, false, "Account ID", "%d", r.ID) |
0 | 229 |
indentedPrint(w, indent, false, false, "Following", "%v", r.Following) |
230 |
indentedPrint(w, indent, false, false, "Followed-by", "%v", r.FollowedBy) |
|
231 |
indentedPrint(w, indent, false, false, "Blocking", "%v", r.Blocking) |
|
232 |
indentedPrint(w, indent, false, false, "Muting", "%v", r.Muting) |
|
233 |
indentedPrint(w, indent, false, false, "Requested", "%v", r.Requested) |
|
234 |
return nil |
|
235 |
} |
|
236 |
||
237 |
func (p *PlainPrinter) plainPrintReport(r *madon.Report, w io.Writer, indent string) error { |
|
238 |
indentedPrint(w, indent, true, false, "Report ID", "%d", r.ID) |
|
239 |
indentedPrint(w, indent, false, false, "Action taken", "%s", r.ActionTaken) |
|
240 |
return nil |
|
241 |
} |
|
242 |
||
243 |
func (p *PlainPrinter) plainPrintResults(r *madon.Results, w io.Writer, indent string) error { |
|
244 |
indentedPrint(w, indent, true, false, "Results", "%d account(s), %d status(es), %d hashtag(s)", |
|
245 |
len(r.Accounts), len(r.Statuses), len(r.Hashtags)) |
|
246 |
if len(r.Accounts) > 0 { |
|
247 |
indentedPrint(w, indent, false, false, "Accounts", "") |
|
248 |
p.PrintObj(r.Accounts, w, indent+p.Indent) |
|
249 |
} |
|
250 |
if len(r.Statuses) > 0 { |
|
251 |
indentedPrint(w, indent, false, false, "Statuses", "") |
|
252 |
p.PrintObj(r.Statuses, w, indent+p.Indent) |
|
253 |
} |
|
254 |
if len(r.Hashtags) > 0 { |
|
255 |
indentedPrint(w, indent, false, false, "Hashtags", "") |
|
256 |
for _, tag := range r.Hashtags { |
|
257 |
indentedPrint(w, indent+p.Indent, true, false, "Tag", "%s", tag) |
|
258 |
} |
|
259 |
} |
|
260 |
return nil |
|
261 |
} |
|
262 |
||
263 |
func (p *PlainPrinter) plainPrintStatus(s *madon.Status, w io.Writer, indent string) error { |
|
264 |
indentedPrint(w, indent, true, false, "Status ID", "%d", s.ID) |
|
121
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
265 |
if s.Account != nil { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
266 |
author := s.Account.Acct |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
267 |
if s.Account.DisplayName != "" { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
268 |
author += " (" + s.Account.DisplayName + ")" |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
269 |
} |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
270 |
indentedPrint(w, indent, false, false, "From", "%s", author) |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
271 |
} |
0 | 272 |
indentedPrint(w, indent, false, false, "Timestamp", "%v", s.CreatedAt.Local()) |
273 |
||
274 |
if s.Reblog != nil { |
|
121
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
275 |
if s.Reblog.Account != nil { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
276 |
indentedPrint(w, indent, false, false, "Reblogged from", "%s", s.Reblog.Account.Username) |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
277 |
} |
0 | 278 |
return p.plainPrintStatus(s.Reblog, w, indent+p.Indent) |
279 |
} |
|
280 |
||
77
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
281 |
if s.Sensitive { |
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
282 |
indentedPrint(w, indent, false, false, "Sensitive (NSFW)", "%v", s.Sensitive) |
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
283 |
} |
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
284 |
|
0 | 285 |
indentedPrint(w, indent, false, false, "Contents", "%s", html2string(s.Content)) |
286 |
if s.InReplyToID > 0 { |
|
287 |
indentedPrint(w, indent, false, false, "In-Reply-To", "%d", s.InReplyToID) |
|
288 |
} |
|
289 |
if s.Reblogged { |
|
290 |
indentedPrint(w, indent, false, false, "Reblogged", "%v", s.Reblogged) |
|
291 |
} |
|
292 |
indentedPrint(w, indent, false, false, "URL", "%s", s.URL) |
|
58
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
293 |
// Display minimum details of attachments |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
294 |
//return p.PrintObj(s.MediaAttachments, w, indent+p.Indent) |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
295 |
for _, a := range s.MediaAttachments { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
296 |
indentedPrint(w, indent+p.Indent, true, false, "Attachment ID", "%d", a.ID) |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
297 |
if a.TextURL != "" { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
298 |
indentedPrint(w, indent+p.Indent, true, false, "Text URL", "%s", a.TextURL) |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
299 |
} else if a.URL != "" { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
300 |
indentedPrint(w, indent+p.Indent, false, false, "URL", "%s", a.URL) |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
301 |
} else { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
302 |
indentedPrint(w, indent+p.Indent, false, false, "Remote URL", "%s", a.RemoteURL) |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
303 |
} |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
304 |
} |
0 | 305 |
return nil |
306 |
} |
|
307 |
||
308 |
func (p *PlainPrinter) plainPrintUserToken(s *madon.UserToken, w io.Writer, indent string) error { |
|
309 |
indentedPrint(w, indent, true, false, "User token", "%s", s.AccessToken) |
|
310 |
indentedPrint(w, indent, false, true, "Type", "%s", s.TokenType) |
|
311 |
if s.CreatedAt != 0 { |
|
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
312 |
indentedPrint(w, indent, false, true, "Timestamp", "%v", time.Unix(s.CreatedAt, 0)) |
0 | 313 |
} |
314 |
indentedPrint(w, indent, false, true, "Scope", "%s", s.Scope) |
|
315 |
return nil |
|
316 |
} |
|
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
317 |
|
38
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
318 |
func (p *PlainPrinter) plainPrintInstanceStatistics(is *gomif.InstanceStatus, w io.Writer, indent string) error { |
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
319 |
if is == nil { |
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
320 |
return nil |
891a3c46a62a
Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents:
37
diff
changeset
|
321 |
} |
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
322 |
indentedPrint(w, indent, true, false, "Instance", "%s", is.InstanceName) |
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
323 |
indentedPrint(w, indent, false, false, "Users", "%d", is.Users) |
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
324 |
indentedPrint(w, indent, false, false, "Statuses", "%d", is.Statuses) |
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
325 |
indentedPrint(w, indent, false, false, "Open Registrations", "%v", is.OpenRegistrations) |
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
326 |
indentedPrint(w, indent, false, false, "Up", "%v", is.Up) |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
327 |
indentedPrint(w, indent, false, false, "Date", "%s", time.Unix(is.Date, 0)) |
37
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
328 |
return nil |
9bc03db114c3
Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents:
18
diff
changeset
|
329 |
} |