From b213fd831fa8a9dc598e1a36d372e89e1ee0f1f4 Mon Sep 17 00:00:00 2001 From: TwistedAsylumMC Date: Fri, 19 Apr 2024 21:51:36 +0100 Subject: [PATCH] minecraft/text: Expose formatting code constants --- minecraft/text/colour.go | 4 +- minecraft/text/doc.go | 3 +- minecraft/text/map.go | 188 +++++++++++++++++++-------------------- 3 files changed, 98 insertions(+), 97 deletions(-) diff --git a/minecraft/text/colour.go b/minecraft/text/colour.go index 0383740d..033546b6 100644 --- a/minecraft/text/colour.go +++ b/minecraft/text/colour.go @@ -59,7 +59,7 @@ type enc struct { // the stack or removes a colour from the stack. func (e *enc) process(tok html.Token) { if e.first { - e.w.WriteString(reset) + e.w.WriteString(Reset) e.first = false } switch tok.Type { @@ -91,6 +91,6 @@ func (e *enc) writeText(s string) { } e.w.WriteString(s) if len(e.formatStack) != 0 { - e.w.WriteString(reset) + e.w.WriteString(Reset) } } diff --git a/minecraft/text/doc.go b/minecraft/text/doc.go index 37da592f..778f10a0 100644 --- a/minecraft/text/doc.go +++ b/minecraft/text/doc.go @@ -1,3 +1,4 @@ // Package text has utility methods used for formatting text to display in Minecraft, and to convert these -// colour codes into codes suitable for the command line. +// colour codes into codes suitable for the command line. It also contains constants for each of the +// Minecraft colours and formatting codes. package text diff --git a/minecraft/text/map.go b/minecraft/text/map.go index ae996baa..3e0cce84 100644 --- a/minecraft/text/map.go +++ b/minecraft/text/map.go @@ -3,37 +3,37 @@ package text import "strings" const ( - black = "§0" - darkBlue = "§1" - darkGreen = "§2" - darkAqua = "§3" - darkRed = "§4" - darkPurple = "§5" - orange = "§6" - grey = "§7" - darkGrey = "§8" - blue = "§9" - green = "§a" - aqua = "§b" - red = "§c" - purple = "§d" - yellow = "§e" - white = "§f" - darkYellow = "§g" - quartz = "§h" - iron = "§i" - netherite = "§j" - obfuscated = "§k" - bold = "§l" - redstone = "§m" - copper = "§n" - italic = "§o" - gold = "§p" - emerald = "§q" - reset = "§r" - diamond = "§s" - lapis = "§t" - amethyst = "§u" + Black = "§0" + DarkBlue = "§1" + DarkGreen = "§2" + DarkAqua = "§3" + DarkRed = "§4" + DarkPurple = "§5" + Orange = "§6" + Grey = "§7" + DarkGrey = "§8" + Blue = "§9" + Green = "§a" + Aqua = "§b" + Red = "§c" + Purple = "§d" + Yellow = "§e" + White = "§f" + DarkYellow = "§g" + Quartz = "§h" + Iron = "§i" + Netherite = "§j" + Obfuscated = "§k" + Bold = "§l" + Redstone = "§m" + Copper = "§n" + Italic = "§o" + Gold = "§p" + Emerald = "§q" + Reset = "§r" + Diamond = "§s" + Lapis = "§t" + Amethyst = "§u" ) const ( @@ -72,73 +72,73 @@ const ( ) var m = map[string]string{ - black: ansiBlack, - darkBlue: ansiDarkBlue, - darkGreen: ansiDarkGreen, - darkAqua: ansiDarkAqua, - darkRed: ansiDarkRed, - darkPurple: ansiDarkPurple, - orange: ansiOrange, - grey: ansiGrey, - darkGrey: ansiDarkGrey, - blue: ansiBlue, - green: ansiGreen, - aqua: ansiAqua, - red: ansiRed, - purple: ansiPurple, - yellow: ansiYellow, - white: ansiWhite, - darkYellow: ansiDarkYellow, - quartz: ansiQuartz, - iron: ansiIron, - netherite: ansiNetherite, - redstone: ansiRedstone, - copper: ansiCopper, - gold: ansiGold, - emerald: ansiEmerald, - diamond: ansiDiamond, - lapis: ansiLapis, - amethyst: ansiAmethyst, + Black: ansiBlack, + DarkBlue: ansiDarkBlue, + DarkGreen: ansiDarkGreen, + DarkAqua: ansiDarkAqua, + DarkRed: ansiDarkRed, + DarkPurple: ansiDarkPurple, + Orange: ansiOrange, + Grey: ansiGrey, + DarkGrey: ansiDarkGrey, + Blue: ansiBlue, + Green: ansiGreen, + Aqua: ansiAqua, + Red: ansiRed, + Purple: ansiPurple, + Yellow: ansiYellow, + White: ansiWhite, + DarkYellow: ansiDarkYellow, + Quartz: ansiQuartz, + Iron: ansiIron, + Netherite: ansiNetherite, + Redstone: ansiRedstone, + Copper: ansiCopper, + Gold: ansiGold, + Emerald: ansiEmerald, + Diamond: ansiDiamond, + Lapis: ansiLapis, + Amethyst: ansiAmethyst, - obfuscated: ansiObfuscated, - bold: ansiBold, - reset: ansiReset, - italic: ansiItalic, + Obfuscated: ansiObfuscated, + Bold: ansiBold, + Reset: ansiReset, + Italic: ansiItalic, } var strMap = map[string]string{ - "black": black, - "dark-blue": darkBlue, - "dark-green": darkGreen, - "dark-aqua": darkAqua, - "dark-red": darkRed, - "dark-purple": darkPurple, - "orange": orange, - "grey": grey, - "dark-grey": darkGrey, - "blue": blue, - "green": green, - "aqua": aqua, - "red": red, - "purple": purple, - "yellow": yellow, - "white": white, - "dark-yellow": darkYellow, - "quartz": quartz, - "iron": iron, - "netherite": netherite, - "obfuscated": obfuscated, - "bold": bold, - "b": bold, - "redstone": redstone, - "copper": copper, - "gold": gold, - "emerald": emerald, - "italic": italic, - "i": italic, - "diamond": diamond, - "lapis": lapis, - "amethyst": amethyst, + "black": Black, + "dark-blue": DarkBlue, + "dark-green": DarkGreen, + "dark-aqua": DarkAqua, + "dark-red": DarkRed, + "dark-purple": DarkPurple, + "orange": Orange, + "grey": Grey, + "dark-grey": DarkGrey, + "blue": Blue, + "green": Green, + "aqua": Aqua, + "red": Red, + "purple": Purple, + "yellow": Yellow, + "white": White, + "dark-yellow": DarkYellow, + "quartz": Quartz, + "iron": Iron, + "netherite": Netherite, + "obfuscated": Obfuscated, + "bold": Bold, + "b": Bold, + "redstone": Redstone, + "copper": Copper, + "gold": Gold, + "emerald": Emerald, + "italic": Italic, + "i": Italic, + "diamond": Diamond, + "lapis": Lapis, + "amethyst": Amethyst, } // minecraftReplacer and ansiReplacer are used to translate ANSI formatting codes to Minecraft formatting