feat: added translation, updated readme
This commit is contained in:
57
ui.ts
57
ui.ts
@@ -42,6 +42,7 @@ export async function showMainMenu(): Promise<string> {
|
||||
{ name: "Start New Game", value: "play" },
|
||||
{ name: "View Statistics", value: "stats" },
|
||||
{ name: "Morse Code Reference", value: "reference" },
|
||||
{ name: "Translator", value: "translator" },
|
||||
{ name: "Reset Statistics", value: "reset" },
|
||||
{ name: "Exit", value: "exit" },
|
||||
],
|
||||
@@ -50,6 +51,62 @@ export async function showMainMenu(): Promise<string> {
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show translator utility
|
||||
*/
|
||||
export async function showTranslator(): Promise<void> {
|
||||
clearScreen();
|
||||
console.log(colors.bold.cyan("\n=== Morse Code Translator ===\n"));
|
||||
|
||||
const direction = await Select.prompt({
|
||||
message: "Select translation direction:",
|
||||
options: [
|
||||
{ name: "Text → Morse Code", value: "toMorse" },
|
||||
{ name: "Morse Code → Text", value: "toText" },
|
||||
],
|
||||
});
|
||||
|
||||
if (direction === "toMorse") {
|
||||
const text = await Input.prompt({
|
||||
message: "Enter text to translate:",
|
||||
validate: (value) => {
|
||||
if (!value.trim()) {
|
||||
return "Please enter some text";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const morse = textToMorse(text.toUpperCase());
|
||||
console.log(colors.bold.green("\nTranslation:"));
|
||||
console.log(colors.yellow(morse));
|
||||
} else {
|
||||
const morse = await Input.prompt({
|
||||
message: "Enter Morse code to translate (use dots and dashes):",
|
||||
validate: (value) => {
|
||||
if (!value.trim()) {
|
||||
return "Please enter some Morse code";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const text = morseToText(morse);
|
||||
console.log(colors.bold.green("\nTranslation:"));
|
||||
console.log(colors.yellow(text));
|
||||
}
|
||||
|
||||
console.log(colors.gray("\nPress Enter to continue..."));
|
||||
await new Promise((resolve) => {
|
||||
const buf = new Uint8Array(1);
|
||||
Deno.stdin.setRaw(true);
|
||||
Deno.stdin.read(buf).then(() => {
|
||||
Deno.stdin.setRaw(false);
|
||||
resolve(undefined);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select game mode
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user