author | Mikael Berthe <mikael@lilotux.net> |
Tue, 04 Sep 2018 17:36:13 +0200 | |
changeset 221 | 970c319e1f7c |
parent 210 | 94be15243195 |
child 228 | 360929ee6aef |
permissions | -rw-r--r-- |
185 | 1 |
// Copyright © 2017-2018 Mikael Berthe <mikael@lilotux.net> |
0 | 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 |
||
15 |
"github.com/McKael/madon" |
|
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
121
diff
changeset
|
16 |
"github.com/McKael/madonctl/printer/html2text" |
0 | 17 |
) |
18 |
||
19 |
// PlainPrinter is the default "plain text" printer |
|
20 |
type PlainPrinter struct { |
|
21 |
Indent string |
|
22 |
NoSubtitles bool |
|
23 |
} |
|
24 |
||
25 |
// NewPrinterPlain returns a plaintext ResourcePrinter |
|
26 |
// 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
|
27 |
func NewPrinterPlain(options Options) (*PlainPrinter, error) { |
0 | 28 |
indentInc := " " |
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
77
diff
changeset
|
29 |
if i, ok := options["indent"]; ok { |
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
77
diff
changeset
|
30 |
indentInc = i |
0 | 31 |
} |
32 |
return &PlainPrinter{Indent: indentInc}, nil |
|
33 |
} |
|
34 |
||
35 |
// PrintObj sends the object as text to the writer |
|
36 |
// If the writer w is nil, standard output will be used. |
|
37 |
// For PlainPrinter, the option parameter contains the initial indent. |
|
38 |
func (p *PlainPrinter) PrintObj(obj interface{}, w io.Writer, initialIndent string) error { |
|
39 |
if w == nil { |
|
40 |
w = os.Stdout |
|
41 |
} |
|
42 |
switch o := obj.(type) { |
|
43 |
case []madon.Account, []madon.Attachment, []madon.Card, []madon.Context, |
|
192 | 44 |
[]madon.Emoji, []madon.Instance, []madon.InstancePeer, |
45 |
[]madon.List, []madon.Mention, []madon.Notification, |
|
0 | 46 |
[]madon.Relationship, []madon.Report, []madon.Results, |
192 | 47 |
[]madon.Status, []madon.StreamEvent, []madon.Tag, |
210
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
48 |
[]madon.WeekActivity, []madon.DomainName: |
0 | 49 |
return p.plainForeach(o, w, initialIndent) |
152
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
50 |
case *madon.DomainName: |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
51 |
return p.plainPrintDomainName(o, w, initialIndent) |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
52 |
case madon.DomainName: |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
53 |
return p.plainPrintDomainName(&o, w, initialIndent) |
0 | 54 |
case *madon.Account: |
55 |
return p.plainPrintAccount(o, w, initialIndent) |
|
56 |
case madon.Account: |
|
57 |
return p.plainPrintAccount(&o, w, initialIndent) |
|
58 |
case *madon.Attachment: |
|
59 |
return p.plainPrintAttachment(o, w, initialIndent) |
|
60 |
case madon.Attachment: |
|
61 |
return p.plainPrintAttachment(&o, w, initialIndent) |
|
62 |
case *madon.Card: |
|
63 |
return p.plainPrintCard(o, w, initialIndent) |
|
64 |
case madon.Card: |
|
65 |
return p.plainPrintCard(&o, w, initialIndent) |
|
66 |
case *madon.Context: |
|
67 |
return p.plainPrintContext(o, w, initialIndent) |
|
68 |
case madon.Context: |
|
69 |
return p.plainPrintContext(&o, w, initialIndent) |
|
192 | 70 |
case *madon.Emoji: |
71 |
return p.plainPrintEmoji(o, w, initialIndent) |
|
72 |
case madon.Emoji: |
|
73 |
return p.plainPrintEmoji(&o, w, initialIndent) |
|
0 | 74 |
case *madon.Instance: |
75 |
return p.plainPrintInstance(o, w, initialIndent) |
|
76 |
case madon.Instance: |
|
77 |
return p.plainPrintInstance(&o, w, initialIndent) |
|
192 | 78 |
case *madon.InstancePeer: |
79 |
return p.plainPrintInstancePeer(o, w, initialIndent) |
|
80 |
case madon.InstancePeer: |
|
81 |
return p.plainPrintInstancePeer(&o, w, initialIndent) |
|
82 |
case *madon.List: |
|
83 |
return p.plainPrintList(o, w, initialIndent) |
|
84 |
case madon.List: |
|
85 |
return p.plainPrintList(&o, w, initialIndent) |
|
0 | 86 |
case *madon.Notification: |
87 |
return p.plainPrintNotification(o, w, initialIndent) |
|
88 |
case madon.Notification: |
|
89 |
return p.plainPrintNotification(&o, w, initialIndent) |
|
90 |
case *madon.Relationship: |
|
91 |
return p.plainPrintRelationship(o, w, initialIndent) |
|
92 |
case madon.Relationship: |
|
93 |
return p.plainPrintRelationship(&o, w, initialIndent) |
|
94 |
case *madon.Report: |
|
95 |
return p.plainPrintReport(o, w, initialIndent) |
|
96 |
case madon.Report: |
|
97 |
return p.plainPrintReport(&o, w, initialIndent) |
|
98 |
case *madon.Results: |
|
99 |
return p.plainPrintResults(o, w, initialIndent) |
|
100 |
case madon.Results: |
|
101 |
return p.plainPrintResults(&o, w, initialIndent) |
|
102 |
case *madon.Status: |
|
103 |
return p.plainPrintStatus(o, w, initialIndent) |
|
104 |
case madon.Status: |
|
105 |
return p.plainPrintStatus(&o, w, initialIndent) |
|
106 |
case *madon.UserToken: |
|
107 |
return p.plainPrintUserToken(o, w, initialIndent) |
|
108 |
case madon.UserToken: |
|
109 |
return p.plainPrintUserToken(&o, w, initialIndent) |
|
210
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
110 |
case *madon.WeekActivity: |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
111 |
return p.plainPrintWeekActivity(o, w, initialIndent) |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
112 |
case madon.WeekActivity: |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
113 |
return p.plainPrintWeekActivity(&o, w, initialIndent) |
0 | 114 |
} |
115 |
// TODO: Mention |
|
116 |
// TODO: StreamEvent |
|
117 |
// TODO: Tag |
|
118 |
||
119 |
return fmt.Errorf("PlainPrinter not yet implemented for %T (try json or yaml...)", obj) |
|
120 |
} |
|
121 |
||
122 |
func (p *PlainPrinter) plainForeach(ol interface{}, w io.Writer, ii string) error { |
|
123 |
switch reflect.TypeOf(ol).Kind() { |
|
124 |
case reflect.Slice: |
|
125 |
s := reflect.ValueOf(ol) |
|
126 |
||
127 |
for i := 0; i < s.Len(); i++ { |
|
128 |
o := s.Index(i).Interface() |
|
129 |
if err := p.PrintObj(o, w, ii); err != nil { |
|
130 |
return err |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
return nil |
|
135 |
} |
|
136 |
||
137 |
func html2string(h string) string { |
|
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
121
diff
changeset
|
138 |
t, err := html2text.Textify(h) |
0 | 139 |
if err == nil { |
140 |
return t |
|
141 |
} |
|
142 |
return h // Failed: return initial string |
|
143 |
} |
|
144 |
||
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
145 |
// 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
|
146 |
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
|
147 |
switch t := ts.(type) { |
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
148 |
case int64: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
149 |
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
|
150 |
case int: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
151 |
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
|
152 |
case float64: |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
153 |
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
|
154 |
} |
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
155 |
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
|
156 |
} |
909c3ddd83f6
Add fromunix filter to templates (converts date from UNIX timestamp)
Mikael Berthe <mikael@lilotux.net>
parents:
38
diff
changeset
|
157 |
|
0 | 158 |
func indentedPrint(w io.Writer, indent string, title, skipIfEmpty bool, label string, format string, args ...interface{}) { |
159 |
prefix := indent |
|
160 |
if title { |
|
161 |
prefix += "- " |
|
162 |
} else { |
|
163 |
prefix += " " |
|
164 |
} |
|
165 |
value := fmt.Sprintf(format, args...) |
|
166 |
if !title && skipIfEmpty && len(value) == 0 { |
|
167 |
return |
|
168 |
} |
|
169 |
fmt.Fprintf(w, "%s%s: %s\n", prefix, label, value) |
|
170 |
} |
|
171 |
||
152
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
172 |
func (p *PlainPrinter) plainPrintDomainName(d *madon.DomainName, w io.Writer, indent string) error { |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
173 |
indentedPrint(w, indent, true, false, "Domain Name", "%s", string(*d)) |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
174 |
return nil |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
175 |
} |
4397b8c740e5
PlainPrinter: support for madon.DomainName
Mikael Berthe <mikael@lilotux.net>
parents:
150
diff
changeset
|
176 |
|
0 | 177 |
func (p *PlainPrinter) plainPrintAccount(a *madon.Account, w io.Writer, indent string) error { |
178 |
indentedPrint(w, indent, true, false, "Account ID", "%d (%s)", a.ID, a.Username) |
|
179 |
indentedPrint(w, indent, false, false, "User ID", "%s", a.Acct) |
|
180 |
indentedPrint(w, indent, false, false, "Display name", "%s", a.DisplayName) |
|
181 |
indentedPrint(w, indent, false, false, "Creation date", "%v", a.CreatedAt.Local()) |
|
182 |
indentedPrint(w, indent, false, false, "URL", "%s", a.URL) |
|
183 |
indentedPrint(w, indent, false, false, "Statuses count", "%d", a.StatusesCount) |
|
184 |
indentedPrint(w, indent, false, false, "Followers count", "%d", a.FollowersCount) |
|
185 |
indentedPrint(w, indent, false, false, "Following count", "%d", a.FollowingCount) |
|
186 |
if a.Locked { |
|
187 |
indentedPrint(w, indent, false, false, "Locked", "%v", a.Locked) |
|
188 |
} |
|
189 |
indentedPrint(w, indent, false, true, "User note", "%s", html2string(a.Note)) // XXX too long? |
|
207
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
190 |
if a.Moved != nil { |
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
191 |
m := a.Moved |
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
192 |
indentedPrint(w, indent+p.Indent, true, false, "Moved to account ID", "%d (%s)", m.ID, m.Username) |
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
193 |
indentedPrint(w, indent+p.Indent, false, false, "New user ID", "%s", m.Acct) |
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
194 |
indentedPrint(w, indent+p.Indent, false, false, "New display name", "%s", m.DisplayName) |
56afbe03a7d4
Printers: Display moved accounts (PlainPrinter + templates)
Mikael Berthe <mikael@lilotux.net>
parents:
206
diff
changeset
|
195 |
} |
0 | 196 |
return nil |
197 |
} |
|
198 |
||
199 |
func (p *PlainPrinter) plainPrintAttachment(a *madon.Attachment, w io.Writer, indent string) error { |
|
200 |
indentedPrint(w, indent, true, false, "Attachment ID", "%d", a.ID) |
|
201 |
indentedPrint(w, indent, false, false, "Type", "%s", a.Type) |
|
202 |
indentedPrint(w, indent, false, false, "Local URL", "%s", a.URL) |
|
203
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
203 |
if a.RemoteURL != nil { |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
204 |
indentedPrint(w, indent, false, true, "Remote URL", "%s", *a.RemoteURL) |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
205 |
} |
0 | 206 |
indentedPrint(w, indent, false, true, "Preview URL", "%s", a.PreviewURL) |
203
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
207 |
if a.TextURL != nil { |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
208 |
indentedPrint(w, indent, false, true, "Text URL", "%s", *a.TextURL) |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
209 |
} |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
210 |
if a.Description != nil { |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
211 |
indentedPrint(w, indent, false, true, "Description", "%s", *a.Description) |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
212 |
} |
0 | 213 |
return nil |
214 |
} |
|
215 |
||
216 |
func (p *PlainPrinter) plainPrintCard(c *madon.Card, w io.Writer, indent string) error { |
|
217 |
indentedPrint(w, indent, true, false, "Card title", "%s", c.Title) |
|
218 |
indentedPrint(w, indent, false, true, "Description", "%s", c.Description) |
|
219 |
indentedPrint(w, indent, false, true, "URL", "%s", c.URL) |
|
220 |
indentedPrint(w, indent, false, true, "Image", "%s", c.Image) |
|
221 |
return nil |
|
222 |
} |
|
223 |
||
224 |
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
|
225 |
indentedPrint(w, indent, true, false, "Context", "%d relative(s)", len(c.Ancestors)+len(c.Descendants)) |
0 | 226 |
if len(c.Ancestors) > 0 { |
227 |
indentedPrint(w, indent, false, false, "Ancestors", "") |
|
228 |
p.PrintObj(c.Ancestors, w, indent+p.Indent) |
|
229 |
} |
|
67
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
230 |
if len(c.Descendants) > 0 { |
c72b15bec8d9
Fix status context (sync with Madon 1.4.3)
Mikael Berthe <mikael@lilotux.net>
parents:
58
diff
changeset
|
231 |
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
|
232 |
p.PrintObj(c.Descendants, w, indent+p.Indent) |
0 | 233 |
} |
234 |
return nil |
|
235 |
} |
|
236 |
||
192 | 237 |
func (p *PlainPrinter) plainPrintEmoji(e *madon.Emoji, w io.Writer, indent string) error { |
238 |
indentedPrint(w, indent, true, false, "Emoji shortcode", "%s", e.ShortCode) |
|
239 |
indentedPrint(w, indent, false, false, "URL", "%s", e.URL) |
|
240 |
return nil |
|
241 |
} |
|
242 |
||
0 | 243 |
func (p *PlainPrinter) plainPrintInstance(i *madon.Instance, w io.Writer, indent string) error { |
244 |
indentedPrint(w, indent, true, false, "Instance title", "%s", i.Title) |
|
245 |
indentedPrint(w, indent, false, true, "Description", "%s", html2string(i.Description)) |
|
246 |
indentedPrint(w, indent, false, true, "URL", "%s", i.URI) |
|
247 |
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
|
248 |
indentedPrint(w, indent, false, true, "Version", "%s", i.Version) |
192 | 249 |
if i.ContactAccount != nil { |
250 |
c := i.ContactAccount |
|
251 |
indentedPrint(w, indent+p.Indent, true, false, "Contact account ID", "%d (%s)", c.ID, c.Username) |
|
252 |
indentedPrint(w, indent+p.Indent, false, false, "Contact user ID", "%s", c.Acct) |
|
253 |
indentedPrint(w, indent+p.Indent, false, false, "Contact display name", "%s", c.DisplayName) |
|
254 |
} |
|
255 |
return nil |
|
256 |
} |
|
257 |
||
258 |
func (p *PlainPrinter) plainPrintInstancePeer(i *madon.InstancePeer, w io.Writer, indent string) error { |
|
259 |
indentedPrint(w, indent, true, false, "Peer", "%s", *i) |
|
260 |
return nil |
|
261 |
} |
|
262 |
||
263 |
func (p *PlainPrinter) plainPrintList(l *madon.List, w io.Writer, indent string) error { |
|
264 |
indentedPrint(w, indent, true, false, "List ID", "%d", l.ID) |
|
265 |
indentedPrint(w, indent, false, false, "Title", "%s", l.Title) |
|
0 | 266 |
return nil |
267 |
} |
|
268 |
||
269 |
func (p *PlainPrinter) plainPrintNotification(n *madon.Notification, w io.Writer, indent string) error { |
|
270 |
indentedPrint(w, indent, true, false, "Notification ID", "%d", n.ID) |
|
271 |
indentedPrint(w, indent, false, false, "Type", "%s", n.Type) |
|
272 |
indentedPrint(w, indent, false, false, "Timestamp", "%v", n.CreatedAt.Local()) |
|
273 |
if n.Account != nil { |
|
274 |
indentedPrint(w, indent+p.Indent, true, false, "Account", "(%d) @%s - %s", |
|
275 |
n.Account.ID, n.Account.Acct, n.Account.DisplayName) |
|
276 |
} |
|
277 |
if n.Status != nil { |
|
278 |
p.plainPrintStatus(n.Status, w, indent+p.Indent) |
|
279 |
} |
|
280 |
return nil |
|
281 |
} |
|
282 |
||
283 |
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
|
284 |
indentedPrint(w, indent, true, false, "Account ID", "%d", r.ID) |
0 | 285 |
indentedPrint(w, indent, false, false, "Following", "%v", r.Following) |
206
102b34bb2c28
Printers: Add Relationship.showing_reblogs
Mikael Berthe <mikael@lilotux.net>
parents:
203
diff
changeset
|
286 |
//indentedPrint(w, indent, false, false, "Showing reblogs", "%v", r.ShowingReblogs) |
0 | 287 |
indentedPrint(w, indent, false, false, "Followed-by", "%v", r.FollowedBy) |
288 |
indentedPrint(w, indent, false, false, "Blocking", "%v", r.Blocking) |
|
289 |
indentedPrint(w, indent, false, false, "Muting", "%v", r.Muting) |
|
192 | 290 |
indentedPrint(w, indent, false, false, "Muting notifications", "%v", r.MutingNotifications) |
0 | 291 |
indentedPrint(w, indent, false, false, "Requested", "%v", r.Requested) |
292 |
return nil |
|
293 |
} |
|
294 |
||
295 |
func (p *PlainPrinter) plainPrintReport(r *madon.Report, w io.Writer, indent string) error { |
|
296 |
indentedPrint(w, indent, true, false, "Report ID", "%d", r.ID) |
|
297 |
indentedPrint(w, indent, false, false, "Action taken", "%s", r.ActionTaken) |
|
298 |
return nil |
|
299 |
} |
|
300 |
||
301 |
func (p *PlainPrinter) plainPrintResults(r *madon.Results, w io.Writer, indent string) error { |
|
302 |
indentedPrint(w, indent, true, false, "Results", "%d account(s), %d status(es), %d hashtag(s)", |
|
303 |
len(r.Accounts), len(r.Statuses), len(r.Hashtags)) |
|
304 |
if len(r.Accounts) > 0 { |
|
305 |
indentedPrint(w, indent, false, false, "Accounts", "") |
|
306 |
p.PrintObj(r.Accounts, w, indent+p.Indent) |
|
307 |
} |
|
308 |
if len(r.Statuses) > 0 { |
|
309 |
indentedPrint(w, indent, false, false, "Statuses", "") |
|
310 |
p.PrintObj(r.Statuses, w, indent+p.Indent) |
|
311 |
} |
|
312 |
if len(r.Hashtags) > 0 { |
|
313 |
indentedPrint(w, indent, false, false, "Hashtags", "") |
|
314 |
for _, tag := range r.Hashtags { |
|
315 |
indentedPrint(w, indent+p.Indent, true, false, "Tag", "%s", tag) |
|
316 |
} |
|
317 |
} |
|
318 |
return nil |
|
319 |
} |
|
320 |
||
321 |
func (p *PlainPrinter) plainPrintStatus(s *madon.Status, w io.Writer, indent string) error { |
|
322 |
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
|
323 |
if s.Account != nil { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
324 |
author := s.Account.Acct |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
325 |
if s.Account.DisplayName != "" { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
326 |
author += " (" + s.Account.DisplayName + ")" |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
327 |
} |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
328 |
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
|
329 |
} |
192 | 330 |
if s.Pinned { |
331 |
indentedPrint(w, indent, false, false, "Pinned", "%v", s.Pinned) |
|
332 |
} |
|
162
3118ab97c8df
PlainPrinter: Display when a message is private
Mikael Berthe <mikael@lilotux.net>
parents:
152
diff
changeset
|
333 |
if s.Visibility == "private" { |
3118ab97c8df
PlainPrinter: Display when a message is private
Mikael Berthe <mikael@lilotux.net>
parents:
152
diff
changeset
|
334 |
indentedPrint(w, indent, false, false, "Private", "true") |
3118ab97c8df
PlainPrinter: Display when a message is private
Mikael Berthe <mikael@lilotux.net>
parents:
152
diff
changeset
|
335 |
} |
0 | 336 |
indentedPrint(w, indent, false, false, "Timestamp", "%v", s.CreatedAt.Local()) |
337 |
||
338 |
if s.Reblog != nil { |
|
121
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
339 |
if s.Reblog.Account != nil { |
10453a1c5698
PlainPrinter: Display username of a status author
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
340 |
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
|
341 |
} |
0 | 342 |
return p.plainPrintStatus(s.Reblog, w, indent+p.Indent) |
343 |
} |
|
344 |
||
77
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
345 |
if s.Sensitive { |
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
346 |
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
|
347 |
} |
23b2b6c5643e
PlainPrinter: Display when 'sensitive' (aka NSFW) is set
Mikael Berthe <mikael@lilotux.net>
parents:
67
diff
changeset
|
348 |
|
0 | 349 |
indentedPrint(w, indent, false, false, "Contents", "%s", html2string(s.Content)) |
172
0d651f070319
Update types to reflect Mastodon 2.0.0 API changes
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
350 |
if s.InReplyToID != nil && *s.InReplyToID > 0 { |
0d651f070319
Update types to reflect Mastodon 2.0.0 API changes
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
351 |
indentedPrint(w, indent, false, false, "In-Reply-To", "%d", *s.InReplyToID) |
0 | 352 |
} |
353 |
if s.Reblogged { |
|
354 |
indentedPrint(w, indent, false, false, "Reblogged", "%v", s.Reblogged) |
|
355 |
} |
|
356 |
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
|
357 |
// Display minimum details of attachments |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
358 |
//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
|
359 |
for _, a := range s.MediaAttachments { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
360 |
indentedPrint(w, indent+p.Indent, true, false, "Attachment ID", "%d", a.ID) |
150
7f46bcaf240c
Sync with Madon library update
Mikael Berthe <mikael@lilotux.net>
parents:
148
diff
changeset
|
361 |
if a.TextURL != nil && *a.TextURL != "" { |
7f46bcaf240c
Sync with Madon library update
Mikael Berthe <mikael@lilotux.net>
parents:
148
diff
changeset
|
362 |
indentedPrint(w, indent+p.Indent, true, false, "Text URL", "%s", *a.TextURL) |
58
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
363 |
} else if a.URL != "" { |
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
364 |
indentedPrint(w, indent+p.Indent, false, false, "URL", "%s", a.URL) |
150
7f46bcaf240c
Sync with Madon library update
Mikael Berthe <mikael@lilotux.net>
parents:
148
diff
changeset
|
365 |
} else if a.RemoteURL != nil { |
7f46bcaf240c
Sync with Madon library update
Mikael Berthe <mikael@lilotux.net>
parents:
148
diff
changeset
|
366 |
indentedPrint(w, indent+p.Indent, false, false, "Remote URL", "%s", *a.RemoteURL) |
58
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
367 |
} |
203
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
368 |
if a.Description != nil && *a.Description != "" { |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
369 |
indentedPrint(w, indent+p.Indent, false, true, "Description", "%s", a.Description) |
71455784278b
PlainPrinter: Fix attachment output
Mikael Berthe <mikael@lilotux.net>
parents:
194
diff
changeset
|
370 |
} |
58
5a0cb1e65e65
PlainPrinter: Display attachment URLs in statuses
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
371 |
} |
0 | 372 |
return nil |
373 |
} |
|
374 |
||
375 |
func (p *PlainPrinter) plainPrintUserToken(s *madon.UserToken, w io.Writer, indent string) error { |
|
376 |
indentedPrint(w, indent, true, false, "User token", "%s", s.AccessToken) |
|
377 |
indentedPrint(w, indent, false, true, "Type", "%s", s.TokenType) |
|
378 |
if s.CreatedAt != 0 { |
|
120
54b6f2a4098b
Add template command tolocal; update templates and documentation
Mikael Berthe <mikael@lilotux.net>
parents:
84
diff
changeset
|
379 |
indentedPrint(w, indent, false, true, "Timestamp", "%v", time.Unix(s.CreatedAt, 0)) |
0 | 380 |
} |
381 |
indentedPrint(w, indent, false, true, "Scope", "%s", s.Scope) |
|
382 |
return nil |
|
383 |
} |
|
210
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
384 |
|
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
385 |
func (p *PlainPrinter) plainPrintWeekActivity(a *madon.WeekActivity, w io.Writer, indent string) error { |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
386 |
indentedPrint(w, indent, true, false, "Activity week", "%v", a.Week.Format("2006-01-02")) |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
387 |
indentedPrint(w, indent, false, true, "Weekly logins", "%d", a.Logins) |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
388 |
indentedPrint(w, indent, false, true, "Weekly statuses", "%d", a.Statuses) |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
389 |
indentedPrint(w, indent, false, true, "Weekly registrations", "%d", a.Registrations) |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
390 |
return nil |
94be15243195
PlainPrinter: Add WeekActivity format
Mikael Berthe <mikael@lilotux.net>
parents:
207
diff
changeset
|
391 |
} |