git ssb

15+

ansuz / dnssb



Commit ef5b680f12314fbee18f0b73237211b34f26360c

show: Format more compactly

Pad fields to their max width, except for the author name field, because
that is not known until the feed names are looked up.
cel committed on 11/8/2016, 11:38:02 PM
Parent: a5f3e744fecfdc61e4a4bb7a227a0cd49746986a

Files changed

lib/dump.jschanged
lib/format.jschanged
lib/dump.jsView
@@ -44,9 +44,9 @@
4444 record.authorName = '@' + about.name;
4545 cb(err, record);
4646 });
4747 }, 8),
48- Pull.map(Format.recordToLine),
48 + Pull.map(Format.recordsToLines(Format.getMaxLengths(records))),
4949 Pull.drain(each, done))
5050 }));
5151 });
5252 };
lib/format.jsView
@@ -23,20 +23,33 @@
2323 record.name = record.name.replace(nameRegexp, '') || '@';
2424 };
2525 };
2626
27-Format.recordToLine = function (record) {
28- return [
29- record.id,
30- pad(record.authorName, 12),
31- pad(record.name, -24),
32- pad(record.ttl, -5),
33- pad(record.class, -3),
34- pad(record.type, 5),
35- dataToString(record, record.data)
36- ].join(' ');
27 +Format.getMaxLengths = function (records) {
28 + var maxLengths = {};
29 + records.forEach(function (record) {
30 + for (var k in record) {
31 + var len = String(record[k]).length
32 + if (len > ~~maxLengths[k]) maxLengths[k] = len;
33 + }
34 + });
35 + return maxLengths;
3736 };
3837
38 +Format.recordsToLines = function (maxLengths) {
39 + return function (record) {
40 + return [
41 + record.id,
42 + pad(record.authorName, 12),
43 + pad(record.name, -maxLengths.name),
44 + pad(record.ttl, -maxLengths.ttl),
45 + pad(record.class, maxLengths.class),
46 + pad(record.type, maxLengths.type),
47 + dataToString(record, record.data)
48 + ].join(' ');
49 + };
50 +};
51 +
3952 function dataToString(record, data) {
4053 switch (record.class + " " + record.type) {
4154 case "IN A":
4255 case "IN AAAA":

Built with git-ssb-web