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