Skip to content

Commit 513f2c1

Browse files
committed
Fix lineWidth issue
1 parent 0f34acf commit 513f2c1

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ViewType,
88
} from '@augmentos/sdk';
99
import { TranscriptProcessor } from './utils/src/text-wrapping/TranscriptProcessor';
10+
import { convertLineWidth } from './utils/src/text-wrapping/convertLineWidth';
1011

1112
// Configuration constants
1213
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 80;
@@ -380,10 +381,12 @@ class TeleprompterApp extends TpaServer {
380381
): Promise<void> {
381382
try {
382383
// Extract settings from the session
383-
const lineWidth = session.settings.get<number>('line_width', 38);
384+
const lineWidthString = session.settings.get<string>('line_width', "Medium");
384385
const scrollSpeed = session.settings.get<number>('scroll_speed', 120);
385386
const numberOfLines = session.settings.get<number>('number_of_lines', 4);
386387
const customText = session.settings.get<string>('custom_text', '');
388+
389+
const lineWidth = convertLineWidth(lineWidthString, false);
387390

388391
console.log(`Applied settings for user ${userId}: lineWidth=${lineWidth}, scrollSpeed=${scrollSpeed}, numberOfLines=${numberOfLines}`);
389392

src/utils/src/text-wrapping/TranscriptProcessor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ export class TranscriptProcessor {
164164

165165
// Wrap text into lines based on max line length
166166
public wrapText(text: string, maxLineLength: number): string[] {
167+
if (typeof maxLineLength !== "number" || isNaN(maxLineLength)) {
168+
throw new Error(`wrapText: maxLineLength must be a number, got ${typeof maxLineLength}: ${maxLineLength}`);
169+
}
167170
const result: string[] = [];
168171
// Split the text by newlines first
169172
const lines = text.split(/\r?\n/);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Converts a line width setting to a numeric character count
3+
* @param width The width setting as a string or number
4+
* @param isHanzi Whether the text uses Hanzi characters (Chinese, Japanese)
5+
* @returns The number of characters per line
6+
*/
7+
export function convertLineWidth(width: string | number, isHanzi: boolean): number {
8+
if (typeof width === 'number') return width;
9+
10+
if (!isHanzi) {
11+
switch (width.toLowerCase()) {
12+
case 'very narrow': return 21;
13+
case 'narrow': return 30;
14+
case 'medium': return 38;
15+
case 'wide': return 44;
16+
case 'very wide': return 52;
17+
default: return 45;
18+
}
19+
} else {
20+
switch (width.toLowerCase()) {
21+
case 'very narrow': return 7;
22+
case 'narrow': return 10;
23+
case 'medium': return 14;
24+
case 'wide': return 18;
25+
case 'very wide': return 21;
26+
default: return 14;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)