whspr 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recorder.js +8 -25
- package/package.json +1 -1
package/dist/recorder.js
CHANGED
|
@@ -5,7 +5,7 @@ import os from "os";
|
|
|
5
5
|
import chalk from "chalk";
|
|
6
6
|
const MAX_DURATION_SECONDS = 900; // 15 minutes
|
|
7
7
|
const DEFAULT_WAVE_WIDTH = 60;
|
|
8
|
-
const
|
|
8
|
+
const BRACKET_WIDTH = 2; // For "[" and "]" wrapping the waveform
|
|
9
9
|
// Horizontal bar characters for waveform (quiet to loud)
|
|
10
10
|
const WAVE_CHARS = ["·", "-", "=", "≡", "■", "█"];
|
|
11
11
|
function formatTime(seconds) {
|
|
@@ -22,12 +22,9 @@ function dbToChar(db) {
|
|
|
22
22
|
}
|
|
23
23
|
function getWaveWidth() {
|
|
24
24
|
const termWidth = process.stdout.columns || 80;
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
// Otherwise, use full terminal width for wave (will wrap text to next line)
|
|
30
|
-
return Math.max(10, termWidth - 2);
|
|
25
|
+
// Use full terminal width minus brackets and small margin
|
|
26
|
+
const availableWidth = termWidth - BRACKET_WIDTH - 2;
|
|
27
|
+
return Math.max(10, Math.min(DEFAULT_WAVE_WIDTH, availableWidth));
|
|
31
28
|
}
|
|
32
29
|
export async function record(verbose = false) {
|
|
33
30
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "whspr-"));
|
|
@@ -59,16 +56,8 @@ export async function record(verbose = false) {
|
|
|
59
56
|
const elapsed = formatTime(elapsedSeconds);
|
|
60
57
|
const max = formatTime(MAX_DURATION_SECONDS);
|
|
61
58
|
const wave = waveBuffer.join("");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (termWidth >= singleLineWidth) {
|
|
65
|
-
// Single line layout
|
|
66
|
-
process.stdout.write(`\x1b[2K\r${chalk.cyan(wave)} ${chalk.blue("Recording")} [${chalk.yellow(elapsed)} / ${max}] ${chalk.gray("Press Enter to stop")}`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// Two line layout: wave on first line, status on second
|
|
70
|
-
process.stdout.write(`\x1b[2K\r${chalk.cyan(wave)}\n\x1b[2K${chalk.blue("Recording")} [${chalk.yellow(elapsed)} / ${max}] ${chalk.gray("Press Enter to stop")}\x1b[A\r`);
|
|
71
|
-
}
|
|
59
|
+
// Always render waveform on its own line, wrapped in brackets
|
|
60
|
+
process.stdout.write(`\x1b[2K\r${chalk.cyan(`[${wave}]`)}\n\x1b[2K${chalk.blue("Recording")} [${chalk.yellow(elapsed)} / ${max}] ${chalk.gray("Press Enter to stop")}\x1b[A\r`);
|
|
72
61
|
}
|
|
73
62
|
// Update timer every second
|
|
74
63
|
const timer = setInterval(() => {
|
|
@@ -131,14 +120,8 @@ export async function record(verbose = false) {
|
|
|
131
120
|
ffmpeg.on("close", (code) => {
|
|
132
121
|
clearInterval(timer);
|
|
133
122
|
clearInterval(waveTimer);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (termWidth >= singleLineWidth) {
|
|
137
|
-
process.stdout.write("\x1b[2K\r"); // Clear the line
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
process.stdout.write("\x1b[2K\n\x1b[2K\x1b[A\r"); // Clear both lines
|
|
141
|
-
}
|
|
123
|
+
// Clear both lines (waveform and status)
|
|
124
|
+
process.stdout.write("\x1b[2K\n\x1b[2K\x1b[A\r");
|
|
142
125
|
if (cancelled) {
|
|
143
126
|
// User pressed Ctrl+C - clean up and reject
|
|
144
127
|
if (fs.existsSync(wavPath)) {
|