Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

Say which characters can't be typed in an app, instead of dropping them (#57)

Rayanne B. Lima0c3d856c95fe
diff --git a/src/core/apps.ts b/src/core/apps.ts
index 78856c9..04cb4d6 100644
--- a/src/core/apps.ts
+++ b/src/core/apps.ts
@@ -59,14 +59,16 @@ async function bundleOf(app: string): Promise<string | undefined> {
return (await macOpenApps().catch(() => [])).find(same)?.bundleId ?? (await macApps().catch(() => [])).find(same)?.bundleId
}
-// Types text key by key into the app's focused field. Letters, digits, spaces and common
-// punctuation; anything else goes as a pasted value at the end, which most fields take.
+// Types text key by key into the app's focused field: letters, digits, spaces and common
+// punctuation. With anything else it types nothing and says so, or the field would get part of it.
const KEYNAME: Record<string, string> = { ' ': 'space', ',': 'comma', '.': 'period', '/': 'slash', ';': 'semicolon', "'": 'quote', '-': 'minus', '=': 'equal' }
+const keyOf = (ch: string): string | undefined => (/^[a-z0-9]$/.test(ch) ? ch : /^[A-Z]$/.test(ch) ? `shift+${ch.toLowerCase()}` : KEYNAME[ch])
+
export async function typeKeys(cli: Cli, app: string, text: string): Promise<Envelope> {
+ const missing = [...new Set([...text].filter((ch) => !keyOf(ch)))]
+ if (missing.length) return { ok: false, error: { message: L(`Não dá pra digitar ${missing.join(' ')} tecla por tecla. Escreva no campo sem digitar.`, `${missing.join(' ')} can't be typed key by key. Write in the field without typing.`) } }
for (const ch of text) {
- const key = /^[a-z0-9]$/.test(ch) ? ch : /^[A-Z]$/.test(ch) ? `shift+${ch.toLowerCase()}` : KEYNAME[ch]
- if (!key) continue
- const r = await cli(['press', key, '--app', app], 10_000)
+ const r = await cli(['press', keyOf(ch)!, '--app', app], 10_000)
if (!r.ok) return r
}
return { ok: true }
diff --git a/test/apps.test.ts b/test/apps.test.ts
index 616da4d..9e8b401 100644
--- a/test/apps.test.ts
+++ b/test/apps.test.ts
@@ -202,6 +202,15 @@ describe('confirming and typing', () => {
expect((await typeKeys(cli, 'Spotify', 'Lofi 24, ok.')).ok).toBe(true)
expect(keys).toEqual(['shift+l', 'o', 'f', 'i', 'space', '2', '4', 'comma', 'space', 'o', 'k', 'period'])
})
+
+ it('types nothing and says so when a character has no key', async () => {
+ const keys: string[] = []
+ const cli: Cli = async (a) => (keys.push(a[1]!), { ok: true })
+ const refused = await typeKeys(cli, 'Spotify', 'Olá joão@x')
+ expect(refused.ok).toBe(false)
+ expect(refused.error?.message).toMatch(/á ã @/)
+ expect(keys).toEqual([])
+ })
})
describe('an app with several windows', () => {