Skip to content

Commit 9e6fab7

Browse files
mmstickjackpot51
authored andcommitted
improv(plugins): Add fill property for the default plugin prefix for help completion
1 parent 18ad5ab commit 9e6fab7

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

src/launcher_plugins.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Selection {
1010
id: number,
1111
name: string,
1212
description: string,
13+
fill?: string
1314
}
1415

1516
/** The trait which all builtin plugins implement */
@@ -25,7 +26,7 @@ export abstract class Builtin {
2526

2627
/** Uses the search input to query for search results */
2728
abstract query(ext: Ext, query: string): Response.Response
28-
29+
2930
/** Applies an option by its ID */
3031
abstract submit(ext: Ext, id: number): Response.Response
3132

@@ -123,6 +124,7 @@ export namespace Plugin {
123124
pattern: string
124125
exec: string
125126
icon: string
127+
fill?: string
126128
}
127129

128130
export function read(file: string): Config | null {
@@ -175,7 +177,7 @@ export namespace Plugin {
175177
return null
176178
}
177179
}
178-
180+
179181
try {
180182
let [bytes,] = backend.proc.stdout.read_line(null)
181183
return Response.parse(imports.byteArray.toString(bytes))
@@ -210,7 +212,7 @@ export namespace Plugin {
210212

211213
export function send(ext: Ext, plugin: Plugin.Source, event: Request.Request): boolean {
212214
const backend = plugin.backend
213-
215+
214216
if ('builtin' in backend) {
215217
backend.builtin.handle(ext, event)
216218
return true

src/plugin_help.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,42 @@ import type { Response, Selection } from 'launcher_plugins'
77
import type { Ext } from './extension'
88

99
export class ShellBuiltin extends plugins.Builtin {
10+
selections: Array<Selection> = []
11+
1012
init() {}
1113

1214
query(ext :Ext, _: string): Response.Response {
13-
let selections = []
15+
this.selections.splice(0);
1416
let id = 0;
1517

1618
for (const [name, service] of ext.window_search.service.plugins) {
1719
if (service.config.pattern?.length > 0) {
18-
selections.push({
20+
this.selections.push({
1921
id,
2022
name,
2123
description: service.config.description + `: ${service.config.pattern}`,
24+
fill: service.config.fill
2225
})
2326
id += 1;
2427
}
2528
}
2629

2730
return {
2831
event: "queried",
29-
selections
32+
selections: this.selections
3033
}
3134
}
3235

33-
submit(ext: Ext, id: number): Response.Response {
34-
return { event: "fill", text: "" }
36+
submit(_: Ext, id: number): Response.Response {
37+
const selection = this.selections[id];
38+
39+
let text = ""
40+
if (selection) {
41+
if (selection.fill) {
42+
text = selection.fill;
43+
}
44+
}
45+
46+
return { event: "fill", text }
3547
}
3648
}

src/plugins/calc/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"description": "Perform calculations from terminal",
44
"pattern": "^(=)+",
55
"exec": "main.js",
6-
"icon": "x-office-spreadsheet"
6+
"icon": "x-office-spreadsheet",
7+
"fill": "="
78
}

src/plugins/files/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"description": "Searches files in the file system",
44
"pattern": "^(\/|~).*",
55
"exec": "main.js",
6-
"icon": "system-file-manager"
6+
"icon": "system-file-manager",
7+
"fill": "~/"
78
}

src/plugins/terminal/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"description": "Run commands in a terminal",
44
"pattern": "^(:|t:|run ).*",
55
"exec": "main.js",
6-
"icon": "utilities-terminal"
6+
"icon": "utilities-terminal",
7+
"fill": "run "
78
}

src/plugins/web/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"description": "Searches",
44
"pattern": "^(amazon|wiki|bing|ddg|google|yt|stack|crates|arch|pp|ppw|rdt|bc|lib|npm|gist|fh|gh|dev|sdcl|twitch|yh|alie)\\s.*",
55
"exec": "main.js",
6-
"icon": "system-search"
6+
"icon": "system-search",
7+
"fill": "ddg "
78
}

0 commit comments

Comments
 (0)