From 7216a7ab33f15a1dca7592dcbea29c08e59619e5 Mon Sep 17 00:00:00 2001 From: Eri Date: Sat, 2 Aug 2025 21:44:32 +0200 Subject: [PATCH] menu --- lydia.js | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/lydia.js b/lydia.js index 760afbf..c0fc241 100644 --- a/lydia.js +++ b/lydia.js @@ -81,15 +81,87 @@ const inputBox = blessed.textbox({ mouse: true, placeholder: `go on, tell ${assistantname} something!`, }); + +const menuBox = blessed.list({ + top: "center", + left: "center", + width: 60, + height: 16, + border: { + type: "line", + }, + style: { + border: { + fg: "cyan", + }, + bg: "black", + selected: { + bg: "cyan", + fg: "black", + }, + item: { + fg: "white", + }, + }, + keys: true, + vi: true, + mouse: true, + hidden: true, + label: ` ${assistantname} menu `, + items: ["help & commands", "clear chat history", `exit ${assistantname}`], +}); + +const popup = blessed.box({ + parent: screen, + top: "center", + left: "center", + width: 40, + height: 8, + border: { + type: "line", + }, + style: { + border: { + fg: "cyan", + }, + bg: "black", + }, + tags: true, + hidden: true, + content: "", +}); + +const popupButton = blessed.button({ + parent: popup, + bottom: 1, + left: "center", + width: 8, + height: 3, + content: "OK", + style: { + bg: "cyan", + fg: "black", + focus: { + bg: "white", + fg: "black", + }, + }, + mouse: true, + keys: true, +}); + screen.append(faceBox); screen.append(chatBox); screen.append(inputBox); +screen.append(menuBox); +screen.append(popup); inputBox.focus(); let chatHistory = []; let conversationHistory = []; let currentStreamMessage = ""; +let menuVisible = false; function addMessage(role, content) { let message; @@ -204,6 +276,40 @@ function clearChatHistory() { screen.render(); } +function showMenu() { + menuVisible = true; + menuBox.show(); + menuBox.focus(); + screen.render(); +} + +function hideMenu() { + menuVisible = false; + menuBox.hide(); + inputBox.focus(); + screen.render(); +} + +function handleMenuSelection() { + const selectedIndex = menuBox.selected; + hideMenu(); + + switch (selectedIndex) { + case 0: + addMessage( + assistantname, + "available commands:\nl!help - if you wanna know what i can do, run this!\nl!clear - clear chat history, if you want me to forget everything, just run this!\nl!face - if you want to force my expression, here you go! not sure i'll be too happy about it though.\nl!prompt - if you want to change how i act, here you go! not sure i'll be too happy about that either.\n\nMenu shortcuts:\nESC - open/close menu\nUp/Down arrows - navigate menu\nEnter - select option\nCtrl+C or q - quit application\n", + ); + break; + case 1: + clearChatHistory(); + addMessage("system", "SYSTEM: Chat history cleared."); + break; + case 2: + process.exit(0); + } +} + async function sendMessage(message) { if (!message.trim()) return; @@ -299,7 +405,33 @@ screen.key(["q", "C-c"], () => { }); screen.key(["escape"], () => { - // menu soon when i decide that i wanna do it + if (menuVisible) { + hideMenu(); + } else { + showMenu(); + } +}); + +menuBox.on("select", (item, selected) => { + if (menuVisible) { + handleMenuSelection(); + } +}); + +popupButton.on("press", () => { + popup.hide(); + inputBox.focus(); + screen.render(); +}); + +screen.key(["enter"], () => { + if (!popup.hidden) { + popup.hide(); + inputBox.focus(); + screen.render(); + } else if (menuVisible) { + handleMenuSelection(); + } }); screen.on("resize", () => {