22from rich .console import Console as RichConsole
33from typing import Dict , Optional
44
5- def RemoveDirectives (Text : str ):return RegexLibrary .sub (r"\{\{.*?\}\}" , "" , Text )
5+ def RemoveDirectives (Text : str ):
6+ return RegexLibrary .sub (r"<:.*?:>" , "" , Text )
67
78def EnsureResetEnding (Line ):
8- if not Line .endswith ("{{ reset}} " ):
9- return Line + "{{ reset}} "
10- return Line
9+ if not Line .endswith ("<: reset:> " ):
10+ return Line + "<: reset:> "
11+ return Line
1112
12- class MeowfetchColourFormatter :
13+ class FancyfetchColourFormatter :
1314 def __init__ (self , CustomColours : Optional [Dict [str , str ]] = None ):
1415 self .Console = RichConsole (highlight = False )
1516
@@ -47,7 +48,7 @@ def __init__(self, CustomColours: Optional[Dict[str, str]] = None):
4748 if CustomColours :
4849 self .ColourMap .update (CustomColours )
4950
50- self .TagPattern = RegexLibrary .compile (r"\{\{ ([^} ]+)\}\} " )
51+ self .TagPattern = RegexLibrary .compile (r"<: ([^: ]+):> " )
5152
5253 def AddColour (self , Name : str , HexCode : str ):
5354 self .ColourMap [Name .lower ()] = HexCode
@@ -148,21 +149,24 @@ def GetAvailableStyles(self) -> Dict[str, str]:
148149def FormatASCII (Lines , TargetLength :int | None = None ):
149150 def ExtractVisibleText (Line ):
150151 VisibleChars = []
151- InDirective = False
152- BraceCount = 0
152+ I = 0
153153
154- for I , Char in enumerate (Line ):
155- if Char == "{" and I + 1 < len (Line ) and Line [I + 1 ] == "{" :
156- InDirective = True
157- BraceCount = 1
158- elif Char == "{" and InDirective :
159- BraceCount += 1
160- elif Char == "}" and InDirective :
161- BraceCount -= 1
162- if BraceCount == 0 :
163- InDirective = False
164- elif not InDirective :
165- VisibleChars .append ((Char , I ))
154+ while I < len (Line ):
155+ # Check for start of directive <:
156+ if I + 1 < len (Line ) and Line [I :I + 2 ] == "<:" :
157+ # Find the end of directive :>
158+ EndPos = Line .find (":>" , I + 2 )
159+ if EndPos != - 1 :
160+ # Skip the entire directive including :>
161+ I = EndPos + 2
162+ else :
163+ # Malformed directive, treat as visible character
164+ VisibleChars .append ((Line [I ], I ))
165+ I += 1
166+ else :
167+ # Regular visible character
168+ VisibleChars .append ((Line [I ], I ))
169+ I += 1
166170
167171 return VisibleChars
168172
@@ -185,29 +189,30 @@ def TruncateToTarget(Line, TargetLen):
185189 CutoffPos = VisibleChars [TargetLen - 1 ][1 ] + 1
186190
187191 Result = []
188- InDirective = False
189- BraceCount = 0
192+ I = 0
190193
191- for I , Char in enumerate (Line ):
192- if I >= CutoffPos and not InDirective :
193- break
194-
195- Result .append (Char )
196-
197- if Char == "{" and I + 1 < len (Line ) and Line [I + 1 ] == "{" :
198- InDirective = True
199- BraceCount = 1
200- elif Char == "{" and InDirective :
201- BraceCount += 1
202- elif Char == "}" and InDirective :
203- BraceCount -= 1
204- if BraceCount == 0 :
205- InDirective = False
194+ while I < len (Line ):
195+ if I >= CutoffPos :
196+ # Check if we're in the middle of a directive
197+ if I + 1 < len (Line ) and Line [I :I + 2 ] == "<:" :
198+ # Find the end of this directive and include it
199+ EndPos = Line .find (":>" , I + 2 )
200+ if EndPos != - 1 :
201+ # Include the complete directive
202+ Result .extend (Line [I :EndPos + 2 ])
203+ I = EndPos + 2
204+ else :
205+ break
206+ else :
207+ break
208+ else :
209+ Result .append (Line [I ])
210+ I += 1
206211
207212 ResultStr = "" .join (Result )
208213
209- if not ResultStr .endswith ("{{ reset}} " ):
210- ResultStr += "{{ reset}} "
214+ if not ResultStr .endswith ("<: reset:> " ):
215+ ResultStr += "<: reset:> "
211216
212217 return ResultStr
213218
@@ -227,9 +232,9 @@ def TruncateToTarget(Line, TargetLen):
227232 for Line in ProcessedLines :
228233 VisibleLength = GetVisibleLength (Line )
229234 if VisibleLength < MaxVisibleLength :
230- if Line .endswith ("{{ reset}} " ):
235+ if Line .endswith ("<: reset:> " ):
231236 SpacesNeeded = MaxVisibleLength - VisibleLength
232- AlignedLine = Line [:- 9 ] + " " * SpacesNeeded + "{{ reset}} "
237+ AlignedLine = Line [:- 10 ] + " " * SpacesNeeded + "<: reset:> "
233238 else :
234239 SpacesNeeded = MaxVisibleLength - VisibleLength
235240 AlignedLine = Line + " " * SpacesNeeded
0 commit comments