forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.js
More file actions
57 lines (47 loc) · 1.22 KB
/
type.js
File metadata and controls
57 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* type command - Type text at cursor position
* @module cli/commands/type
*/
const path = require('path');
const { success, error, info } = require('../util/output');
const UI_MODULE = path.resolve(__dirname, '../../main/ui-automation');
let ui;
function loadUI() {
if (!ui) {
ui = require(UI_MODULE);
}
return ui;
}
/**
* Run the type command
*
* Usage:
* liku type "Hello World"
* liku type "slow typing" --delay 100
*/
async function run(args, options) {
if (args.length === 0) {
error('Usage: liku type <text> [--delay <ms>]');
return { success: false };
}
loadUI();
const text = args.join(' ');
if (!options.quiet) {
info(`Typing: "${text.substring(0, 30)}${text.length > 30 ? '...' : ''}"`);
}
const typeOptions = {};
if (options.delay) {
typeOptions.delay = parseInt(options.delay, 10);
}
const result = await ui.typeText(text, typeOptions);
if (result.success) {
if (!options.quiet) {
success(`Typed ${text.length} characters`);
}
return { success: true, length: text.length };
} else {
error(`Type failed: ${result.error || 'Unknown error'}`);
return { success: false, error: result.error };
}
}
module.exports = { run };