Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Namespace

CONSOLE

Public Namespace
std.os.windows.CONSOLE
pub const CONSOLE = struct

Namespaces

File

os/windows.zig:888
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
pub const CONSOLE = struct {
    pub const USER_IO = struct {
        pub const INFO = struct {
            pub const CP = extern struct {
                /// GetCP: output
                /// SetCP: input
                CodePage: UINT,
                /// input
                Mode: MODE,

                pub const MODE = enum(BOOLEAN.Backing) {
                    Input,
                    Output,
                };
            };

            pub const WRITE = extern struct {
                /// output, in bytes
                Size: DWORD,
                /// input
                Mode: MODE,

                pub const MODE = enum(BOOLEAN.Backing) {
                    Character,
                    WideCharacter,
                };
            };

            pub const FILL = extern struct {
                /// input
                dwWriteCoord: COORD,
                /// input
                Tag: WITH.Tag,
                /// input
                With: WITH.Payload,
                /// input/output, in characters
                nLength: DWORD,

                pub const WITH = union(enum(DWORD)) {
                    Character: CHAR = 1,
                    WideCharacter: WCHAR = 2,
                    Attribute: WORD = 3,

                    pub const Tag = @typeInfo(WITH).@"union".tag_type.?;
                    pub const Payload = PAYLOAD: {
                        const with_info = @typeInfo(WITH).@"union";
                        break :PAYLOAD @Union(.@"extern", null, with_info.field_names, with_info.field_types[0..], &@splat(.{}));
                    };
                };
            };

            /// all output
            pub const SCREEN_BUFFER = extern struct {
                dwSize: COORD,
                dwCursorPosition: COORD,
                dwWindowPosition: COORD,
                wAttributes: WORD,
                dwWindowSize: COORD,
                dwMaximumWindowSize: COORD,
                wPopupAttributes: WORD,
                bFullscreenSupported: BOOL,
                ColorTable: [16]COLORREF,
            };

            pub const READ_OUTPUT_CHARACTER = extern struct {
                /// input
                dwReadCoord: COORD,
                Mode: MODE,
                /// output, in characters
                nLength: DWORD,

                pub const MODE = enum(DWORD) {
                    Character = 1,
                    WideCharacter = 2,
                };
            };
        };

        pub fn GET_CP(mode: INFO.CP.MODE) Header.With(INFO.CP) {
            return .init(.GetCP, .{ .CodePage = undefined, .Mode = mode });
        }
        pub const GET_MODE: Header.With(DWORD) = .init(.GetMode, undefined);
        pub fn SET_MODE(mode: DWORD) Header.With(DWORD) {
            return .init(.SetMode, mode);
        }
        pub fn WRITE(mode: INFO.WRITE.MODE) Header.With(INFO.WRITE) {
            return .init(.Write, .{ .Size = undefined, .Mode = mode });
        }
        pub fn FILL(with: INFO.FILL.WITH, len: DWORD, coord: COORD) Header.With(INFO.FILL) {
            return .init(.Fill, .{
                .dwWriteCoord = coord,
                .Tag = with,
                .With = switch (with) {
                    inline else => |payload, tag| @unionInit(
                        INFO.FILL.WITH.Payload,
                        @tagName(tag),
                        payload,
                    ),
                },
                .nLength = len,
            });
        }
        pub fn SET_CP(mode: INFO.CP.MODE, cp: UINT) Header.With(INFO.CP) {
            return .init(.SetCP, .{ .CodePage = cp, .Mode = mode });
        }
        pub const GET_SCREEN_BUFFER_INFO: Header.With(INFO.SCREEN_BUFFER) =
            .init(.GetScreenBufferInfo, undefined);
        pub fn SET_CURSOR_POSITION(coord: COORD) Header.With(COORD) {
            return .init(.SetCursorPosition, coord);
        }
        pub fn SET_TEXT_ATTRIBUTE(attribute: WORD) Header.With(WORD) {
            return .init(.SetTextAttribute, attribute);
        }
        pub fn READ_OUTPUT_CHARACTER(
            coord: COORD,
            mode: INFO.READ_OUTPUT_CHARACTER.MODE,
        ) Header.With(INFO.READ_OUTPUT_CHARACTER) {
            return .init(.ReadOutputCharacter, .{
                .dwReadCoord = coord,
                .Mode = mode,
                .nLength = undefined,
            });
        }

        pub const InputBuffer = extern struct {
            Size: u32,
            Pointer: *const anyopaque,
        };

        pub const OutputBuffer = extern struct {
            Size: u32,
            Pointer: *anyopaque,
        };

        pub fn Request(comptime in_len: u32, comptime out_len: u32) type {
            return extern struct {
                Handle: ?HANDLE,
                InputBuffersLength: u32,
                OutputBuffersLength: u32,
                InputBuffers: [in_len]InputBuffer,
                OutputBuffers: [out_len]OutputBuffer,

                pub fn init(
                    handle: ?HANDLE,
                    in: [in_len]InputBuffer,
                    out: [out_len]OutputBuffer,
                ) @This() {
                    return .{
                        .Handle = handle,
                        .InputBuffersLength = in_len,
                        .OutputBuffersLength = out_len,
                        .InputBuffers = in,
                        .OutputBuffers = out,
                    };
                }
            };
        }

        pub const Header = extern struct {
            Operation: Operation,
            Size: u32,

            pub fn With(comptime Data: type) type {
                return extern struct {
                    Header: Header,
                    Data: Data,

                    pub fn init(operation: Operation, data: Data) @This() {
                        return .{
                            .Header = .{ .Operation = operation, .Size = @sizeOf(Data) },
                            .Data = data,
                        };
                    }

                    pub fn request(
                        with: *@This(),
                        file: ?Io.File,
                        comptime in_len: u32,
                        in: [in_len]InputBuffer,
                        comptime out_len: u32,
                        out: [out_len]OutputBuffer,
                    ) Request(1 + in_len, 1 + out_len) {
                        return .init(
                            if (file) |f| f.handle else null,
                            [1]InputBuffer{.{
                                .Size = @offsetOf(@This(), "Data") + @sizeOf(Data),
                                .Pointer = with,
                            }} ++ in,
                            [1]OutputBuffer{.{ .Size = @sizeOf(Data), .Pointer = &with.Data }} ++ out,
                        );
                    }

                    pub fn operate(with: *@This(), io: Io, file: ?Io.File) Io.Cancelable!NTSTATUS {
                        return (try io.operate(.{ .device_io_control = .{
                            .file = .{
                                .handle = peb().ProcessParameters.ConsoleHandle,
                                .flags = .{ .nonblocking = false },
                            },
                            .code = IOCTL.CONDRV.ISSUE_USER_IO,
                            .in = @ptrCast(&with.request(file, 0, .{}, 0, .{})),
                        } })).device_io_control.u.Status;
                    }
                };
            }
        };

        pub const Operation = enum(u32) {
            GetCP = 0x1000000,
            GetMode = 0x1000001,
            SetMode = 0x1000002,
            Read = 0x1000005,
            Write = 0x1000006,
            Fill = 0x2000000,
            SetCP = 0x2000004,
            GetScreenBufferInfo = 0x2000007,
            SetCursorPosition = 0x200000a,
            SetTextAttribute = 0x200000d,
            ReadOutputCharacter = 0x200000f,
            _,
        };
    };
}