|
| 1 | +#include "Console.h" |
| 2 | + |
| 3 | +void FormatBoxedMessage(SpanChar destination, ReadOnlySpanChar message) |
| 4 | +{ |
| 5 | + auto upLeftCorner = String("┌"); |
| 6 | + auto upRightCorner = String("┐"); |
| 7 | + auto downLeftCorner = String("└"); |
| 8 | + auto downRightCorner = String("┘"); |
| 9 | + auto horizontalLine = String("─"); |
| 10 | + auto verticalLine = String("│"); |
| 11 | + |
| 12 | + MemoryCopy(destination, upLeftCorner); |
| 13 | + destination = SpanSliceFrom(destination, upLeftCorner.Length); |
| 14 | + |
| 15 | + for (uint32_t i = 0; i < message.Length + 2; i++) |
| 16 | + { |
| 17 | + MemoryCopy(destination, horizontalLine); |
| 18 | + destination = SpanSliceFrom(destination, horizontalLine.Length); |
| 19 | + } |
| 20 | + |
| 21 | + MemoryCopy(destination, upRightCorner); |
| 22 | + destination = SpanSliceFrom(destination, upRightCorner.Length); |
| 23 | + |
| 24 | + MemoryCopy(destination, String("\n")); |
| 25 | + destination = SpanSliceFrom(destination, 1); |
| 26 | + |
| 27 | + MemoryCopy(destination, verticalLine); |
| 28 | + destination = SpanSliceFrom(destination, verticalLine.Length); |
| 29 | + |
| 30 | + MemoryCopy(destination, String(" ")); |
| 31 | + destination = SpanSliceFrom(destination, 1); |
| 32 | + |
| 33 | + MemoryCopy(destination, message); |
| 34 | + destination = SpanSliceFrom(destination, message.Length); |
| 35 | + |
| 36 | + MemoryCopy(destination, String(" ")); |
| 37 | + destination = SpanSliceFrom(destination, 1); |
| 38 | + |
| 39 | + MemoryCopy(destination, verticalLine); |
| 40 | + destination = SpanSliceFrom(destination, verticalLine.Length); |
| 41 | + |
| 42 | + MemoryCopy(destination, String("\n")); |
| 43 | + destination = SpanSliceFrom(destination, 1); |
| 44 | + |
| 45 | + MemoryCopy(destination, downLeftCorner); |
| 46 | + destination = SpanSliceFrom(destination, downLeftCorner.Length); |
| 47 | + |
| 48 | + for (uint32_t i = 0; i < message.Length + 2; i++) |
| 49 | + { |
| 50 | + MemoryCopy(destination, horizontalLine); |
| 51 | + destination = SpanSliceFrom(destination, horizontalLine.Length); |
| 52 | + } |
| 53 | + |
| 54 | + MemoryCopy(destination, downRightCorner); |
| 55 | + destination = SpanSliceFrom(destination, downRightCorner.Length); |
| 56 | + |
| 57 | + // TODO: There is a problem here with null terminator not present |
| 58 | +} |
| 59 | + |
| 60 | +void ConsoleSetForegroundColor(Color color) |
| 61 | +{ |
| 62 | + ConsolePrint(String("\x1b[38;2;%d;%d;%dm"), (int32_t)color.Red, (int32_t)color.Green, (int32_t)color.Blue); |
| 63 | +} |
| 64 | + |
| 65 | +void ConsoleResetStyle() |
| 66 | +{ |
| 67 | + ConsolePrint(String("\x1b[0m")); |
| 68 | + ConsoleSetForegroundColor(ConsoleColorNormal); |
| 69 | +} |
| 70 | + |
| 71 | +void ConsolePrintBoxMessage(ReadOnlySpanChar message) |
| 72 | +{ |
| 73 | + // TODO: Use the stack memory arena here |
| 74 | + auto boxedMessage = StackAlloc(char, 512); |
| 75 | + FormatBoxedMessage(boxedMessage, message); |
| 76 | + ConsolePrint(String("\n%s\n"), boxedMessage); |
| 77 | +} |
0 commit comments