|
|
@ -149,7 +149,7 @@ const ProcessWithOutput = struct {
|
|
149
|
149
|
}
|
|
150
|
150
|
};
|
|
151
|
151
|
|
|
152
|
|
const RegexRunner = struct {
|
|
|
152
|
const Runner = struct {
|
|
153
|
153
|
name: []const u8,
|
|
154
|
154
|
run_always: bool,
|
|
155
|
155
|
process: ?ProcessWithOutput = null,
|
|
|
@ -157,7 +157,7 @@ const RegexRunner = struct {
|
|
157
|
157
|
toArgv: fn (cmd: []const u8) []const []const u8,
|
|
158
|
158
|
isActive: fn (cmd: []const u8) bool,
|
|
159
|
159
|
|
|
160
|
|
fn run(self: *RegexRunner, allocator: *std.mem.Allocator, cmd: []const u8, is_confirmed: bool) !bool {
|
|
|
160
|
fn run(self: *Runner, allocator: *std.mem.Allocator, cmd: []const u8, is_confirmed: bool) !bool {
|
|
161
|
161
|
if (!self.run_always and !is_confirmed) {
|
|
162
|
162
|
return false;
|
|
163
|
163
|
}
|
|
|
@ -189,7 +189,7 @@ const RegexRunner = struct {
|
|
189
|
189
|
return true;
|
|
190
|
190
|
}
|
|
191
|
191
|
|
|
192
|
|
fn output(self: *RegexRunner) ![]const u8 {
|
|
|
192
|
fn output(self: *Runner) ![]const u8 {
|
|
193
|
193
|
if (self.process) |*process| {
|
|
194
|
194
|
process.poll() catch |err| switch (err) {
|
|
195
|
195
|
error.StdoutStreamTooLong => {
|
|
|
@ -211,7 +211,7 @@ const RegexRunner = struct {
|
|
211
|
211
|
return "<no output>";
|
|
212
|
212
|
}
|
|
213
|
213
|
|
|
214
|
|
fn deinit(self: *RegexRunner) void {
|
|
|
214
|
fn deinit(self: *Runner) void {
|
|
215
|
215
|
if (self.process) |*process| {
|
|
216
|
216
|
process.deinit();
|
|
217
|
217
|
}
|
|
|
@ -221,8 +221,8 @@ const RegexRunner = struct {
|
|
221
|
221
|
var cmd_buf: [1000]u8 = undefined;
|
|
222
|
222
|
|
|
223
|
223
|
const GoDocRunner = struct {
|
|
224
|
|
fn init() RegexRunner {
|
|
225
|
|
return RegexRunner{ .name = "go doc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
224
|
fn init() Runner {
|
|
|
225
|
return Runner{ .name = "go doc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
226
|
226
|
}
|
|
227
|
227
|
|
|
228
|
228
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -237,8 +237,8 @@ const GoDocRunner = struct {
|
|
237
|
237
|
};
|
|
238
|
238
|
|
|
239
|
239
|
const PythonHelpRunner = struct {
|
|
240
|
|
fn init() RegexRunner {
|
|
241
|
|
return RegexRunner{ .name = "python help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
240
|
fn init() Runner {
|
|
|
241
|
return Runner{ .name = "python help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
242
|
242
|
}
|
|
243
|
243
|
|
|
244
|
244
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -252,8 +252,8 @@ const PythonHelpRunner = struct {
|
|
252
|
252
|
};
|
|
253
|
253
|
|
|
254
|
254
|
const PythonRunner = struct {
|
|
255
|
|
fn init() RegexRunner {
|
|
256
|
|
return RegexRunner{ .name = "python run", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
255
|
fn init() Runner {
|
|
|
256
|
return Runner{ .name = "python run", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
257
|
257
|
}
|
|
258
|
258
|
|
|
259
|
259
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -267,8 +267,8 @@ const PythonRunner = struct {
|
|
267
|
267
|
};
|
|
268
|
268
|
|
|
269
|
269
|
const HelpRunner = struct {
|
|
270
|
|
fn init() RegexRunner {
|
|
271
|
|
return RegexRunner{ .name = "--help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
270
|
fn init() Runner {
|
|
|
271
|
return Runner{ .name = "--help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
272
|
272
|
}
|
|
273
|
273
|
|
|
274
|
274
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -282,8 +282,8 @@ const HelpRunner = struct {
|
|
282
|
282
|
};
|
|
283
|
283
|
|
|
284
|
284
|
const ManPageRunner = struct {
|
|
285
|
|
fn init() RegexRunner {
|
|
286
|
|
return RegexRunner{ .name = "man page", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
285
|
fn init() Runner {
|
|
|
286
|
return Runner{ .name = "man page", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
287
|
287
|
}
|
|
288
|
288
|
|
|
289
|
289
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -297,8 +297,8 @@ const ManPageRunner = struct {
|
|
297
|
297
|
};
|
|
298
|
298
|
|
|
299
|
299
|
const SearchRunner = struct {
|
|
300
|
|
fn init() RegexRunner {
|
|
301
|
|
return RegexRunner{ .name = "search", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
300
|
fn init() Runner {
|
|
|
301
|
return Runner{ .name = "search", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
302
|
302
|
}
|
|
303
|
303
|
|
|
304
|
304
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -312,8 +312,8 @@ const SearchRunner = struct {
|
|
312
|
312
|
};
|
|
313
|
313
|
|
|
314
|
314
|
const LogsRunner = struct {
|
|
315
|
|
fn init() RegexRunner {
|
|
316
|
|
return RegexRunner{ .name = "logs", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
315
|
fn init() Runner {
|
|
|
316
|
return Runner{ .name = "logs", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
317
|
317
|
}
|
|
318
|
318
|
|
|
319
|
319
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -332,8 +332,8 @@ const LogsRunner = struct {
|
|
332
|
332
|
};
|
|
333
|
333
|
|
|
334
|
334
|
const QalcRunner = struct {
|
|
335
|
|
fn init() RegexRunner {
|
|
336
|
|
return RegexRunner{ .name = "qalc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
|
335
|
fn init() Runner {
|
|
|
336
|
return Runner{ .name = "qalc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
|
|
337
|
337
|
}
|
|
338
|
338
|
|
|
339
|
339
|
fn isActive(cmd: []const u8) bool {
|
|
|
@ -411,7 +411,7 @@ pub fn main() !void {
|
|
411
|
411
|
const keyboardState = c.SDL_GetKeyboardState(null);
|
|
412
|
412
|
|
|
413
|
413
|
c.SDL_StartTextInput();
|
|
414
|
|
var commands = [_]RegexRunner{
|
|
|
414
|
var commands = [_]Runner{
|
|
415
|
415
|
GoDocRunner.init(),
|
|
416
|
416
|
PythonHelpRunner.init(),
|
|
417
|
417
|
PythonRunner.init(),
|