diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-05-18 11:08:06 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-05-18 11:25:02 -0300 |
commit | 9bd6637fbd778650db42cd85baa0057cd5be8083 (patch) | |
tree | e24053ade651fa8a8c6b52945ed0b8df9012d3e6 /src/data/things/group.js | |
parent | 42a8568371acf5dfc7ec2a6dc1bcee2e66e0ee98 (diff) |
data: Series: custom inspect preview
Diffstat (limited to 'src/data/things/group.js')
-rw-r--r-- | src/data/things/group.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/data/things/group.js b/src/data/things/group.js index 294c02c6..4b4c306c 100644 --- a/src/data/things/group.js +++ b/src/data/things/group.js @@ -1,5 +1,8 @@ export const GROUP_DATA_FILE = 'groups.yaml'; +import {inspect} from 'node:util'; + +import {colors} from '#cli'; import {input} from '#composite'; import Thing from '#thing'; import {is} from '#validators'; @@ -285,4 +288,31 @@ export class Series extends Thing { 'Albums': {property: 'albums'}, }, }; + + [inspect.custom](depth, options, inspect) { + const parts = []; + + parts.push(Thing.prototype[inspect.custom].apply(this)); + + if (depth >= 0) showGroup: { + let group = null; + try { + group = this.group; + } catch { + break showGroup; + } + + const groupName = group.name; + const groupIndex = group.serieses.indexOf(this); + + const num = + (groupIndex === -1 + ? 'indeterminate position' + : `#${groupIndex + 1}`); + + parts.push(` (${colors.yellow(num)} in ${colors.green(`"${groupName}"`)})`); + } + + return parts.join(''); + } } |