refactor(utils): use new Io
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const utils = @import("../utils.zig");
|
const utils = @import("../utils.zig");
|
||||||
|
|
||||||
pub fn getPackagesInfo(allocator: std.mem.Allocator) ![]const u8 {
|
pub fn getPackagesInfo(allocator: std.mem.Allocator, io: std.Io) ![]const u8 {
|
||||||
var packages_info = std.array_list.Managed(u8).init(allocator);
|
var packages_info = std.array_list.Managed(u8).init(allocator);
|
||||||
defer packages_info.deinit();
|
defer packages_info.deinit();
|
||||||
|
|
||||||
const homebrew_packages = countHomebrewPackages() catch |err| if (err == error.FileNotFound) 0 else return err;
|
const homebrew_packages = countHomebrewPackages(io) catch |err| if (err == error.FileNotFound) 0 else return err;
|
||||||
const homebrew_casks = countHomebrewCasks() catch |err| if (err == error.FileNotFound) 0 else return err;
|
const homebrew_casks = countHomebrewCasks(io) catch |err| if (err == error.FileNotFound) 0 else return err;
|
||||||
const macports_packages = countMacportPackages() catch |err| if (err == error.FileNotFound) 0 else return err;
|
const macports_packages = countMacportPackages(io) catch |err| if (err == error.FileNotFound) 0 else return err;
|
||||||
|
|
||||||
var buffer: [32]u8 = undefined;
|
var buffer: [32]u8 = undefined;
|
||||||
|
|
||||||
@@ -26,14 +26,14 @@ pub fn getPackagesInfo(allocator: std.mem.Allocator) ![]const u8 {
|
|||||||
return try allocator.dupe(u8, packages_info.items);
|
return try allocator.dupe(u8, packages_info.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn countHomebrewPackages() !usize {
|
fn countHomebrewPackages(io: std.Io) !usize {
|
||||||
return try utils.countEntries("/opt/homebrew/Cellar");
|
return try utils.countEntries(io, "/opt/homebrew/Cellar");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn countHomebrewCasks() !usize {
|
fn countHomebrewCasks(io: std.Io) !usize {
|
||||||
return try utils.countEntries("/opt/homebrew/Caskroom");
|
return try utils.countEntries(io, "/opt/homebrew/Caskroom");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn countMacportPackages() !usize {
|
fn countMacportPackages(io: std.Io) !usize {
|
||||||
return try utils.countEntries("/opt/local/bin");
|
return try utils.countEntries(io, "/opt/local/bin");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub const TermSize = struct {
|
|||||||
pub fn getTerminalSize() !TermSize {
|
pub fn getTerminalSize() !TermSize {
|
||||||
// https://github.com/softprops/zig-termsize (https://github.com/softprops/zig-termsize/blob/main/src/main.zig)
|
// https://github.com/softprops/zig-termsize (https://github.com/softprops/zig-termsize/blob/main/src/main.zig)
|
||||||
|
|
||||||
const stdout = std.fs.File.stdout();
|
const stdout = std.Io.File.stdout();
|
||||||
|
|
||||||
switch (builtin.os.tag) {
|
switch (builtin.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
@@ -126,14 +126,14 @@ pub fn readFile(allocator: std.mem.Allocator, io: std.Io, file: std.Io.File, siz
|
|||||||
return allocator.dupe(u8, data);
|
return allocator.dupe(u8, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn countEntries(dir_path: []const u8) !usize {
|
pub fn countEntries(io: std.Io, dir_path: []const u8) !usize {
|
||||||
var dir = try std.fs.openDirAbsolute(dir_path, .{ .iterate = true });
|
var dir = try std.Io.Dir.openDirAbsolute(io, dir_path, .{ .iterate = true });
|
||||||
defer dir.close();
|
defer dir.close(io);
|
||||||
|
|
||||||
var count: usize = 0;
|
var count: usize = 0;
|
||||||
var iter = dir.iterate();
|
var iter = dir.iterate();
|
||||||
|
|
||||||
while (try iter.next()) |_| {
|
while (try iter.next(io)) |_| {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user