This commit is contained in:
Eri Ishihara 2025-08-02 21:44:32 +02:00
parent 8816fe5b39
commit 7216a7ab33

134
lydia.js
View file

@ -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 <text> - if you want to force my expression, here you go! not sure i'll be too happy about it though.\nl!prompt <text> - 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", () => {