add --id flag to scene list and scene current

scene list no longer displays IDs by default

Active column added to scene list
This commit is contained in:
onyx-and-iris 2025-06-30 19:30:36 +01:00
parent 597b9e6ee0
commit faa73e8f07
6 changed files with 28 additions and 14 deletions

View File

@ -33,7 +33,7 @@ socket.onopen = function () {
switch (sceneCommand) { switch (sceneCommand) {
case 'list': case 'list':
channel = new QWebChannel(socket, function (channel) { channel = new QWebChannel(socket, function (channel) {
sceneList(channel) sceneList(channel, flags.id)
.then((scenes) => { .then((scenes) => {
console.log(scenes) console.log(scenes)
socket.close() socket.close()
@ -68,7 +68,7 @@ socket.onopen = function () {
break break
case 'current': case 'current':
channel = new QWebChannel(socket, function (channel) { channel = new QWebChannel(socket, function (channel) {
sceneCurrent(channel) sceneCurrent(channel, flags.id)
.then((message) => { .then((message) => {
console.log(message) console.log(message)
socket.close() socket.close()

View File

@ -29,7 +29,7 @@ const audioHelp = meowHelp({
name: 'meld-cli audio', name: 'meld-cli audio',
flags, flags,
commands, commands,
description: 'Manage audio settings in Meld', desc: 'Manage audio settings in Meld',
defaults: false defaults: false
}) })

View File

@ -43,7 +43,6 @@ const helpText = meowHelp({
name: 'meld-cli', name: 'meld-cli',
flags, flags,
commands, commands,
description: 'A command-line interface for managing scenes in Meld',
defaults: false defaults: false
}) })

View File

@ -24,7 +24,7 @@ const recordHelp = meowHelp({
name: 'meld-cli record', name: 'meld-cli record',
flags, flags,
commands, commands,
description: 'Manage recording in Meld', desc: 'Manage recording in Meld',
defaults: false defaults: false
}) })

View File

@ -5,13 +5,13 @@ import { highlight, error, errorHighlight } from './style.js'
const commands = { const commands = {
list: { list: {
desc: 'List all scenes' desc: 'List all scenes, optionally showing IDs'
}, },
switch: { switch: {
desc: 'Switch to a scene by name' desc: 'Switch to a scene by name'
}, },
current: { current: {
desc: 'Show the current scene' desc: 'Show the current scene, optionally showing its ID'
} }
} }
@ -20,6 +20,10 @@ const flags = {
type: 'boolean', type: 'boolean',
shortFlag: 'h', shortFlag: 'h',
desc: 'Display help information' desc: 'Display help information'
},
id: {
type: 'boolean',
desc: 'Display scene IDs'
} }
} }
@ -27,27 +31,35 @@ const sceneHelp = meowHelp({
name: 'meld-cli scene', name: 'meld-cli scene',
flags, flags,
commands, commands,
description: 'Manage scenes in Meld', desc: 'Manage scenes in Meld',
defaults: false defaults: false
}) })
function sceneList (channel) { function sceneList (channel, showId) {
if (!channel.objects || !channel.objects.meld) { if (!channel.objects || !channel.objects.meld) {
return Promise.reject(new Error('Meld object not found in channel.')) return Promise.reject(new Error('Meld object not found in channel.'))
} }
const headers = [{ content: 'Scene Name', hAlign: 'center' }, { content: 'Active', hAlign: 'center' }]
if (showId) {
headers.push({ content: 'ID', hAlign: 'center' })
}
const table = new Table({ const table = new Table({
style: { style: {
head: ['none'], head: ['none'],
compact: true compact: true
}, },
head: [{ content: 'Scene Name', hAlign: 'center' }, { content: 'ID', hAlign: 'center' }] head: headers
}) })
const meld = channel.objects.meld const meld = channel.objects.meld
for (const [key, value] of Object.entries(meld.session.items)) { for (const [key, value] of Object.entries(meld.session.items)) {
if (value.type === 'scene') { if (value.type === 'scene') {
table.push([highlight(value.name), highlight(key)]) if (showId) {
table.push([highlight(value.name), { content: value.current ? highlight('✓') : '✗', hAlign: 'center' }, highlight(key)])
} else {
table.push([highlight(value.name), { content: value.current ? highlight('✓') : '✗', hAlign: 'center' }])
}
} }
} }
if (table.length === 0) { if (table.length === 0) {
@ -82,7 +94,7 @@ function sceneSwitch (channel, sceneName) {
}) })
} }
function sceneCurrent (channel) { function sceneCurrent (channel, showId) {
if (!channel.objects || !channel.objects.meld) { if (!channel.objects || !channel.objects.meld) {
return Promise.reject(new Error('Meld object not found in channel.')) return Promise.reject(new Error('Meld object not found in channel.'))
} }
@ -90,7 +102,10 @@ function sceneCurrent (channel) {
const meld = channel.objects.meld const meld = channel.objects.meld
for (const [key, value] of Object.entries(meld.session.items)) { for (const [key, value] of Object.entries(meld.session.items)) {
if (value.type === 'scene' && value.current) { if (value.type === 'scene' && value.current) {
return Promise.resolve(`Current scene: ${highlight(value.name)} (ID: ${highlight(key)})`) if (showId) {
return Promise.resolve(`Current scene: ${highlight(value.name)} (ID: ${highlight(key)})`)
}
return Promise.resolve(`Current scene: ${highlight(value.name)}`)
} }
} }
return Promise.reject(new Error('No current scene found.')) return Promise.reject(new Error('No current scene found.'))

View File

@ -24,7 +24,7 @@ const streamHelp = meowHelp({
name: 'meld-cli stream', name: 'meld-cli stream',
flags, flags,
commands, commands,
description: 'Manage streaming in Meld', desc: 'Manage streaming in Meld',
defaults: false defaults: false
}) })