@@ -279,7 +279,8 @@ TBox = record
279279{ $PUSH}
280280{ $SCOPEDENUMS ON}
281281type
282- EDebugLn = (CLEAR, YELLOW, RED, GREEN, FOCUS);
282+ EDebugLn = (CLEAR, FOCUS, BACKGROUND_COLOR);
283+ EDebugLnColor = (YELLOW, RED, GREEN);
283284 EDebugLnFlags = set of EDebugLn;
284285{ $POP}
285286
@@ -291,10 +292,14 @@ procedure Debug(const Msg: String; Args: array of const); overload;
291292procedure DebugLn (const Msg: String); overload;
292293procedure DebugLn (const Msg: String; Args: array of const ); overload;
293294procedure DebugLn (const Flags: EDebugLnFlags; const Msg: String); overload;
295+ procedure DebugLn (const Flags: EDebugLnFlags; bgColor: TColor; const Msg: String); overload;
294296procedure DebugLn (const Flags: EDebugLnFlags; const Msg: String; Args: array of const ); overload;
297+ procedure DebugLn (const Flags: EDebugLnFlags; bgColor: TColor; const Msg: String; Args: array of const ); overload;
295298
296- function FlagsToString (const Flags: EDebugLnFlags): String;
297- function FlagsFromString (var Str: String): EDebugLnFlags;
299+ function GetLineColor (const color: EDebugLnColor): TColor;
300+
301+ function FlagsToString (const flags: EDebugLnFlags; const bgColor: TColor): String;
302+ function FlagsFromString (var Str: String; out bgColor: Int32): EDebugLnFlags;
298303
299304function InRange (const AValue, AMin, AMax: Integer): Boolean; inline; overload;
300305function InRange (const AValue, AMin, AMax: Int64): Boolean; inline; overload;
@@ -412,12 +417,22 @@ procedure DebugLn(const Msg: String; Args: array of const);
412417
413418procedure DebugLn (const Flags: EDebugLnFlags; const Msg: String);
414419begin
415- DebugLn(FlagsToString(Flags) + Msg);
420+ DebugLn(FlagsToString(Flags, $0 ) + Msg);
421+ end ;
422+
423+ procedure DebugLn (const Flags: EDebugLnFlags; bgColor: TColor; const Msg: String);
424+ begin
425+ DebugLn(FlagsToString(Flags, bgColor) + Msg);
416426end ;
417427
418428procedure DebugLn (const Flags: EDebugLnFlags; const Msg: String; Args: array of const );
419429begin
420- DebugLn(FlagsToString(Flags) + Format(Msg, Args));
430+ DebugLn(FlagsToString(Flags, $0 ) + Format(Msg, Args));
431+ end ;
432+
433+ procedure DebugLn (const Flags: EDebugLnFlags; bgColor: TColor; const Msg: String; Args: array of const );
434+ begin
435+ DebugLn(FlagsToString(Flags, bgColor) + Format(Msg, Args));
421436end ;
422437
423438procedure SimbaException (Message: String; Args: array of const );
@@ -430,48 +445,58 @@ procedure SimbaException(Message: String);
430445 raise ESimbaException.Create(Message);
431446end ;
432447
433- const
434- DebugLnFlagsHeader = String(#0 #0 );
435- DebugLnFlagsHeaderLength = Length(DebugLnFlagsHeader) + 6 ;
436448
437- function FlagsToString (const Flags: EDebugLnFlags): String; inline;
449+ function GetLineColor (const color: EDebugLnColor): TColor; inline;
450+ const
451+ DEBUG_LINE_COLORS: array [EDebugLnColor] of TColor = [
452+ $00BFFF, $0000A5, $228B22
453+ ];
438454begin
439- Result := DebugLnFlagsHeader + IntToHex(Integer(Flags), 6 ) ;
455+ Result := DEBUG_LINE_COLORS[color] ;
440456end ;
441457
442- function FlagsFromString (var Str: String): EDebugLnFlags;
458+ const
459+ DebugLnFlagsHeader = String(#0 #0 );
460+ DebugLnFlagsHeaderLength = Length(DebugLnFlagsHeader) + 6 ;
443461
444- function HexToInt (P: PChar): Integer; inline;
445- var
446- N, I: Integer;
447- Val: Char;
462+ function FlagsToString (const flags: EDebugLnFlags; const bgColor: TColor): String; inline;
463+ begin
464+ Result := DebugLnFlagsHeader;
465+ Result := Result + Chr(Byte(flags));
466+ if (EDebugLn.BACKGROUND_COLOR in flags) then
448467 begin
449- Result := 0 ;
450-
451- for I := 1 to 6 do
452- begin
453- Val := P^;
454- case Val of
455- ' 0' ..' 9' : N := Ord(Val) - (Ord(' 0' ));
456- ' a' ..' f' : N := Ord(Val) - (Ord(' a' ) - 10 );
457- ' A' ..' F' : N := Ord(Val) - (Ord(' A' ) - 10 );
458- else
459- Exit(0 );
460- end ;
461- Inc(P);
462-
463- Result := Result*16 +N;
464- end ;
468+ Result := Result + Chr((bgColor shr 16 ) and $FF) +
469+ Chr((bgColor shr 8 ) and $FF) +
470+ Chr(bgColor and $FF);
465471 end ;
472+ end ;
466473
474+ function FlagsFromString (var str: String; out bgColor: Int32): EDebugLnFlags;
475+ var
476+ flagsByte: Byte;
477+ idx: Integer;
467478begin
479+ Result := [];
468480 if (Length(Str) >= DebugLnFlagsHeaderLength) and (Str[1 ] = DebugLnFlagsHeader[1 ]) and (Str[2 ] = DebugLnFlagsHeader[2 ]) then
469481 begin
470- Result := EDebugLnFlags(HexToInt(@Str[3 ]));
482+ flagsByte := Ord(str[3 ]);
483+ if (flagsByte and 1 <> 0 ) then Include(Result, EDebugLn.CLEAR);
484+ if (flagsByte and 2 <> 0 ) then Include(Result, EDebugLn.FOCUS);
485+ if (flagsByte and 4 <> 0 ) then Include(Result, EDebugLn.BACKGROUND_COLOR);
486+ // if (flagsByte and 8 <> 0) then Include(Result, EDebugLn.TEXT_COLOR);
487+ // maybe in the future... would like multi color support per line
488+
489+ idx := 4 ;
490+ if EDebugLn.BACKGROUND_COLOR in Result then
491+ begin
492+ bgColor := (Ord(Str[idx]) shl 16 ) or (Ord(str[idx+1 ]) shl 8 ) or Ord(str[idx+2 ]);
493+ Inc(idx, 3 );
494+ end
495+ else
496+ bgColor := $0 ;
471497
472- Delete(Str, 1 , DebugLnFlagsHeaderLength);
473- end else
474- Result := [];
498+ Delete(str, 1 , DebugLnFlagsHeaderLength);
499+ end ;
475500end ;
476501
477502function InRange (const AValue, AMin, AMax: Integer): Boolean;
0 commit comments