From 24d8a8d288768e5969a21e1addc1077b15105f9d Mon Sep 17 00:00:00 2001 From: He4eT Date: Mon, 25 Dec 2023 15:53:42 +0100 Subject: [PATCH] index.js: use fuzzySelect --- index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 89108ec..a210001 100755 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ #!/usr/bin/env node const xml2js = require('xml2js') +const inquirer = require('inquirer') +inquirer.registerPrompt('search-list', require('inquirer-search-list')) const channelsUrl = 'https://somafm.com/channels.xml' @@ -14,12 +16,22 @@ const download = (url) => } }) +const fuzzySelect = (choices) => + inquirer.prompt([{ + type: "search-list", + message: "Select SomaFM channel", + name: "channel", + choices, + pageSize: 10, + }]) + download(channelsUrl) .then(xml2js.parseStringPromise) .then((json) => json.channels.channel) .then((channels) => channels.map((channel) => ({ - title: `${channel.title[0]} — ${channel.description[0]}`, + name: `${channel.title[0]} — ${channel.description[0]}`, value: channel.highestpls[0]['_'], }))) + .then(fuzzySelect) .then((x) => console.log(x)) .catch((error) => console.error('Error:', error.message))