@@ -15,9 +15,9 @@ import Foundation
1515 - [The 8-bits colors table (direct image link)](<https://i.stack.imgur.com/KTSQa.png>);
1616 - [List of Terminals supporting True Colors](<https://gist.github.com/XVilka/8346728>);
1717 - [The ODA Specs](<https://en.wikipedia.org/wiki/Open_Document_Architecture#External_links>) aka. CCITT T.411-T.424 (equivalent to ISO 8613, but freely downloadable). */
18- public struct SGR : RawRepresentable , Hashable , CustomStringConvertible {
18+ public struct SGR : RawRepresentable , Hashable , CustomStringConvertible , CLTLogger_Sendable {
1919
20- public enum Modifier : RawRepresentable , Hashable , CustomStringConvertible {
20+ public enum Modifier : RawRepresentable , Hashable , CustomStringConvertible , CLTLogger_Sendable {
2121
2222 /** Reset/Normal -- All attributes off. */
2323 case reset
@@ -303,7 +303,7 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
303303 Not standard (equivalent to `.bgColorTo4BitWhite` + `.bold` + `.reverseVideo` IIUC). */
304304 case bgColorTo4BitBrightWhite
305305
306- public struct ColorSpaceInfo {
306+ public struct ColorSpaceInfo : Hashable , CLTLogger_Sendable {
307307
308308 /**
309309 - Note: I did not know the type for this one, so I assumed `Int`. */
@@ -315,7 +315,7 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
315315 public var colorSpaceToleranceAsString : String ? { colorSpaceTolerance. flatMap { " \( $0) " } }
316316 public var colorSpaceAssociatedWithToleranceAsString : String ? { colorSpaceAssociatedWithTolerance. flatMap { " \( $0. rawValue) " } }
317317
318- public enum ColorSpaceForTolerance : Int {
318+ public enum ColorSpaceForTolerance : Int , Hashable , CLTLogger_Sendable {
319319 case cieluv = 0
320320 case cielab = 1
321321 }
@@ -454,19 +454,19 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
454454 /* Note: This init probably has terrible perfs. */
455455 init ? ( scanner: Scanner ) {
456456 struct DummyError : Error { }
457- let originalScannerIndex = scanner. currentIndex
457+ let originalScanLocation = scanner. compatibleScanLocation
458458 do {
459459 enum ColorDestination : String {
460460 case fg = " 38 "
461461 case bg = " 48 "
462462 case ul = " 58 "
463463 }
464- let token = scanner. scanUpToCharacters ( from: CharacterSet ( charactersIn: String ( Self . separatorChar) + String( SGR . sgrEndChar) ) ) ?? " "
464+ let token = scanner. xl_scanUpToCharacters ( from: CharacterSet ( charactersIn: String ( Self . separatorChar) + String( SGR . sgrEndChar) ) ) ?? " "
465465 if token. contains ( " : " ) {
466466 /* Let’s process the special ODA cases. */
467467 let subScanner = Scanner ( forParsing: token)
468- let subToken = subScanner. scanUpToString ( " : " ) ?? " "
469- _ = subScanner. scanString ( " : " ) ! /* !: The string contains a colon, so the scan cannot fail. */
468+ let subToken = subScanner. xl_scanUpToString ( " : " ) ?? " "
469+ _ = subScanner. xl_scanString ( " : " ) ! /* !: The string contains a colon, so the scan cannot fail. */
470470
471471 let isFgColor : Bool
472472 switch subToken {
@@ -477,7 +477,7 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
477477 * Note however, it might be possible to get the 58 case too (underline color), though because it is not part of the ODA it shouldn’t be valid with this notation. */
478478 throw DummyError ( )
479479 }
480- let colorFormat = subScanner. scanUpToString ( " : " ) ?? " "
480+ let colorFormat = subScanner. xl_scanUpToString ( " : " ) ?? " "
481481 switch colorFormat {
482482 case " 0 " , " " :
483483 guard isFgColor, subScanner. isAtEnd else {
@@ -499,10 +499,10 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
499499 func scanParam( ) throws -> Int ? {
500500 if subScanner. isAtEnd { return nil }
501501 else {
502- guard subScanner. scanString ( " : " ) != nil else {
502+ guard subScanner. xl_scanString ( " : " ) != nil else {
503503 throw DummyError ( )
504504 }
505- guard let str = subScanner. scanUpToString ( " : " ) else {
505+ guard let str = subScanner. xl_scanUpToString ( " : " ) else {
506506 return nil
507507 }
508508 /* We assume “+1” is a valid value. */
@@ -579,9 +579,9 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
579579 }
580580 if let colorDestination = ColorDestination ( rawValue: token) {
581581 guard
582- scanner. scanCharacter ( ) == Self . separatorChar,
583- let colorType = scanner. scanCharacter ( ) ,
584- scanner. scanCharacter ( ) == Self . separatorChar
582+ scanner. xl_scanCharacter ( ) == Self . separatorChar,
583+ let colorType = scanner. xl_scanCharacter ( ) ,
584+ scanner. xl_scanCharacter ( ) == Self . separatorChar
585585 else {
586586 throw DummyError ( )
587587 }
@@ -600,19 +600,19 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
600600 /* Wikipedia says empty values are treated as 0.
601601 * But Terminal for instance does not seem to know that.
602602 * We don’t care, we do like Wikipedia says. */
603- let r = try uint8 ( scanner. scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
604- guard scanner. scanCharacter ( ) == Self . separatorChar else { throw DummyError ( ) }
605- let g = try uint8 ( scanner. scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
606- guard scanner. scanCharacter ( ) == Self . separatorChar else { throw DummyError ( ) }
607- let b = try uint8 ( scanner. scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
603+ let r = try uint8 ( scanner. xl_scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
604+ guard scanner. xl_scanCharacter ( ) == Self . separatorChar else { throw DummyError ( ) }
605+ let g = try uint8 ( scanner. xl_scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
606+ guard scanner. xl_scanCharacter ( ) == Self . separatorChar else { throw DummyError ( ) }
607+ let b = try uint8 ( scanner. xl_scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
608608 switch colorDestination {
609609 case . fg: self = . fgColorToRGB( red: r, green: g, blue: b) ; return
610610 case . bg: self = . bgColorToRGB( red: r, green: g, blue: b) ; return
611611 case . ul: self = . underlineColorToRGB( red: r, green: g, blue: b) ; return
612612 }
613613
614614 case " 5 " :
615- let v = try uint8 ( scanner. scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
615+ let v = try uint8 ( scanner. xl_scanUpToString ( String ( Self . separatorChar) ) ?? " 0 " )
616616 switch colorDestination {
617617 case . fg: self = . fgColorTo256PaletteValue( v) ; return
618618 case . bg: self = . bgColorTo256PaletteValue( v) ; return
@@ -707,7 +707,7 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
707707 default : throw DummyError ( )
708708 }
709709 } catch {
710- scanner. currentIndex = originalScannerIndex
710+ scanner. compatibleScanLocation = originalScanLocation
711711 return nil
712712 }
713713 }
@@ -756,18 +756,18 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
756756 /* For symetry w/ SGR.Modifier init, but not really needed, at least for now. */
757757 init ? ( scanner: Scanner ) {
758758 struct DummyError : Error { }
759- let originalScannerIndex = scanner. currentIndex
759+ let originalScanLocation = scanner. compatibleScanLocation
760760 do {
761761 guard
762- scanner. scanCharacter ( ) == Self . escapeChar,
763- scanner. scanCharacter ( ) == Self . csiChar
762+ scanner. xl_scanCharacter ( ) == Self . escapeChar,
763+ scanner. xl_scanCharacter ( ) == Self . csiChar
764764 else {
765765 /* Not a CSI. */
766766 throw DummyError ( )
767767 }
768768
769- let csiContent = scanner. scanUpToCharacters ( from: Self . possibleFinalByte) ?? " "
770- guard scanner. scanCharacter ( ) == Self . sgrEndChar else {
769+ let csiContent = scanner. xl_scanUpToCharacters ( from: Self . possibleFinalByte) ?? " "
770+ guard scanner. xl_scanCharacter ( ) == Self . sgrEndChar else {
771771 /* Not an SGR. */
772772 throw DummyError ( )
773773 }
@@ -781,15 +781,15 @@ public struct SGR : RawRepresentable, Hashable, CustomStringConvertible {
781781 /* A modifier has been parsed.
782782 * Either scan location is now at a semicolon or at the end.
783783 * If on semicolon we must consume it. */
784- let c = contentScanner. scanCharacter ( )
784+ let c = contentScanner. xl_scanCharacter ( )
785785 assert ( c == Modifier . separatorChar)
786786 }
787787 guard contentScanner. isAtEnd else {
788788 /* Not all modifiers parsed in the content. */
789789 throw DummyError ( )
790790 }
791791 } catch {
792- scanner. currentIndex = originalScannerIndex
792+ scanner. compatibleScanLocation = originalScanLocation
793793 return nil
794794 }
795795 }
0 commit comments