chore: claude code refactor (7.5/10)
This commit is contained in:
66
main.ts
66
main.ts
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env
|
||||
#!/usr/bin/env -S deno run --allow-read --allow-write
|
||||
|
||||
import { Command } from "@cliffy/command";
|
||||
import { colors } from "@cliffy/ansi/colors";
|
||||
@@ -104,17 +104,24 @@ class MorseGame {
|
||||
streak: session.bestStreak,
|
||||
};
|
||||
|
||||
await updateStats(gameResult);
|
||||
try {
|
||||
await updateStats(gameResult);
|
||||
} catch (error) {
|
||||
console.log(colors.red("\n⚠ Warning: Failed to save statistics"));
|
||||
if (error instanceof Error) {
|
||||
console.log(colors.gray(error.message));
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for user to continue
|
||||
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);
|
||||
});
|
||||
Deno.stdin.read(buf)
|
||||
.then(() => resolve(undefined))
|
||||
.catch(() => resolve(undefined))
|
||||
.finally(() => Deno.stdin.setRaw(false));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,10 +137,10 @@ class MorseGame {
|
||||
await new Promise((resolve) => {
|
||||
const buf = new Uint8Array(1);
|
||||
Deno.stdin.setRaw(true);
|
||||
Deno.stdin.read(buf).then(() => {
|
||||
Deno.stdin.setRaw(false);
|
||||
resolve(undefined);
|
||||
});
|
||||
Deno.stdin.read(buf)
|
||||
.then(() => resolve(undefined))
|
||||
.catch(() => resolve(undefined))
|
||||
.finally(() => Deno.stdin.setRaw(false));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,10 +155,10 @@ class MorseGame {
|
||||
await new Promise((resolve) => {
|
||||
const buf = new Uint8Array(1);
|
||||
Deno.stdin.setRaw(true);
|
||||
Deno.stdin.read(buf).then(() => {
|
||||
Deno.stdin.setRaw(false);
|
||||
resolve(undefined);
|
||||
});
|
||||
Deno.stdin.read(buf)
|
||||
.then(() => resolve(undefined))
|
||||
.catch(() => resolve(undefined))
|
||||
.finally(() => Deno.stdin.setRaw(false));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -171,8 +178,15 @@ class MorseGame {
|
||||
);
|
||||
|
||||
if (confirmed) {
|
||||
await resetStats();
|
||||
console.log(colors.green("\n✓ Statistics have been reset.\n"));
|
||||
try {
|
||||
await resetStats();
|
||||
console.log(colors.green("\n✓ Statistics have been reset.\n"));
|
||||
} catch (error) {
|
||||
console.log(colors.red("\n⚠ Error: Failed to reset statistics"));
|
||||
if (error instanceof Error) {
|
||||
console.log(colors.gray(error.message));
|
||||
}
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
}
|
||||
}
|
||||
@@ -224,7 +238,14 @@ class MorseGame {
|
||||
streak: session.bestStreak,
|
||||
};
|
||||
|
||||
await updateStats(gameResult);
|
||||
try {
|
||||
await updateStats(gameResult);
|
||||
} catch (error) {
|
||||
console.log(colors.red("\n⚠ Warning: Failed to save statistics"));
|
||||
if (error instanceof Error) {
|
||||
console.log(colors.gray(error.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,8 +305,15 @@ await new Command()
|
||||
);
|
||||
|
||||
if (confirmed) {
|
||||
await resetStats();
|
||||
console.log(colors.green("\n✓ Statistics have been reset.\n"));
|
||||
try {
|
||||
await resetStats();
|
||||
console.log(colors.green("\n✓ Statistics have been reset.\n"));
|
||||
} catch (error) {
|
||||
console.log(colors.red("\n⚠ Error: Failed to reset statistics"));
|
||||
if (error instanceof Error) {
|
||||
console.log(colors.gray(error.message));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(colors.yellow("\nCancelled.\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user