@@ -3,48 +3,45 @@ const command = @import("./command.zig");
33
44const Self = @This ();
55
6- out : std.fs.File .Writer ,
6+ writer : * std.Io .Writer ,
77use_color : bool ,
88
99const color_clear = "0" ;
1010
11- pub fn init (file : std.fs.File , color : command.ColorUsage ) Self {
11+ pub fn init (writer : * std.Io.Writer , use_color : bool ) Self {
1212 return .{
13- .out = file .writer (),
14- .use_color = switch (color ) {
15- .always = > true ,
16- .never = > false ,
17- .auto = > std .posix .isatty (file .handle ),
18- },
13+ .writer = writer ,
14+ .use_color = use_color ,
1915 };
2016}
2117
22- pub inline fn write (self : * const Self , text : [] const u8 ) void {
23- _ = self .out . write ( text ) catch unreachable ;
18+ pub fn flush (self : * Self ) void {
19+ self .writer . flush ( ) catch unreachable ;
2420}
2521
26- pub inline fn printNewLine (self : * const Self ) void {
27- self .write ( " \n " ) ;
22+ pub inline fn write (self : * Self , text : [] const u8 ) void {
23+ _ = self .writer . writeAll ( text ) catch unreachable ;
2824}
2925
30- pub inline fn format (self : * const Self , comptime text : [] const u8 , args : anytype ) void {
31- std . fmt . format ( self . out , text , args ) catch unreachable ;
26+ pub inline fn printNewLine (self : * Self ) void {
27+ self . writer . writeByte ( ' \n ' ) catch unreachable ;
3228}
3329
34- pub inline fn printColor (self : * const Self , color : []const u8 ) void {
30+ pub inline fn format (self : * Self , comptime fmt : []const u8 , args : anytype ) void {
31+ self .writer .print (fmt , args ) catch unreachable ;
32+ }
33+
34+ pub inline fn printColor (self : * Self , color : []const u8 ) void {
3535 if (self .use_color )
3636 self .format ("{c}[{s}m" , .{ 0x1b , color });
3737}
3838
39- pub inline fn printInColor (self : * const Self , color : []const u8 , text : []const u8 ) void {
39+ pub inline fn printInColor (self : * Self , color : []const u8 , text : []const u8 ) void {
4040 self .printColor (color );
4141 self .write (text );
4242 self .printColor (color_clear );
4343}
4444
45- pub inline fn printSpaces (self : * const Self , cnt : usize ) void {
46- var i : usize = 0 ;
47- while (i < cnt ) : (i += 1 ) {
48- self .write (" " );
49- }
45+ pub inline fn printSpaces (self : * Self , cnt : usize ) void {
46+ self .writer .splatByteAll (' ' , cnt ) catch unreachable ;
5047}
0 commit comments