Skip to content

Commit 010f170

Browse files
remove shortcut FontStyles
they were duplicates with the field names in the FontStyle struct, which is not really clean. Besides, I think it's ok to write .{ .bold = true } instead for example.
1 parent be839e9 commit 010f170

File tree

3 files changed

+20
-64
lines changed

3 files changed

+20
-64
lines changed

src/format.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ test "reset to default, old non-null" {
159159
var fixed_buf_stream = fixedBufferStream(&buf);
160160

161161
try updateStyle(fixed_buf_stream.writer(), Style{}, Style{
162-
.font_style = FontStyle.bold,
162+
.font_style = .{ .bold = true },
163163
});
164164

165165
const expected = "\x1B[0m";
@@ -173,7 +173,7 @@ test "bold style" {
173173
var fixed_buf_stream = fixedBufferStream(&buf);
174174

175175
try updateStyle(fixed_buf_stream.writer(), Style{
176-
.font_style = FontStyle.bold,
176+
.font_style = .{ .bold = true },
177177
}, Style{});
178178

179179
const expected = "\x1B[1m";
@@ -187,9 +187,9 @@ test "add bold style" {
187187
var fixed_buf_stream = fixedBufferStream(&buf);
188188

189189
try updateStyle(fixed_buf_stream.writer(), Style{
190-
.font_style = FontStyle{ .bold = true, .italic = true },
190+
.font_style = .{ .bold = true, .italic = true },
191191
}, Style{
192-
.font_style = FontStyle.italic,
192+
.font_style = .{ .italic = true },
193193
});
194194

195195
const expected = "\x1B[1m";
@@ -203,9 +203,9 @@ test "reset required font style" {
203203
var fixed_buf_stream = fixedBufferStream(&buf);
204204

205205
try updateStyle(fixed_buf_stream.writer(), Style{
206-
.font_style = FontStyle.bold,
206+
.font_style = .{ .bold = true },
207207
}, Style{
208-
.font_style = FontStyle{ .bold = true, .underline = true },
208+
.font_style = .{ .bold = true, .underline = true },
209209
});
210210

211211
const expected = "\x1B[0m\x1B[1m";

src/parse_style.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn parseStyle(code: []const u8) ?Style {
3636
var red: u8 = 0;
3737
var green: u8 = 0;
3838

39-
var iter = std.mem.split(u8, code, ";");
39+
var iter = std.mem.splitScalar(u8, code, ';');
4040
while (iter.next()) |str| {
4141
const part = std.fmt.parseInt(u8, str, 10) catch return null;
4242

@@ -164,7 +164,7 @@ test "parse empty style" {
164164
test "parse bold style" {
165165
const actual = parseStyle("01");
166166
const expected = Style{
167-
.font_style = FontStyle.bold,
167+
.font_style = .{ .bold = true },
168168
};
169169

170170
try expectEqual(@as(?Style, expected), actual);
@@ -175,7 +175,7 @@ test "parse yellow style" {
175175
const expected = Style{
176176
.foreground = Color.Yellow,
177177

178-
.font_style = FontStyle{},
178+
.font_style = .{},
179179
};
180180

181181
try expectEqual(@as(?Style, expected), actual);
@@ -186,7 +186,7 @@ test "parse some fixed color" {
186186
const expected = Style{
187187
.foreground = Color{ .Fixed = 220 },
188188

189-
.font_style = FontStyle.bold,
189+
.font_style = .{ .bold = true },
190190
};
191191

192192
try expectEqual(@as(?Style, expected), actual);
@@ -197,7 +197,7 @@ test "parse some rgb color" {
197197
const expected = Style{
198198
.foreground = Color{ .RGB = .{ .r = 123, .g = 123, .b = 123 } },
199199

200-
.font_style = FontStyle.bold,
200+
.font_style = .{ .bold = true },
201201
};
202202

203203
try expectEqual(@as(?Style, expected), actual);

src/style.zig

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,6 @@ pub const FontStyle = packed struct {
5151

5252
const Self = @This();
5353

54-
pub const bold = Self{
55-
.bold = true,
56-
};
57-
58-
pub const dim = Self{
59-
.dim = true,
60-
};
61-
62-
pub const italic = Self{
63-
.italic = true,
64-
};
65-
66-
pub const underline = Self{
67-
.underline = true,
68-
};
69-
70-
pub const slowblink = Self{
71-
.slowblink = true,
72-
};
73-
74-
pub const rapidblink = Self{
75-
.rapidblink = true,
76-
};
77-
78-
pub const reverse = Self{
79-
.reverse = true,
80-
};
81-
82-
pub const hidden = Self{
83-
.hidden = true,
84-
};
85-
86-
pub const crossedout = Self{
87-
.crossedout = true,
88-
};
89-
90-
pub const fraktur = Self{
91-
.fraktur = true,
92-
};
93-
94-
pub const overline = Self{
95-
.overline = true,
96-
};
97-
9854
pub fn toU11(self: Self) u11 {
9955
return @bitCast(self);
10056
}
@@ -130,17 +86,17 @@ pub const FontStyle = packed struct {
13086

13187
test "FontStyle bits" {
13288
try expectEqual(@as(u11, 0), (FontStyle{}).toU11());
133-
try expectEqual(@as(u11, 1), (FontStyle.bold).toU11());
134-
try expectEqual(@as(u11, 1 << 2), (FontStyle.italic).toU11());
89+
try expectEqual(@as(u11, 1), (FontStyle{ .bold = true }).toU11());
90+
try expectEqual(@as(u11, 1 << 2), (FontStyle{ .italic = true }).toU11());
13591
try expectEqual(@as(u11, 1 << 2) | 1, (FontStyle{ .bold = true, .italic = true }).toU11());
13692
try expectEqual(FontStyle{}, FontStyle.fromU11((FontStyle{}).toU11()));
137-
try expectEqual(FontStyle.bold, FontStyle.fromU11((FontStyle.bold).toU11()));
93+
try expectEqual(FontStyle{ .bold = true }, FontStyle.fromU11((FontStyle{ .bold = true }).toU11()));
13894
}
13995

14096
test "FontStyle subsetOf" {
14197
const default = FontStyle{};
142-
const bold = FontStyle.bold;
143-
const italic = FontStyle.italic;
98+
const bold = FontStyle{ .bold = true };
99+
const italic = FontStyle{ .italic = true };
144100
const bold_and_italic = FontStyle{ .bold = true, .italic = true };
145101

146102
try expect(default.subsetOf(default));
@@ -159,8 +115,8 @@ test "FontStyle subsetOf" {
159115

160116
test "FontStyle without" {
161117
const default = FontStyle{};
162-
const bold = FontStyle.bold;
163-
const italic = FontStyle.italic;
118+
const bold = FontStyle{ .bold = true };
119+
const italic = FontStyle{ .italic = true };
164120
const bold_and_italic = FontStyle{ .bold = true, .italic = true };
165121

166122
try expectEqual(default, default.without(default));
@@ -202,10 +158,10 @@ pub const Style = struct {
202158
test "style equality" {
203159
const a = Style{};
204160
const b = Style{
205-
.font_style = FontStyle.bold,
161+
.font_style = .{ .bold = true },
206162
};
207163
const c = Style{
208-
.foreground = Color.Red,
164+
.foreground = .Red,
209165
};
210166

211167
try expect(a.isDefault());

0 commit comments

Comments
 (0)