« get me outta code hell

data: Series: custom inspect - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
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
commit9bd6637fbd778650db42cd85baa0057cd5be8083 (patch)
treee24053ade651fa8a8c6b52945ed0b8df9012d3e6
parent42a8568371acf5dfc7ec2a6dc1bcee2e66e0ee98 (diff)
data: Series: custom inspect preview
-rw-r--r--src/data/things/album.js30
-rw-r--r--src/data/things/group.js30
2 files changed, 45 insertions, 15 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 7a7b387d..a4c2f6a5 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -970,11 +970,13 @@ export class TrackSection extends Thing {
 
     parts.push(Thing.prototype[inspect.custom].apply(this));
 
-    if (depth >= 0) {
+    if (depth >= 0) showAlbum: {
       let album = null;
       try {
         album = this.album;
-      } catch {}
+      } catch {
+        break showAlbum;
+      }
 
       let first = null;
       try {
@@ -986,22 +988,20 @@ export class TrackSection extends Thing {
         last = this.tracks.at(-1).trackNumber;
       } catch {}
 
-      if (album) {
-        const albumName = album.name;
-        const albumIndex = album.trackSections.indexOf(this);
+      const albumName = album.name;
+      const albumIndex = album.trackSections.indexOf(this);
 
-        const num =
-          (albumIndex === -1
-            ? 'indeterminate position'
-            : `#${albumIndex + 1}`);
+      const num =
+        (albumIndex === -1
+          ? 'indeterminate position'
+          : `#${albumIndex + 1}`);
 
-        const range =
-          (albumIndex >= 0 && first !== null && last !== null
-            ? `: ${first}-${last}`
-            : '');
+      const range =
+        (albumIndex >= 0 && first !== null && last !== null
+          ? `: ${first}-${last}`
+          : '');
 
-        parts.push(` (${colors.yellow(num + range)} in ${colors.green(albumName)})`);
-      }
+      parts.push(` (${colors.yellow(num + range)} in ${colors.green(`"${albumName}"`)})`);
     }
 
     return parts.join('');
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('');
+  }
 }