| ... | @@ -44,10 +44,10 @@ pub const escape = struct { | ... | @@ -44,10 +44,10 @@ pub const escape = struct { |
| 44 | pub const SS3 = ascii.ESC.s() ++ "O"; | 44 | pub const SS3 = ascii.ESC.s() ++ "O"; |
| 45 | pub const DCS = ascii.ESC.s() ++ "P"; | 45 | pub const DCS = ascii.ESC.s() ++ "P"; |
| 46 | pub const CSI = ascii.ESC.s() ++ "["; | 46 | pub const CSI = ascii.ESC.s() ++ "["; |
| 47 | pub const ST = ascii.ESC.s() ++ "\\"; | 47 | pub const ST = ascii.ESC.s() ++ "\\"; |
| 48 | pub const OSC = ascii.ESC.s() ++ "]"; | 48 | pub const OSC = ascii.ESC.s() ++ "]"; |
| 49 | pub const SOS = ascii.ESC.s() ++ "X"; | 49 | pub const SOS = ascii.ESC.s() ++ "X"; |
| 50 | pub const PM = ascii.ESC.s() ++ "^"; | 50 | pub const PM = ascii.ESC.s() ++ "^"; |
| 51 | pub const APC = ascii.ESC.s() ++ "_"; | 51 | pub const APC = ascii.ESC.s() ++ "_"; |
| 52 | pub const RIS = ascii.ESC.s() ++ "c"; | 52 | pub const RIS = ascii.ESC.s() ++ "c"; |
| 53 | }; | 53 | }; |
| ... | @@ -65,76 +65,104 @@ fn arr_i_to_s(x: anytype) [][]const u8 { | ... | @@ -65,76 +65,104 @@ fn arr_i_to_s(x: anytype) [][]const u8 { |
| 65 | } | 65 | } |
| 66 | | 66 | |
| 67 | pub const csi = struct { | 67 | pub const csi = struct { |
| 68 | pub fn CursorUp(comptime n: i32) []const u8 { return make_csi_sequence("A", .{n}); } | 68 | pub fn CursorUp(comptime n: i32) []const u8 { |
| 69 | pub fn CursorDown(comptime n: i32) []const u8 { return make_csi_sequence("B", .{n}); } | 69 | return make_csi_sequence("A", .{n}); |
| 70 | pub fn CursorForward(comptime n: i32) []const u8 { return make_csi_sequence("C", .{n}); } | 70 | } |
| 71 | pub fn CursorBack(comptime n: i32) []const u8 { return make_csi_sequence("D", .{n}); } | 71 | pub fn CursorDown(comptime n: i32) []const u8 { |
| 72 | pub fn CursorNextLine(comptime n: i32) []const u8 { return make_csi_sequence("E", .{n}); } | 72 | return make_csi_sequence("B", .{n}); |
| 73 | pub fn CursorPrevLine(comptime n: i32) []const u8 { return make_csi_sequence("F", .{n}); } | 73 | } |
| 74 | pub fn CursorHorzAbs(comptime n: i32) []const u8 { return make_csi_sequence("G", .{n}); } | 74 | pub fn CursorForward(comptime n: i32) []const u8 { |
| 75 | pub fn CursorPos(comptime n: i32, m: i32) []const u8 { return make_csi_sequence("H", .{n, m}); } | 75 | return make_csi_sequence("C", .{n}); |
| 76 | pub fn EraseInDisplay(comptime n: i32) []const u8 { return make_csi_sequence("J", .{n}); } | 76 | } |
| 77 | pub fn EraseInLine(comptime n: i32) []const u8 { return make_csi_sequence("K", .{n}); } | 77 | pub fn CursorBack(comptime n: i32) []const u8 { |
| 78 | pub fn ScrollUp(comptime n: i32) []const u8 { return make_csi_sequence("S", .{n}); } | 78 | return make_csi_sequence("D", .{n}); |
| 79 | pub fn ScrollDown(comptime n: i32) []const u8 { return make_csi_sequence("T", .{n}); } | 79 | } |
| 80 | pub fn HorzVertPos(comptime n: i32, m: i32) []const u8 { return make_csi_sequence("f", .{n, m}); } | 80 | pub fn CursorNextLine(comptime n: i32) []const u8 { |
| 81 | pub fn SGR(comptime ns: anytype) []const u8 { return make_csi_sequence("m", ns); } | 81 | return make_csi_sequence("E", .{n}); |
| | 82 | } |
| | 83 | pub fn CursorPrevLine(comptime n: i32) []const u8 { |
| | 84 | return make_csi_sequence("F", .{n}); |
| | 85 | } |
| | 86 | pub fn CursorHorzAbs(comptime n: i32) []const u8 { |
| | 87 | return make_csi_sequence("G", .{n}); |
| | 88 | } |
| | 89 | pub fn CursorPos(comptime n: i32, m: i32) []const u8 { |
| | 90 | return make_csi_sequence("H", .{ n, m }); |
| | 91 | } |
| | 92 | pub fn EraseInDisplay(comptime n: i32) []const u8 { |
| | 93 | return make_csi_sequence("J", .{n}); |
| | 94 | } |
| | 95 | pub fn EraseInLine(comptime n: i32) []const u8 { |
| | 96 | return make_csi_sequence("K", .{n}); |
| | 97 | } |
| | 98 | pub fn ScrollUp(comptime n: i32) []const u8 { |
| | 99 | return make_csi_sequence("S", .{n}); |
| | 100 | } |
| | 101 | pub fn ScrollDown(comptime n: i32) []const u8 { |
| | 102 | return make_csi_sequence("T", .{n}); |
| | 103 | } |
| | 104 | pub fn HorzVertPos(comptime n: i32, m: i32) []const u8 { |
| | 105 | return make_csi_sequence("f", .{ n, m }); |
| | 106 | } |
| | 107 | pub fn SGR(comptime ns: anytype) []const u8 { |
| | 108 | return make_csi_sequence("m", ns); |
| | 109 | } |
| 82 | }; | 110 | }; |
| 83 | | 111 | |
| 84 | pub const style = struct { | 112 | pub const style = struct { |
| 85 | pub const ResetAll = csi.SGR(.{0}); | 113 | pub const ResetAll = csi.SGR(.{0}); |
| 86 | | 114 | |
| 87 | pub const Bold = csi.SGR(.{1}); | 115 | pub const Bold = csi.SGR(.{1}); |
| 88 | pub const Faint = csi.SGR(.{2}); | 116 | pub const Faint = csi.SGR(.{2}); |
| 89 | pub const Italic = csi.SGR(.{3}); | 117 | pub const Italic = csi.SGR(.{3}); |
| 90 | pub const Underline = csi.SGR(.{4}); | 118 | pub const Underline = csi.SGR(.{4}); |
| 91 | pub const BlinkSlow = csi.SGR(.{5}); | 119 | pub const BlinkSlow = csi.SGR(.{5}); |
| 92 | pub const BlinkFast = csi.SGR(.{6}); | 120 | pub const BlinkFast = csi.SGR(.{6}); |
| 93 | | 121 | |
| 94 | pub const ResetFont = csi.SGR(.{10}); | 122 | pub const ResetFont = csi.SGR(.{10}); |
| 95 | pub const Font1 = csi.SGR(.{11}); | 123 | pub const Font1 = csi.SGR(.{11}); |
| 96 | pub const Font2 = csi.SGR(.{12}); | 124 | pub const Font2 = csi.SGR(.{12}); |
| 97 | pub const Font3 = csi.SGR(.{13}); | 125 | pub const Font3 = csi.SGR(.{13}); |
| 98 | pub const Font4 = csi.SGR(.{14}); | 126 | pub const Font4 = csi.SGR(.{14}); |
| 99 | pub const Font5 = csi.SGR(.{15}); | 127 | pub const Font5 = csi.SGR(.{15}); |
| 100 | pub const Font6 = csi.SGR(.{16}); | 128 | pub const Font6 = csi.SGR(.{16}); |
| 101 | pub const Font7 = csi.SGR(.{17}); | 129 | pub const Font7 = csi.SGR(.{17}); |
| 102 | pub const Font8 = csi.SGR(.{18}); | 130 | pub const Font8 = csi.SGR(.{18}); |
| 103 | pub const Font9 = csi.SGR(.{19}); | 131 | pub const Font9 = csi.SGR(.{19}); |
| 104 | | 132 | |
| 105 | pub const UnderlineDouble = csi.SGR(.{21}); | 133 | pub const UnderlineDouble = csi.SGR(.{21}); |
| 106 | pub const ResetIntensity = csi.SGR(.{22}); | 134 | pub const ResetIntensity = csi.SGR(.{22}); |
| 107 | pub const ResetItalic = csi.SGR(.{23}); | 135 | pub const ResetItalic = csi.SGR(.{23}); |
| 108 | pub const ResetUnderline = csi.SGR(.{24}); | 136 | pub const ResetUnderline = csi.SGR(.{24}); |
| 109 | pub const ResetBlink = csi.SGR(.{25}); | 137 | pub const ResetBlink = csi.SGR(.{25}); |
| 110 | | 138 | |
| 111 | pub const FgBlack = csi.SGR(.{30}); | 139 | pub const FgBlack = csi.SGR(.{30}); |
| 112 | pub const FgRed = csi.SGR(.{31}); | 140 | pub const FgRed = csi.SGR(.{31}); |
| 113 | pub const FgGreen = csi.SGR(.{32}); | 141 | pub const FgGreen = csi.SGR(.{32}); |
| 114 | pub const FgYellow = csi.SGR(.{33}); | 142 | pub const FgYellow = csi.SGR(.{33}); |
| 115 | pub const FgBlue = csi.SGR(.{34}); | 143 | pub const FgBlue = csi.SGR(.{34}); |
| 116 | pub const FgMagenta = csi.SGR(.{35}); | 144 | pub const FgMagenta = csi.SGR(.{35}); |
| 117 | pub const FgCyan = csi.SGR(.{36}); | 145 | pub const FgCyan = csi.SGR(.{36}); |
| 118 | pub const FgWhite = csi.SGR(.{37}); | 146 | pub const FgWhite = csi.SGR(.{37}); |
| 119 | // Fg8bit = func(n int) string { return csi.SGR(38, 5, n) } | 147 | // Fg8bit = func(n int) string { return csi.SGR(38, 5, n) } |
| 120 | // Fg24bit = func(r, g, b int) string { return csi.SGR(38, 2, r, g, b) } | 148 | // Fg24bit = func(r, g, b int) string { return csi.SGR(38, 2, r, g, b) } |
| 121 | pub const ResetFgColor = csi.SGR(.{39}); | 149 | pub const ResetFgColor = csi.SGR(.{39}); |
| 122 | | 150 | |
| 123 | pub const BgBlack = csi.SGR(.{40}); | 151 | pub const BgBlack = csi.SGR(.{40}); |
| 124 | pub const BgRed = csi.SGR(.{41}); | 152 | pub const BgRed = csi.SGR(.{41}); |
| 125 | pub const BgGreen = csi.SGR(.{42}); | 153 | pub const BgGreen = csi.SGR(.{42}); |
| 126 | pub const BgYellow = csi.SGR(.{43}); | 154 | pub const BgYellow = csi.SGR(.{43}); |
| 127 | pub const BgBlue = csi.SGR(.{44}); | 155 | pub const BgBlue = csi.SGR(.{44}); |
| 128 | pub const BgMagenta = csi.SGR(.{45}); | 156 | pub const BgMagenta = csi.SGR(.{45}); |
| 129 | pub const BgCyan = csi.SGR(.{46}); | 157 | pub const BgCyan = csi.SGR(.{46}); |
| 130 | pub const BgWhite = csi.SGR(.{47}); | 158 | pub const BgWhite = csi.SGR(.{47}); |
| 131 | // Bg8bit = func(n int) string { return csi.SGR(48, 5, n) } | 159 | // Bg8bit = func(n int) string { return csi.SGR(48, 5, n) } |
| 132 | // Bg24bit = func(r, g, b int) string { return csi.SGR(48, 2, r, g, b) } | 160 | // Bg24bit = func(r, g, b int) string { return csi.SGR(48, 2, r, g, b) } |
| 133 | pub const ResetBgColor = csi.SGR(.{49}); | 161 | pub const ResetBgColor = csi.SGR(.{49}); |
| 134 | | 162 | |
| 135 | pub const Framed = csi.SGR(.{51}); | 163 | pub const Framed = csi.SGR(.{51}); |
| 136 | pub const Encircled = csi.SGR(.{52}); | 164 | pub const Encircled = csi.SGR(.{52}); |
| 137 | pub const Overlined = csi.SGR(.{53}); | 165 | pub const Overlined = csi.SGR(.{53}); |
| 138 | pub const ResetFrameEnci = csi.SGR(.{54}); | 166 | pub const ResetFrameEnci = csi.SGR(.{54}); |
| 139 | pub const ResetOverlined = csi.SGR(.{55}); | 167 | pub const ResetOverlined = csi.SGR(.{55}); |
| 140 | }; | 168 | }; |
| ... | @@ -152,11 +180,11 @@ pub const color = struct { | ... | @@ -152,11 +180,11 @@ pub const color = struct { |
| 152 | }; | 180 | }; |
| 153 | | 181 | |
| 154 | pub fn Fg(s: Color, comptime m: []const u8) []const u8 { | 182 | pub fn Fg(s: Color, comptime m: []const u8) []const u8 { |
| 155 | return csi.SGR(.{30+@enumToInt(s)}) ++ m ++ style.ResetFgColor; | 183 | return csi.SGR(.{30 + @enumToInt(s)}) ++ m ++ style.ResetFgColor; |
| 156 | } | 184 | } |
| 157 | | 185 | |
| 158 | pub fn Bg(s: Color, comptime m: []const u8) []const u8 { | 186 | pub fn Bg(s: Color, comptime m: []const u8) []const u8 { |
| 159 | return csi.SGR(.{40+@enumToInt(s)}) ++ m ++ style.ResetBgColor; | 187 | return csi.SGR(.{40 + @enumToInt(s)}) ++ m ++ style.ResetBgColor; |
| 160 | } | 188 | } |
| 161 | }; | 189 | }; |
| 162 | | 190 | |
| ... | @@ -166,9 +194,9 @@ pub const color = struct { | ... | @@ -166,9 +194,9 @@ pub const color = struct { |
| 166 | | 194 | |
| 167 | fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 { | 195 | fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 { |
| 168 | var buf: []const u8 = ""; | 196 | var buf: []const u8 = ""; |
| 169 | for (xs) |x,i| { | 197 | for (xs) |x, i| { |
| 170 | buf = buf ++ x; | 198 | buf = buf ++ x; |
| 171 | if (i < xs.len-1) buf = buf ++ delim; | 199 | if (i < xs.len - 1) buf = buf ++ delim; |
| 172 | } | 200 | } |
| 173 | return buf; | 201 | return buf; |
| 174 | } | 202 | } |