Skip to content

Commit d266355

Browse files
update to zig 0.16.0
1 parent e5eff04 commit d266355

6 files changed

Lines changed: 89 additions & 83 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This was originally code which was extracted from
1111
[lscolors](https://github.com/ziglibs/lscolors) for use in
1212
other zig libraries. More features have been added since.
1313

14-
`ansi_term` is designed to work with Zig 0.15.2.
14+
`ansi_term` is designed to work with Zig 0.16.0.
1515

1616
## Documentation
1717

src/clear.zig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1+
const std = @import("std");
2+
const Io = std.Io;
3+
14
const esc = "\x1B";
25
const csi = esc ++ "[";
36

4-
pub fn clearCurrentLine(writer: anytype) !void {
7+
pub fn clearCurrentLine(writer: *Io.Writer) !void {
58
try writer.writeAll(csi ++ "2K");
69
}
710

8-
pub fn clearFromCursorToLineBeginning(writer: anytype) !void {
11+
pub fn clearFromCursorToLineBeginning(writer: *Io.Writer) !void {
912
try writer.writeAll(csi ++ "1K");
1013
}
1114

12-
pub fn clearFromCursorToLineEnd(writer: anytype) !void {
15+
pub fn clearFromCursorToLineEnd(writer: *Io.Writer) !void {
1316
try writer.writeAll(csi ++ "K");
1417
}
1518

16-
pub fn clearScreen(writer: anytype) !void {
19+
pub fn clearScreen(writer: *Io.Writer) !void {
1720
try writer.writeAll(csi ++ "2J");
1821
}
1922

20-
pub fn clearFromCursorToScreenBeginning(writer: anytype) !void {
23+
pub fn clearFromCursorToScreenBeginning(writer: *Io.Writer) !void {
2124
try writer.writeAll(csi ++ "1J");
2225
}
2326

24-
pub fn clearFromCursorToScreenEnd(writer: anytype) !void {
27+
pub fn clearFromCursorToScreenEnd(writer: *Io.Writer) !void {
2528
try writer.writeAll(csi ++ "J");
2629
}

src/cursor.zig

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22
const testing = std.testing;
3-
const fixedBufferStream = std.io.fixedBufferStream;
3+
const Io = std.Io;
44
const esc = "\x1B";
55
const csi = esc ++ "[";
66

@@ -13,91 +13,91 @@ pub const CursorMode = enum(u8) {
1313
I_beam,
1414
};
1515

16-
pub fn setCursorMode(writer: anytype, mode: CursorMode) !void {
16+
pub fn setCursorMode(writer: *Io.Writer, mode: CursorMode) Io.Writer.Error!void {
1717
const modeNumber = @intFromEnum(mode);
1818
try writer.print(csi ++ "{d} q", .{modeNumber});
1919
}
2020

21-
pub fn hideCursor(writer: anytype) !void {
21+
pub fn hideCursor(writer: *Io.Writer) Io.Writer.Error!void {
2222
try writer.writeAll(csi ++ "?25l");
2323
}
2424

25-
pub fn showCursor(writer: anytype) !void {
25+
pub fn showCursor(writer: *Io.Writer) Io.Writer.Error!void {
2626
try writer.writeAll(csi ++ "?25h");
2727
}
2828

29-
pub fn saveCursor(writer: anytype) !void {
29+
pub fn saveCursor(writer: *Io.Writer) Io.Writer.Error!void {
3030
try writer.writeAll(csi ++ "s");
3131
}
3232

33-
pub fn restoreCursor(writer: anytype) !void {
33+
pub fn restoreCursor(writer: *Io.Writer) Io.Writer.Error!void {
3434
try writer.writeAll(csi ++ "u");
3535
}
3636

37-
pub fn setCursor(writer: anytype, x: usize, y: usize) !void {
37+
pub fn setCursor(writer: *Io.Writer, x: usize, y: usize) Io.Writer.Error!void {
3838
try writer.print(csi ++ "{};{}H", .{ y + 1, x + 1 });
3939
}
4040

41-
pub fn setCursorRow(writer: anytype, row: usize) !void {
41+
pub fn setCursorRow(writer: *Io.Writer, row: usize) Io.Writer.Error!void {
4242
try writer.print(csi ++ "{}H", .{row + 1});
4343
}
4444

45-
pub fn setCursorColumn(writer: anytype, column: usize) !void {
45+
pub fn setCursorColumn(writer: *Io.Writer, column: usize) Io.Writer.Error!void {
4646
try writer.print(csi ++ "{}G", .{column + 1});
4747
}
4848

49-
pub fn cursorUp(writer: anytype, lines: usize) !void {
49+
pub fn cursorUp(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
5050
try writer.print(csi ++ "{}A", .{lines});
5151
}
5252

53-
pub fn cursorDown(writer: anytype, lines: usize) !void {
53+
pub fn cursorDown(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
5454
try writer.print(csi ++ "{}B", .{lines});
5555
}
5656

57-
pub fn cursorForward(writer: anytype, columns: usize) !void {
57+
pub fn cursorForward(writer: *Io.Writer, columns: usize) Io.Writer.Error!void {
5858
try writer.print(csi ++ "{}C", .{columns});
5959
}
6060

61-
pub fn cursorBackward(writer: anytype, columns: usize) !void {
61+
pub fn cursorBackward(writer: *Io.Writer, columns: usize) Io.Writer.Error!void {
6262
try writer.print(csi ++ "{}D", .{columns});
6363
}
6464

65-
pub fn cursorNextLine(writer: anytype, lines: usize) !void {
65+
pub fn cursorNextLine(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
6666
try writer.print(csi ++ "{}E", .{lines});
6767
}
6868

69-
pub fn cursorPreviousLine(writer: anytype, lines: usize) !void {
69+
pub fn cursorPreviousLine(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
7070
try writer.print(csi ++ "{}F", .{lines});
7171
}
7272

73-
pub fn scrollUp(writer: anytype, lines: usize) !void {
73+
pub fn scrollUp(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
7474
try writer.print(csi ++ "{}S", .{lines});
7575
}
7676

77-
pub fn scrollDown(writer: anytype, lines: usize) !void {
77+
pub fn scrollDown(writer: *Io.Writer, lines: usize) Io.Writer.Error!void {
7878
try writer.print(csi ++ "{}T", .{lines});
7979
}
8080

8181
test "test cursor mode BLINKING_UNDERSCORE" {
8282
var buf: [1024]u8 = undefined;
83-
var fixed_buf_stream = fixedBufferStream(&buf);
83+
var fixed_writer: Io.Writer = .fixed(&buf);
8484

85-
try setCursorMode(fixed_buf_stream.writer(), .blinking_underscore);
85+
try setCursorMode(&fixed_writer, .blinking_underscore);
8686
// the space is needed
8787
const expected = csi ++ "3 q";
88-
const actual = fixed_buf_stream.getWritten();
88+
const actual = fixed_writer.buffered();
8989

9090
try testing.expectEqualSlices(u8, expected, actual);
9191
}
9292

9393
test "test cursor mode BLINKING_I_BEAM" {
9494
var buf: [1024]u8 = undefined;
95-
var fixed_buf_stream = fixedBufferStream(&buf);
95+
var fixed_writer: Io.Writer = .fixed(&buf);
9696

97-
try setCursorMode(fixed_buf_stream.writer(), .blinking_I_beam);
97+
try setCursorMode(&fixed_writer, .blinking_I_beam);
9898
// the space is needed
9999
const expected = csi ++ "5 q";
100-
const actual = fixed_buf_stream.getWritten();
100+
const actual = fixed_writer.buffered();
101101

102102
try testing.expectEqualSlices(u8, expected, actual);
103103
}

0 commit comments

Comments
 (0)