summaryrefslogtreecommitdiff
path: root/src/cmd/cls.zig
blob: a01727862bf99513a1ff7cbc4c0e120f812de27a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const std = @import("std");
const Allocator = std.mem.Allocator;

const types = @import("./lib/types.zig");
const CommandStatus = types.CommandStatus;
const CommandContext = types.CommandContext;

pub const Cls = struct {
    pub fn eval(cls: Cls, ctx: CommandContext) !CommandStatus {
        _ = cls;

        // Clear screen - only works when going to stdout, not when redirected
        switch (ctx.output_writer) {
            .stdout => |writer| {
                try writer.write("\x1B[2J\x1B[H");
            },
            .capture => {
                // Do nothing when output is captured/redirected
            },
        }
        return CommandStatus{ .Code = 0 };
    }
};