command-cmd 1.0.5 → 1.0.6
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/cmd.js +79 -0
- package/doc.md +17 -1
- package/docPTBR.md +18 -1
- package/package.json +1 -1
package/cmd.js
CHANGED
|
@@ -129,6 +129,10 @@ const CLICK_MODE = Object.freeze({
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
let robotCache;
|
|
132
|
+
const MAPER_POLL_INTERVAL = 50;
|
|
133
|
+
let maperInterval = null;
|
|
134
|
+
let maperLastPosition = null;
|
|
135
|
+
let maperPrintedLine = false;
|
|
132
136
|
|
|
133
137
|
export function cmd(message) {
|
|
134
138
|
if (typeof message !== 'string') {
|
|
@@ -298,6 +302,81 @@ export function extractFirstCommand(message) {
|
|
|
298
302
|
return first || null;
|
|
299
303
|
}
|
|
300
304
|
|
|
305
|
+
export async function maper(enabled) {
|
|
306
|
+
const shouldEnable = parseBooleanValue(enabled);
|
|
307
|
+
if (shouldEnable === null) {
|
|
308
|
+
throw new Error('maper_requires_boolean_true_or_false');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (!shouldEnable) {
|
|
312
|
+
if (maperInterval) {
|
|
313
|
+
clearInterval(maperInterval);
|
|
314
|
+
maperInterval = null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
maperLastPosition = null;
|
|
318
|
+
|
|
319
|
+
if (maperPrintedLine && process.stdout && typeof process.stdout.write === 'function') {
|
|
320
|
+
process.stdout.write('\n');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
maperPrintedLine = false;
|
|
324
|
+
return { active: false, pollInterval: MAPER_POLL_INTERVAL };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const robot = await getRobot();
|
|
328
|
+
|
|
329
|
+
const printPosition = (position) => {
|
|
330
|
+
const line = `[maper] x: ${position.x} | y: ${position.y}`;
|
|
331
|
+
|
|
332
|
+
if (process.stdout && process.stdout.isTTY && typeof process.stdout.write === 'function') {
|
|
333
|
+
process.stdout.write(`\r${line}`);
|
|
334
|
+
maperPrintedLine = true;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
console.log(line);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const pollPosition = () => {
|
|
342
|
+
let position;
|
|
343
|
+
try {
|
|
344
|
+
position = robot.getMousePos();
|
|
345
|
+
} catch (error) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (!position || !Number.isFinite(position.x) || !Number.isFinite(position.y)) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (
|
|
354
|
+
maperLastPosition &&
|
|
355
|
+
position.x === maperLastPosition.x &&
|
|
356
|
+
position.y === maperLastPosition.y
|
|
357
|
+
) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
maperLastPosition = { x: position.x, y: position.y };
|
|
362
|
+
printPosition(position);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
if (maperInterval) {
|
|
366
|
+
return { active: true, pollInterval: MAPER_POLL_INTERVAL };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
maperLastPosition = null;
|
|
370
|
+
pollPosition();
|
|
371
|
+
maperInterval = setInterval(pollPosition, MAPER_POLL_INTERVAL);
|
|
372
|
+
|
|
373
|
+
if (typeof maperInterval.unref === 'function') {
|
|
374
|
+
maperInterval.unref();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return { active: true, pollInterval: MAPER_POLL_INTERVAL };
|
|
378
|
+
}
|
|
379
|
+
|
|
301
380
|
export async function initMap(options = {}) {
|
|
302
381
|
const config = buildCursorConfig(options);
|
|
303
382
|
const mapAlreadyExists = await pathExists(config.mapPath);
|
package/doc.md
CHANGED
|
@@ -9,6 +9,7 @@ Exported functions:
|
|
|
9
9
|
- `cursor`
|
|
10
10
|
- `initMap`
|
|
11
11
|
- `initDoc`
|
|
12
|
+
- `maper`
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
@@ -19,7 +20,7 @@ npm install command-cmd
|
|
|
19
20
|
## Import
|
|
20
21
|
|
|
21
22
|
```js
|
|
22
|
-
import { cmd, extractFirstCommand, cursor, initMap, initDoc } from 'command-cmd';
|
|
23
|
+
import { cmd, extractFirstCommand, cursor, initMap, initDoc, maper } from 'command-cmd';
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
## 1) `cmd(message)`
|
|
@@ -156,6 +157,21 @@ Optional keys:
|
|
|
156
157
|
- `includeMapDocs`
|
|
157
158
|
- `files` (e.g. `['doc', 'docPTBR', 'map', 'mapPTBR']`)
|
|
158
159
|
|
|
160
|
+
## 6) `maper(enabled)`
|
|
161
|
+
|
|
162
|
+
Turns terminal mouse position mapping on/off.
|
|
163
|
+
|
|
164
|
+
- pass `true` to start mapping
|
|
165
|
+
- pass `false` to stop mapping
|
|
166
|
+
- while active, it prints current `x/y` only when mouse position changes
|
|
167
|
+
|
|
168
|
+
Example:
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
await maper(true); // starts mapper
|
|
172
|
+
await maper(false); // stops mapper
|
|
173
|
+
```
|
|
174
|
+
|
|
159
175
|
### App and button names (important)
|
|
160
176
|
|
|
161
177
|
You can name apps and buttons however you want.
|
package/docPTBR.md
CHANGED
|
@@ -9,6 +9,7 @@ Funcoes exportadas:
|
|
|
9
9
|
- `cursor`
|
|
10
10
|
- `initMap`
|
|
11
11
|
- `initDoc`
|
|
12
|
+
- `maper`
|
|
12
13
|
|
|
13
14
|
## Instalacao
|
|
14
15
|
|
|
@@ -24,7 +25,8 @@ import {
|
|
|
24
25
|
extractFirstCommand as extrairPrimeiroComando,
|
|
25
26
|
cursor as executarCursor,
|
|
26
27
|
initMap as iniciarMap,
|
|
27
|
-
initDoc as iniciarDoc
|
|
28
|
+
initDoc as iniciarDoc,
|
|
29
|
+
maper
|
|
28
30
|
} from 'command-cmd';
|
|
29
31
|
```
|
|
30
32
|
|
|
@@ -162,6 +164,21 @@ Campos opcionais:
|
|
|
162
164
|
- `includeMapDocs`
|
|
163
165
|
- `files` (ex.: `['doc', 'docPTBR', 'map', 'mapPTBR']`)
|
|
164
166
|
|
|
167
|
+
## 6) `maper(enabled)`
|
|
168
|
+
|
|
169
|
+
Liga/desliga o mapeador de posicao do mouse no terminal.
|
|
170
|
+
|
|
171
|
+
- passe `true` para ativar
|
|
172
|
+
- passe `false` para desativar
|
|
173
|
+
- enquanto ativo, ele mostra `x/y` apenas quando a posicao muda
|
|
174
|
+
|
|
175
|
+
Exemplo:
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
await maper(true); // inicia o mapeador
|
|
179
|
+
await maper(false); // encerra o mapeador
|
|
180
|
+
```
|
|
181
|
+
|
|
165
182
|
### Nome dos apps e botoes (importante)
|
|
166
183
|
|
|
167
184
|
Voce pode chamar apps e botoes como quiser.
|