Change control characters for underlining and strikethrough to __ and ~~

fixes #773
This commit is contained in:
IntegratedQuantum 2024-11-13 21:37:55 +01:00
parent d9da715e6b
commit c53dd26da7
2 changed files with 19 additions and 4 deletions

View File

@ -600,6 +600,12 @@ pub const TextBuffer = struct { // MARK: TextBuffer
self.curChar = self.unicodeIterator.nextCodepoint() orelse return null;
}
fn peekNextByte(self: *Parser) u8 {
const next = self.unicodeIterator.peek(1);
if(next.len == 0) return 0;
return next[0];
}
fn parse(self: *Parser) void {
self.curIndex = @intCast(self.unicodeIterator.i);
self.curChar = self.unicodeIterator.nextCodepoint() orelse return;
@ -614,12 +620,21 @@ pub const TextBuffer = struct { // MARK: TextBuffer
}
},
'_' => {
if(self.peekNextByte() == '_') {
self.appendControlGetNext() orelse return;
self.appendControlGetNext() orelse return;
self.currentFontEffect.underline = !self.currentFontEffect.underline;
} else {
self.appendGetNext() orelse return;
}
},
'~' => {
if(self.peekNextByte() == '~') {
self.appendControlGetNext() orelse return;
if(self.curChar == '_') {
self.appendControlGetNext() orelse return;
self.currentFontEffect.strikethrough = !self.currentFontEffect.strikethrough;
} else {
self.currentFontEffect.underline = !self.currentFontEffect.underline;
self.appendGetNext() orelse return;
}
},
'\\' => {

View File

@ -40,7 +40,7 @@ pub fn onOpen() void {
list.add(Label.init(.{0, 0}, width, "#ff0000Warning: #ffffffYou lose access to your inventory data when changing the name!", .center));
}
list.add(Label.init(.{0, 0}, width, "Cubyz supports formatting your username using a markdown-like syntax:", .center));
list.add(Label.init(.{0, 0}, width, "\\**italic*\\* \\*\\***bold**\\*\\* \\__underlined_\\_ \\_\\___strike-through__\\_\\_", .center));
list.add(Label.init(.{0, 0}, width, "\\**italic*\\* \\*\\***bold**\\*\\* \\_\\___underlined__\\_\\_ \\~\\~~~strike-through~~\\~\\~", .center));
list.add(Label.init(.{0, 0}, width, "Even colors are possible, using the hexadecimal color code:", .center));
list.add(Label.init(.{0, 0}, width, "\\##ff0000ff#ffffff00#ffffff00#ff0000red#ffffff \\##ff0000ff#00770077#ffffff00#ff7700orange#ffffff \\##ffffff00#00ff00ff#ffffff00#00ff00green#ffffff \\##ffffff00#ffffff00#0000ffff#0000ffblue", .center));
textComponent = TextInput.init(.{0, 0}, width, 32, if(settings.playerName.len == 0) "quanturmdoelvloper" else settings.playerName, .{.callback = &apply});