Skip to content

Commit 049f84a

Browse files
committed
data: TrackSection: custom util.inspect (number & range info)
1 parent 0db3ac0 commit 049f84a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/data/things/album.js

+47
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export const DATA_ALBUM_DIRECTORY = 'album';
22

33
import * as path from 'node:path';
4+
import {inspect} from 'node:util';
45

6+
import CacheableObject from '#cacheable-object';
7+
import {colors} from '#cli';
58
import {input} from '#composite';
69
import find from '#find';
710
import {traverse} from '#node-utils';
@@ -578,4 +581,48 @@ export class TrackSection extends Thing {
578581
},
579582
},
580583
};
584+
585+
[inspect.custom](depth) {
586+
const parts = [];
587+
588+
parts.push(Thing.prototype[inspect.custom].apply(this));
589+
590+
if (depth >= 0) {
591+
let album = null;
592+
try {
593+
album = this.album;
594+
} catch {}
595+
596+
let first = null;
597+
try {
598+
first = this.startIndex;
599+
} catch {}
600+
601+
let length = null;
602+
try {
603+
length = this.tracks.length;
604+
} catch {}
605+
606+
album ??= CacheableObject.getUpdateValue(this, 'ownAlbumData')?.[0];
607+
608+
if (album) {
609+
const albumName = album.name;
610+
const albumIndex = album.trackSections.indexOf(this);
611+
612+
const num =
613+
(albumIndex === -1
614+
? 'indeterminate position'
615+
: `#${albumIndex + 1}`);
616+
617+
const range =
618+
(albumIndex >= 0 && first !== null && length !== null
619+
? `: ${first + 1}-${first + length + 1}`
620+
: '');
621+
622+
parts.push(` (${colors.yellow(num + range)} in ${colors.green(albumName)})`);
623+
}
624+
}
625+
626+
return parts.join('');
627+
}
581628
}

0 commit comments

Comments
 (0)