srctree

Gregory Mullen parent 81db8ca4 9fb8c4fb
clean up a few imports

src/hsh.zig added: 16, removed: 18, total 0
@@ -18,6 +18,7 @@ const fs = @import("fs.zig");
const Variables = @import("variables.zig");
const log = @import("log");
const INEvent = @import("inotify.zig").Event;
const Line = @import("line.zig");
 
pub const Error = error{
Unknown,
@@ -189,6 +190,7 @@ pub const HSH = struct {
tty: TTY = undefined,
draw: Drawable = undefined,
tkn: Tokenizer = undefined,
line: *Line = undefined,
input: i32 = 0,
changes: []u8 = undefined,
waiting: bool = false,
@@ -211,6 +213,7 @@ pub const HSH = struct {
.env = env,
.pid = std.os.linux.getpid(),
.jobs = jobs.init(a),
.tkn = Tokenizer.init(a),
.hfs = hfs,
};
 
@@ -236,6 +239,7 @@ pub const HSH = struct {
hsh.env.deinit();
jobs.raze(hsh.alloc);
hsh.hfs.raze(hsh.alloc);
hsh.tkn.raze();
}
 
fn sleep(_: *HSH) void {
 
src/line.zig added: 16, removed: 18, total 0
@@ -34,7 +34,7 @@ mode: union(enum) {
external_editor: bool,
},
history: History = undefined,
completion: *Complete.CompSet,
completion: ?Complete.CompSet = null,
 
usr_line: [1024]u8 = undefined,
 
@@ -42,10 +42,10 @@ pub const Options = struct {
interactive: bool = true,
};
 
pub fn init(hsh: *HSH, comp: *Complete.CompSet, options: Options) Line {
pub fn init(hsh: *HSH, options: Options) Line {
return .{
.hsh = hsh,
.completion = comp,
.completion = try Complete.init(hsh),
.options = options,
.history = History.init(hsh.hfs.history, hsh.alloc),
.input = .{ .stdin = hsh.input, .spin = spin, .hsh = hsh },
@@ -53,6 +53,10 @@ pub fn init(hsh: *HSH, comp: *Complete.CompSet, options: Options) Line {
};
}
 
pub fn raze(line: Line) void {
if (line.completion) |comp| comp.raze();
}
 
fn spin(hsh: ?*HSH) bool {
if (hsh) |h| return h.spin();
return false;
 
src/main.zig added: 16, removed: 18, total 0
@@ -3,8 +3,6 @@ const log = @import("log");
const hsh_build = @import("hsh_build");
const Allocator = std.mem.Allocator;
const TTY = @import("tty.zig");
const tokenizer = @import("tokenizer.zig");
const Tokenizer = tokenizer.Tokenizer;
const Draw = @import("draw.zig");
const Drawable = Draw.Drawable;
const prompt = @import("prompt.zig");
@@ -12,7 +10,6 @@ const jobsContext = @import("prompt.zig").jobsContext;
const ctxContext = @import("prompt.zig").ctxContext;
const Context = @import("context.zig");
const HSH = @import("hsh.zig").HSH;
const complete = @import("completion.zig");
const Exec = @import("exec.zig");
const Signals = @import("signals.zig");
const History = @import("history.zig");
@@ -26,12 +23,10 @@ test "main" {
fn core(hsh: *HSH) !bool {
defer hsh.draw.reset();
//try Context.update(hsh, &[_]Context.Contexts{.git});
var comp = try complete.init(hsh);
defer comp.raze();
 
var redraw = true;
// TODO drop hsh
var line = Line.init(hsh, &comp, .{ .interactive = hsh.tty.is_tty });
var line = Line.init(hsh, .{ .interactive = hsh.tty.is_tty });
 
while (true) {
hsh.draw.clear();
@@ -63,8 +58,6 @@ fn execTacC(args: *std.process.ArgIterator) u8 {
const a = gpa.allocator();
var hsh = HSH.init(a) catch return 255;
defer hsh.raze();
hsh.tkn = Tokenizer.init(a);
defer hsh.tkn.raze();
hsh.tty = TTY.init(a) catch return 255;
defer hsh.tty.raze();
 
@@ -131,8 +124,6 @@ pub fn main() !void {
 
var hsh = try HSH.init(a);
defer hsh.raze();
hsh.tkn = Tokenizer.init(a);
defer hsh.tkn.raze();
 
try Signals.init(a);
defer Signals.raze();
@@ -152,8 +143,7 @@ pub fn main() !void {
if (core(&hsh)) |actionable| {
inerr = false;
if (actionable) {
if (hsh.tkn.raw.items.len == 0) continue;
// debugging data
std.debug.assert(hsh.tkn.raw.items.len != 0);
 
const str = try hsh.alloc.dupe(u8, hsh.tkn.raw.items);
defer hsh.alloc.free(str);