@@ -15,7 +15,6 @@ const should_enable_signal_handling = !is_windows and builtin.os.tag != .wasi;
15
15
16
16
const logger = std .log .scoped (.zigline );
17
17
18
- // std.os is a LIE!
19
18
const SystemCapabilities = switch (builtin .os .tag ) {
20
19
// FIXME: Windows' console handling is a mess, and std doesn't have
21
20
// the necessary bindings to emulate termios on Windows.
@@ -70,39 +69,39 @@ const SystemCapabilities = switch (builtin.os.tag) {
70
69
};
71
70
}
72
71
73
- pub const POLL_IN = std .os . system .POLL .RDNORM ;
72
+ pub const POLL_IN = std .posix .POLL .RDNORM ;
74
73
75
- pub fn setPollFd (p : * std.os.system .pollfd , f : * anyopaque ) void {
74
+ pub fn setPollFd (p : * std.posix .pollfd , f : * anyopaque ) void {
76
75
p .fd = @ptrCast (f );
77
76
}
78
77
79
- pub fn poll (fds : [* ]std.os.system. pollfd , n : std.os.system .nfds_t , timeout : i32 ) c_int {
80
- // std.os.system. poll() doesn't actually exist on windows lul
78
+ pub fn poll (fds : [* ]std.posix. pollfd , n : std.posix .nfds_t , timeout : i32 ) c_int {
79
+ // std.posix. poll() has a Windows implementation but doesn't accept the second arg, only a slice.
81
80
_ = timeout ;
82
81
fds [n - 1 ].revents = Self .POLL_IN ;
83
82
return 1 ;
84
83
}
85
84
86
85
const pipe = (if (is_windows ) struct {
87
- pub fn pipe () ! [2 ]std.os .fd_t {
86
+ pub fn pipe () ! [2 ]std.posix .fd_t {
88
87
var rd : std.os.windows.HANDLE = undefined ;
89
88
var wr : std.os.windows.HANDLE = undefined ;
90
89
var attrs : std.os.windows.SECURITY_ATTRIBUTES = undefined ;
91
90
attrs .nLength = 0 ;
92
91
try std .os .windows .CreatePipe (& rd , & wr , & attrs );
93
- return [2 ]std.os .fd_t { @ptrCast (rd ), @ptrCast (wr ) };
92
+ return [2 ]std.posix .fd_t { @ptrCast (rd ), @ptrCast (wr ) };
94
93
}
95
94
} else struct {
96
- pub fn pipe () ! [2 ]std.os .fd_t {
97
- return std .os .pipe ();
95
+ pub fn pipe () ! [2 ]std.posix .fd_t {
96
+ return std .posix .pipe ();
98
97
}
99
98
}).pipe ;
100
99
},
101
100
.macos = > struct {
102
101
const Self = @This ();
103
- pub const Sigaction = std .os .Sigaction ;
102
+ pub const Sigaction = std .posix .Sigaction ;
104
103
105
- pub const termios = std .os .termios ;
104
+ pub const termios = std .posix .termios ;
106
105
107
106
pub const V = struct {
108
107
const EOF = 0 ;
@@ -124,11 +123,11 @@ const SystemCapabilities = switch (builtin.os.tag) {
124
123
pub const default_operation_mode = Configuration .OperationMode .Full ;
125
124
126
125
pub fn getTermios () ! Self.termios {
127
- return try std .os .tcgetattr (std .os .STDIN_FILENO );
126
+ return try std .posix .tcgetattr (std .posix .STDIN_FILENO );
128
127
}
129
128
130
129
pub fn setTermios (t : Self.termios ) ! void {
131
- try std .os .tcsetattr (std .os .STDIN_FILENO , std .os . system .TCSA .NOW , t );
130
+ try std .posix .tcsetattr (std .posix .STDIN_FILENO , std .posix .TCSA .NOW , t );
132
131
}
133
132
134
133
pub fn clearEchoAndICanon (t : * Self.termios ) void {
@@ -139,61 +138,59 @@ const SystemCapabilities = switch (builtin.os.tag) {
139
138
return t .cc [cc ];
140
139
}
141
140
142
- pub const POLL_IN = std .os . system .POLL .IN ;
141
+ pub const POLL_IN = std .posix .POLL .IN ;
143
142
144
- pub fn setPollFd (p : * std.os.system. pollfd , f : std.os .fd_t ) void {
143
+ pub fn setPollFd (p : * std.posix. pollfd , f : std.posix .fd_t ) void {
145
144
p .fd = f ;
146
145
}
147
146
148
147
const PollReturnType = if (builtin .link_libc ) c_int else usize ; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
149
- pub fn poll (fds : [* ]std.os.system. pollfd , n : std.os.system .nfds_t , timeout : i32 ) PollReturnType {
150
- return std .os .system .poll (fds , n , timeout );
148
+ pub fn poll (fds : [* ]std.posix. pollfd , n : std.posix .nfds_t , timeout : i32 ) PollReturnType {
149
+ return std .posix .system .poll (fds , n , timeout );
151
150
}
152
151
153
- pub const pipe = std .os .pipe ;
152
+ pub const pipe = std .posix .pipe ;
154
153
},
155
154
else = > struct {
156
155
const Self = @This ();
157
- pub const Sigaction = std .os .Sigaction ;
156
+ pub const Sigaction = std .posix .Sigaction ;
158
157
159
- pub const termios = std .os .termios ;
158
+ pub const termios = std .posix .termios ;
160
159
161
- // FIXME: Non-linux systems...?
162
- pub const V = std .os .linux .V ;
163
- const ECHO = std .os .linux .ECHO ;
164
- const ICANON = std .os .linux .ICANON ;
165
- const ISIG = std .os .linux .ISIG ;
160
+ pub const V = std .posix .V ;
166
161
167
162
pub const default_operation_mode = Configuration .OperationMode .Full ;
168
163
169
164
pub fn getTermios () ! Self.termios {
170
- return try std .os .tcgetattr (std .os .STDIN_FILENO );
165
+ return try std .posix .tcgetattr (std .posix .STDIN_FILENO );
171
166
}
172
167
173
168
pub fn setTermios (t : Self.termios ) ! void {
174
- try std .os .tcsetattr (std .os .STDIN_FILENO , std .os . system .TCSA .NOW , t );
169
+ try std .posix .tcsetattr (std .posix .STDIN_FILENO , std .posix .TCSA .NOW , t );
175
170
}
176
171
177
172
pub fn clearEchoAndICanon (t : * Self.termios ) void {
178
- t .lflag &= ~ ECHO & ~ ICANON & ~ ISIG ;
173
+ t .lflag .ECHO = false ;
174
+ t .lflag .ICANON = false ;
175
+ t .lflag .ISIG = false ;
179
176
}
180
177
181
- pub fn getTermiosCC (t : Self.termios , cc : u32 ) u8 {
182
- return t .cc [cc ];
178
+ pub fn getTermiosCC (t : Self.termios , cc : Self.V ) u8 {
179
+ return t .cc [@intFromEnum ( cc ) ];
183
180
}
184
181
185
- pub const POLL_IN = std .os . system .POLL .IN ;
182
+ pub const POLL_IN = std .posix .POLL .IN ;
186
183
187
- pub fn setPollFd (p : * std.os.system. pollfd , f : std.os .fd_t ) void {
184
+ pub fn setPollFd (p : * std.posix. pollfd , f : std.posix .fd_t ) void {
188
185
p .fd = f ;
189
186
}
190
187
191
188
const PollReturnType = if (builtin .link_libc ) c_int else usize ; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
192
- pub fn poll (fds : [* ]std.os.system. pollfd , n : std.os.system .nfds_t , timeout : i32 ) PollReturnType {
193
- return std .os .system .poll (fds , n , timeout );
189
+ pub fn poll (fds : [* ]std.posix. pollfd , n : std.posix .nfds_t , timeout : i32 ) PollReturnType {
190
+ return std .posix .system .poll (fds , n , timeout );
194
191
}
195
192
196
- pub const pipe = std .os .pipe ;
193
+ pub const pipe = std .posix .pipe ;
197
194
},
198
195
};
199
196
@@ -675,8 +672,8 @@ fn vtMoveRelative(row: i64, col: i64) !void {
675
672
676
673
var signalHandlingData : ? struct {
677
674
pipe : struct {
678
- write : std.os .fd_t ,
679
- read : std.os .fd_t ,
675
+ write : std.posix .fd_t ,
676
+ read : std.posix .fd_t ,
680
677
},
681
678
old_sigint : ? SystemCapabilities.Sigaction = null ,
682
679
old_sigwinch : ? SystemCapabilities.Sigaction = null ,
@@ -690,14 +687,14 @@ var signalHandlingData: ?struct {
690
687
pub const Editor = struct {
691
688
pub const Error =
692
689
std .mem .Allocator .Error ||
693
- std .os .MMapError ||
694
- std .os .OpenError ||
695
- std .os .PipeError ||
696
- std .os .ReadError ||
697
- std .os .RealPathError ||
698
- std .os .TermiosGetError ||
699
- std .os .TermiosSetError ||
700
- std .os .WriteError ||
690
+ std .posix .MMapError ||
691
+ std .posix .OpenError ||
692
+ std .posix .PipeError ||
693
+ std .posix .ReadError ||
694
+ std .posix .RealPathError ||
695
+ std .posix .TermiosGetError ||
696
+ std .posix .TermiosSetError ||
697
+ std .posix .WriteError ||
701
698
error { CodepointTooLarge , Utf8CannotEncodeSurrogateHalf } ||
702
699
error { Empty , Eof , ReadFailure } ||
703
700
error { EndOfStream , StreamTooLong , OperationNotSupported } ||
@@ -883,8 +880,8 @@ pub const Editor = struct {
883
880
control_thread : ? Thread = null ,
884
881
control_thread_exited : bool = false ,
885
882
thread_kill_pipe : ? struct {
886
- write : std.os .fd_t ,
887
- read : std.os .fd_t ,
883
+ write : std.posix .fd_t ,
884
+ read : std.posix .fd_t ,
888
885
} = null ,
889
886
890
887
queue_cond_mutex : Mutex = .{},
@@ -1078,7 +1075,7 @@ pub const Editor = struct {
1078
1075
1079
1076
// In the absence of way to interrupt threads, we're just gonna write to it and hope it dies on its own pace.
1080
1077
if (self .thread_kill_pipe ) | pipes | {
1081
- _ = std .os .write (pipes .write , "x" ) catch 0 ;
1078
+ _ = std .posix .write (pipes .write , "x" ) catch 0 ;
1082
1079
}
1083
1080
}
1084
1081
@@ -1112,14 +1109,14 @@ pub const Editor = struct {
1112
1109
1113
1110
signalHandlingData .? .old_sigint = @as (SystemCapabilities .Sigaction , undefined );
1114
1111
signalHandlingData .? .old_sigwinch = @as (SystemCapabilities .Sigaction , undefined );
1115
- try std .os .sigaction (
1116
- std .os .SIG .INT ,
1117
- & SystemCapabilities.Sigaction { .handler = .{ .handler = @TypeOf (signalHandlingData .? ).handleSignal }, .mask = std .os .empty_sigset , .flags = 0 },
1112
+ try std .posix .sigaction (
1113
+ std .posix .SIG .INT ,
1114
+ & SystemCapabilities.Sigaction { .handler = .{ .handler = @TypeOf (signalHandlingData .? ).handleSignal }, .mask = std .posix .empty_sigset , .flags = 0 },
1118
1115
& signalHandlingData .? .old_sigint .? ,
1119
1116
);
1120
- try std .os .sigaction (
1121
- std .os .SIG .WINCH ,
1122
- & SystemCapabilities.Sigaction { .handler = .{ .handler = @TypeOf (signalHandlingData .? ).handleSignal }, .mask = std .os .empty_sigset , .flags = 0 },
1117
+ try std .posix .sigaction (
1118
+ std .posix .SIG .WINCH ,
1119
+ & SystemCapabilities.Sigaction { .handler = .{ .handler = @TypeOf (signalHandlingData .? ).handleSignal }, .mask = std .posix .empty_sigset , .flags = 0 },
1123
1120
& signalHandlingData .? .old_sigwinch .? ,
1124
1121
);
1125
1122
}
@@ -1231,14 +1228,14 @@ pub const Editor = struct {
1231
1228
1232
1229
std .debug .assert (self .thread_kill_pipe != null );
1233
1230
1234
- var pollfds = [_ ]std.os.system .pollfd { undefined , undefined , undefined };
1231
+ var pollfds = [_ ]std.posix .pollfd { undefined , undefined , undefined };
1235
1232
SystemCapabilities .setPollFd (& pollfds [0 ], stdin .handle );
1236
1233
SystemCapabilities .setPollFd (& pollfds [1 ], self .thread_kill_pipe .? .read );
1237
1234
pollfds [0 ].events = SystemCapabilities .POLL_IN ;
1238
1235
pollfds [1 ].events = SystemCapabilities .POLL_IN ;
1239
1236
pollfds [2 ].events = 0 ;
1240
1237
1241
- var nfds : std.os .nfds_t = 2 ;
1238
+ var nfds : std.posix .nfds_t = 2 ;
1242
1239
1243
1240
if (self .configuration .enable_signal_handling ) {
1244
1241
SystemCapabilities .setPollFd (& pollfds [2 ], signalHandlingData .? .pipe .read );
@@ -1255,7 +1252,7 @@ pub const Editor = struct {
1255
1252
defer self .logic_cond_mutex .unlock ();
1256
1253
const rc = SystemCapabilities .poll (& pollfds , nfds , std .math .maxInt (i32 ));
1257
1254
if (rc < 0 ) {
1258
- self .input_error = switch (std .os .errno (rc )) {
1255
+ self .input_error = switch (std .posix .errno (rc )) {
1259
1256
.INTR = > {
1260
1257
continue ;
1261
1258
},
@@ -1275,7 +1272,7 @@ pub const Editor = struct {
1275
1272
if (pollfds [1 ].revents & SystemCapabilities .POLL_IN != 0 ) {
1276
1273
// We're supposed to die...after draining the pipe.
1277
1274
var buf = [_ ]u8 {0 } ** 8 ;
1278
- _ = std .os .read (self .thread_kill_pipe .? .read , & buf ) catch 0 ;
1275
+ _ = std .posix .read (self .thread_kill_pipe .? .read , & buf ) catch 0 ;
1279
1276
break ;
1280
1277
}
1281
1278
@@ -1287,7 +1284,7 @@ pub const Editor = struct {
1287
1284
break :no_read ;
1288
1285
};
1289
1286
switch (signo ) {
1290
- std .os .SIG .WINCH = > {
1287
+ std .posix .SIG .WINCH = > {
1291
1288
self .signal_queue .enqueue (.SIGWINCH ) catch {
1292
1289
break :no_read ;
1293
1290
};
@@ -2102,9 +2099,9 @@ pub const Editor = struct {
2102
2099
var buf = [16 ]u8 { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
2103
2100
var more_junk_to_read = false ;
2104
2101
var stdin = std .io .getStdIn ();
2105
- var pollfds = [1 ]std.os.system .pollfd {undefined };
2102
+ var pollfds = [1 ]std.posix .pollfd {undefined };
2106
2103
{
2107
- var pollfd : std.os.system .pollfd = undefined ;
2104
+ var pollfd : std.posix .pollfd = undefined ;
2108
2105
SystemCapabilities .setPollFd (& pollfd , stdin .handle );
2109
2106
pollfd .events = SystemCapabilities .POLL_IN ;
2110
2107
pollfd .revents = 0 ;
@@ -2710,13 +2707,13 @@ pub const Editor = struct {
2710
2707
self .num_columns = 80 ;
2711
2708
self .num_lines = 24 ;
2712
2709
if (! is_windows ) {
2713
- const system = if (builtin .link_libc and builtin . os .tag == .linux ) std .os .linux else std .os . system ;
2714
- var ws : system .winsize = undefined ;
2715
- if (std . os . system . ioctl (std .io .getStdIn ().handle , system .T .IOCGWINSZ , @intFromPtr (& ws )) != 0 ) {
2716
- const fd = std .os . system . open ("/dev/tty" , .{ .ACCMODE = .RDONLY }, @as (std .os .mode_t , 0 ));
2710
+ const ioctl = if (builtin .os .tag == .linux ) std .os .linux . ioctl else std .c . ioctl ;
2711
+ var ws : std.posix .winsize = undefined ;
2712
+ if (ioctl (std .io .getStdIn ().handle , std . posix .T .IOCGWINSZ , @intFromPtr (& ws )) != 0 ) {
2713
+ const fd = std .posix . open ("/dev/tty" , .{ .ACCMODE = .RDONLY }, @as (std .posix .mode_t , 0 )) catch return ;
2717
2714
if (fd != -1 ) {
2718
- _ = std . os . system . ioctl (@intCast (fd ), system .T .IOCGWINSZ , @intFromPtr (& ws ));
2719
- _ = std .os . system .close (@intCast (fd ));
2715
+ _ = ioctl (@intCast (fd ), std . posix .T .IOCGWINSZ , @intFromPtr (& ws ));
2716
+ _ = std .posix .close (@intCast (fd ));
2720
2717
} else {
2721
2718
return ;
2722
2719
}
0 commit comments