Skip to content
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
workflow_run:
workflows: ['Test']
workflows: ["Test"]
types: [completed]
branches:
- main
Expand All @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [Linux]
runs-on: [ self-hosted, "${{ matrix.os }}" ]
runs-on: [self-hosted, "${{ matrix.os }}"]
defaults:
run:
shell: bash
Expand All @@ -35,12 +35,12 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0-dev.2193+fc517bd01

- uses: actions/github-script@v7
id: parse-version
env:
SHA: '${{env.parentSHA}}'
SHA: "${{env.parentSHA}}"
with:
script: |
const script = require('./.github/workflows/zig-version.js');
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [Linux, Windows]
runs-on: [ self-hosted, "${{ matrix.os }}" ]
runs-on: [self-hosted, "${{ matrix.os }}"]
steps:
- name: Log masks on Linux
if: matrix.os == 'Linux'
Expand All @@ -31,7 +31,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0-dev.2193+fc517bd01

- name: Run zig fmt
if: matrix.os == 'Linux'
Expand Down
6 changes: 0 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});

const zignet = b.dependency("zignet", .{
.target = target,
.optimize = optimize,
});

const build_zig_zon = b.createModule(.{
.root_source_file = b.path("build.zig.zon"),
.target = target,
Expand All @@ -103,7 +98,6 @@ pub fn build(b: *std.Build) !void {
.{ .name = "mmc-api", .module = mmc_api.module("mmc-api") },
.{ .name = "network", .module = network_dep.module("network") },
.{ .name = "chrono", .module = chrono.module("chrono") },
.{ .name = "zignet", .module = zignet.module("zignet") },
.{ .name = "tracy", .module = tracy_module },
};
const setup_options: SetupOptions = .{
Expand Down
18 changes: 7 additions & 11 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .mmc_cli,
.version = "0.16.0",
.fingerprint = 0x392c74984291bf14,
.minimum_zig_version = "0.15.1",
.minimum_zig_version = "0.16.0-dev.2193+fc517bd01",
.dependencies = .{
.json5 = .{
.url = "https://github.com/mochalins/json5.zig/archive/2ef1032.tar.gz",
Expand All @@ -12,21 +12,17 @@
.url = "https://github.com/mochalins/network/archive/084fed7.tar.gz",
.hash = "network-0.1.0-Pm-AgiMxAQCuaDrGAfSxVHeozUQ2gU3jINGLFxJ1Zpld",
},
.zignet = .{
.url = "https://github.com/aaumar25/zignet/archive/ca7d172.tar.gz",
.hash = "zignet-0.2.0-BAu-r4GpAACnu7GCkbPHa4F6lQaq5wypMWqr0z0BM9nO",
},
.chrono = .{
.url = "https://github.com/pmotionf/chrono/archive/31e31b0.tar.gz",
.hash = "chrono-0.1.0-uVd76I_AAwCMh8lYH9E-5ia0tI-tda4Q2FjFoIdE2dYG",
.url = "https://github.com/aaumar25/chrono/archive/11b2a9b.tar.gz",
.hash = "chrono-0.1.0-uVd76ObCAwBL5hB9wCVWZLus9iLTKvINA_GYw_Lmkfid",
},
.mmc_api = .{
.url = "https://github.com/pmotionf/mmc-api/archive/907e011.tar.gz",
.hash = "mmc_api-1.2.0-P5raR2hzCwCUZ73y6Bl6QSWtoUeXric6xPMyUsU3_jDS",
.url = "https://github.com/pmotionf/mmc-api/archive/8fcf069.tar.gz",
.hash = "mmc_api-0.0.0-P5raR8DdOgBmx-t8_lU6fEcosMFSLiKAfi9JVGhz08vP",
},
.soem = .{
.url = "https://github.com/pmotionf/SOEM/archive/6dff3f5.tar.gz",
.hash = "soem-1.4.0-hMH6QwH7DQDhU4QpnIidSZbzZlVoljUcay_9RIbl4jPj",
.url = "https://github.com/aaumar25/SOEM/archive/195fbdd.tar.gz",
.hash = "soem-1.4.0-hMH6Q-37DQBvevB5XrCFluc-BgwBSzKqK7by3hn-Vss0",
.lazy = true,
},
.tracy = .{
Expand Down
4 changes: 2 additions & 2 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const Parse = struct {
modules: []ModuleConfig,
};

pub fn parse(allocator: std.mem.Allocator, f: std.fs.File) !Config {
pub fn parse(allocator: std.mem.Allocator, io: std.Io, f: std.Io.File) !Config {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();

var f_reader_buf: [4096]u8 = undefined;
var f_reader = f.reader(&f_reader_buf);
var f_reader = f.reader(io, &f_reader_buf);
var reader: json5.Reader = .init(a, &f_reader.interface);

const _result = try json5.parseFromTokenSource(
Expand Down
70 changes: 35 additions & 35 deletions src/Prompt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const builtin = @import("builtin");
const std = @import("std");

const command = @import("command.zig");
const io = @import("io.zig");
const mmc_io = @import("io.zig");

const Complete = @import("Prompt/Complete.zig");
const History = @import("Prompt/History.zig");

pub const max_input_size = std.fs.max_path_bytes + 512;
pub const max_input_size = std.Io.Dir.max_path_bytes + 512;

/// Flag to hide prompt and ignore user input.
disable: std.atomic.Value(bool) = .init(false),
Expand All @@ -36,12 +36,12 @@ selected_command: []const u8 = &.{},
/// Prompt handler thread callback. Input must be set to non-canonical mode
/// prior to spawning this thread. Only one prompt handler thread may be
/// running at a time.
pub fn handler(ctx: *Prompt) void {
pub fn handler(ctx: *Prompt, io: std.Io) void {
ctx.history.clear();
ctx.clear();

var stdout_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&stdout_buf);
var stdout = std.Io.File.stdout().writer(io, &stdout_buf);

var prev_disable: bool = true;
main: while (!ctx.close.load(.monotonic)) {
Expand All @@ -53,15 +53,15 @@ pub fn handler(ctx: *Prompt) void {

// Print prompt once on enable.
if (prev_disable) {
std.Thread.sleep(std.time.ns_per_ms * 10);
io.sleep(.fromMilliseconds(10), .real) catch continue :main;
stdout.interface.writeAll(
"Enter command (HELP for usage):\n",
) catch continue :main;
stdout.interface.flush() catch continue :main;
}
prev_disable = false;

if (io.event.poll() catch continue :main == 0) {
if (mmc_io.event.poll() catch continue :main == 0) {
continue :main;
}

Expand All @@ -70,7 +70,7 @@ pub fn handler(ctx: *Prompt) void {
// keep the completion selection.
var keep_complete_selection: bool = false;

const event = io.event.read(.{}) catch continue :main;
const event = mmc_io.event.read(io, .{}) catch continue :main;
parse: switch (event) {
.key => |key_event| {
switch (key_event.value) {
Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn handler(ctx: *Prompt) void {
// Print newline at end of prompt before
// command start.
ctx.cursor.moveEnd();
io.cursor.moveColumn(
mmc_io.cursor.moveColumn(
&stdout.interface,
ctx.cursor.visible + 1,
) catch continue :main;
Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn handler(ctx: *Prompt) void {
.windows => {
var buf: [max_input_size]u8 =
undefined;
const paste = io.clipboard.get(
const paste = mmc_io.clipboard.get(
&buf,
) catch {};
ctx.insertString(paste);
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn handler(ctx: *Prompt) void {
// Underline fragment if it has just been completed.
if (ctx.complete_partial_start) |cvs| {
if (cvs == start and ctx.complete_selection != null) {
io.style.set(
mmc_io.style.set(
&stdout.interface,
.{ .underline = true },
) catch continue :main;
Expand All @@ -414,19 +414,19 @@ pub fn handler(ctx: *Prompt) void {
const fragment = ctx.input[start..i];
// Parsing the first fragment
if (std.mem.count(u8, ctx.input[0..i], " ") == 0) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .red },
}) catch continue :main;
for (command.registry.keys()) |key| {
if (std.ascii.eqlIgnoreCase(key, fragment)) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .green },
}) catch continue :main;
ctx.selected_command = key;
break;
}
}
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(fragment) catch
continue :main;
} else {
Expand All @@ -438,10 +438,10 @@ pub fn handler(ctx: *Prompt) void {
var_entry.key_ptr.*,
fragment,
)) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .magenta },
}) catch continue :main;
defer io.style.reset(
defer mmc_io.style.reset(
&stdout.interface,
) catch {};
stdout.interface.writeAll(fragment) catch
Expand All @@ -450,10 +450,10 @@ pub fn handler(ctx: *Prompt) void {
}
} else validation: {
if (ctx.selected_command.len == 0) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .red },
}) catch continue :main;
defer io.style.reset(
defer mmc_io.style.reset(
&stdout.interface,
) catch {};
stdout.interface.writeAll(fragment) catch
Expand All @@ -462,10 +462,10 @@ pub fn handler(ctx: *Prompt) void {
}
const selected_command =
command.registry.getPtr(ctx.selected_command) orelse {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .red },
}) catch continue :main;
defer io.style.reset(
defer mmc_io.style.reset(
&stdout.interface,
) catch {};
stdout.interface.writeAll(fragment) catch
Expand All @@ -482,10 +482,10 @@ pub fn handler(ctx: *Prompt) void {
// Parameter start at index 1 on command input
const param_idx = fragment_id - 1;
if (param_idx >= selected_command.parameters.len) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .red },
}) catch continue :main;
defer io.style.reset(
defer mmc_io.style.reset(
&stdout.interface,
) catch {};
stdout.interface.writeAll(fragment) catch
Expand All @@ -498,10 +498,10 @@ pub fn handler(ctx: *Prompt) void {
stdout.interface.writeAll(fragment) catch
continue :main;
} else {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .red },
}) catch continue :main;
defer io.style.reset(
defer mmc_io.style.reset(
&stdout.interface,
) catch {};
stdout.interface.writeAll(fragment) catch
Expand All @@ -519,10 +519,10 @@ pub fn handler(ctx: *Prompt) void {
if (ctx.complete.prefix.len > completed_len) {
const suggestion =
ctx.complete.prefix[completed_len..];
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .lut = .grayscale(12) },
}) catch continue :main;
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(suggestion) catch
continue :main;
}
Expand All @@ -538,7 +538,7 @@ pub fn handler(ctx: *Prompt) void {
// Underline fragment if it has just been completed.
if (ctx.complete_partial_start) |cvs| {
if (cvs == start and ctx.complete_selection != null) {
io.style.set(
mmc_io.style.set(
&stdout.interface,
.{ .underline = true },
) catch continue :main;
Expand All @@ -549,11 +549,11 @@ pub fn handler(ctx: *Prompt) void {
if (std.mem.count(u8, ctx.input, " ") == 0) {
for (command.registry.keys()) |key| {
if (std.ascii.eqlIgnoreCase(key, fragment)) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .green },
}) catch continue :main;
ctx.selected_command = key;
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(fragment) catch
continue :main;
break;
Expand All @@ -571,10 +571,10 @@ pub fn handler(ctx: *Prompt) void {
var_entry.key_ptr.*,
fragment,
)) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .named = .magenta },
}) catch continue :main;
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(fragment) catch
continue :main;
break;
Expand All @@ -592,10 +592,10 @@ pub fn handler(ctx: *Prompt) void {
if (ctx.complete.prefix.len > completed_len) {
const suggestion =
ctx.complete.prefix[completed_len..];
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .lut = .grayscale(12) },
}) catch continue :main;
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(suggestion) catch
continue :main;
}
Expand All @@ -607,17 +607,17 @@ pub fn handler(ctx: *Prompt) void {
if (ctx.history.selection) |*selection| {
const hist_item = selection.slice();
if (hist_item.len > ctx.input.len) {
io.style.set(&stdout.interface, .{
mmc_io.style.set(&stdout.interface, .{
.fg = .{ .lut = .grayscale(12) },
.underline = true,
}) catch continue :main;
defer io.style.reset(&stdout.interface) catch {};
defer mmc_io.style.reset(&stdout.interface) catch {};
stdout.interface.writeAll(hist_item[ctx.input.len..]) catch
continue :main;
}
}

io.cursor.moveColumn(&stdout.interface, ctx.cursor.visible + 1) catch
mmc_io.cursor.moveColumn(&stdout.interface, ctx.cursor.visible + 1) catch
continue :main;
}
}
Expand Down
Loading