diff --git a/APPROBATION.md b/APPROBATION.md index 3c7db99..06a35c4 100644 --- a/APPROBATION.md +++ b/APPROBATION.md @@ -1,4 +1,4 @@ -# Approbation Matrix / PerseusDarkMode 2.0.0 && 2.0.1 && 2.0.2 && 2.0.3 && 2.0.4 && 2.1.0 +# Approbation Matrix / PerseusDarkMode 2.0.0 && 2.0.1 && 2.0.2 && 2.0.3 && 2.0.4 && 2.1.0 && 2.1.1 > NOTE: To catch all log messages Mac Console should be started first then after a little while the logged app. diff --git a/CHANGELOG.md b/CHANGELOG.md index 83176a8..404e20c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Dates in this file meets Gregorian calendar. Date in format YYYY-MM-DD. +## [2.1.1] - [2025-11-30], PerseusDarkMode + +### Updated + +- CPL dependency to v1.7.0. + ## [2.1.0] - [2025-10-30], PerseusDarkMode ### Added diff --git a/PDMStar.swift b/PDMStar.swift index 0ba552d..c46a956 100644 --- a/PDMStar.swift +++ b/PDMStar.swift @@ -1,6 +1,6 @@ // // PDMStar.swift -// Version: 2.1.0 +// Version: 2.1.1 // // Standalone PerseusDarkMode. // @@ -23,7 +23,7 @@ // Copyright © 7533 - 7534 PerseusRealDeal // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/PDMSupportingStar.swift b/PDMSupportingStar.swift index 11ec0e7..9ddc8e1 100644 --- a/PDMSupportingStar.swift +++ b/PDMSupportingStar.swift @@ -1,6 +1,6 @@ // // PDMSupportingStar.swift -// Version: 2.1.0 +// Version: 2.1.1 // // The Darkness Support (PerseusUISystemKit previously) // @@ -10,7 +10,7 @@ // Created by Mikhail Zhigulin of Novosibirsk in 7530. // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // // Unlicensed Free Software diff --git a/Package.swift b/Package.swift index a66cb4a..b651ae7 100644 --- a/Package.swift +++ b/Package.swift @@ -1,7 +1,7 @@ // swift-tools-version:5.7 /* Package.swift - Version: 2.1.0 + Version: 2.1.1 For iOS and macOS only. Use Stars to adopt for the specifics you need. diff --git a/README.md b/README.md index 66c0337..ec0eb5f 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ [![Actions Status](https://github.com/perseusrealdeal/PerseusDarkMode/actions/workflows/main.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusDarkMode/actions/workflows/main.yml) [![Style](https://github.com/perseusrealdeal/PerseusDarkMode/actions/workflows/swiftlint.yml/badge.svg)](https://github.com/perseusrealdeal/PerseusDarkMode/actions/workflows/swiftlint.yml) -[![Version](https://img.shields.io/badge/Version-2.1.0-green.svg)](/CHANGELOG.md) +[![Version](https://img.shields.io/badge/Version-2.1.1-green.svg)](/CHANGELOG.md) [![Platforms](https://img.shields.io/badge/Platforms-macOS%2010.13+_|_iOS%2011.0+-orange.svg)](https://en.wikipedia.org/wiki/List_of_Apple_products) [![Xcode 14.2](https://img.shields.io/badge/Xcode-14.2+-red.svg)](https://en.wikipedia.org/wiki/Xcode) [![Swift 5.7](https://img.shields.io/badge/Swift-5.7-red.svg)](https://www.swift.org) [![License](http://img.shields.io/:License-MIT-blue.svg)](/LICENSE) -> Home-made product. The light-weight darkness in Swift you can force. +> This is the great home-made product in Swift to accomplish `Dark Mode switching` task. -> `1:` Build option kinda `Night/Day/System Mode` or `On/Off/System Dark Mode`.
-> `2:` Be awared of Dark Mode changes if you need. +> `1:` Build option kinda `Light/Dark/System Appearance` or `On/Off/System Dark Mode`.
+> `2:` Be awared of Dark Mode changes. > `PDM` is a single author and personale solution developed in `P2P` relationship paradigm. @@ -22,7 +22,7 @@ ## Dependencies -[![ConsolePerseusLogger](http://img.shields.io/:ConsolePerseusLogger-1.6.0-green.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger.git) +[![ConsolePerseusLogger](http://img.shields.io/:ConsolePerseusLogger-1.7.0-green.svg)](https://github.com/perseusrealdeal/ConsolePerseusLogger.git) ## Support Code @@ -44,7 +44,7 @@ ## PDM in Use > `In approbation:` [`iOS app`](https://github.com/perseusrealdeal/TheOneRing) [`macOS app`](https://github.com/perseusrealdeal/Arkenstone)
-> `In business:` [`The Dark Moon`](https://github.com/perseusrealdeal/TheDarkMoon) +> `In business:` [`The Dark Moon`](https://github.com/perseusrealdeal/TheDarkMoon) [`Convertor mov2gif`](https://github.com/perseusrealdeal/mov2gif) > `For details:` [`Approbation and A3 Environment`](/APPROBATION.md) / [`CHANGELOG`](/CHANGELOG.md)
@@ -62,8 +62,8 @@ * [Get awared of DarkMode changes](#Get-awared-of-DarkMode-changes) * [DarkMode change sample](#DarkMode-change-sample) * [Points taken into account](#Points-taken-into-account) -* [License MIT](#License-MIT) - * [Other Required License Notices](#Other-Required-License-Notices) +* [License](#License) + * [Other required license notices](#Other-required-license-notices) * [Credits](#Credits) * [Author](#Author) @@ -100,7 +100,7 @@ | Type | Name | License | | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| Star | [ConsolePerseusLogger](https://github.com/perseusrealdeal/ConsolePerseusLogger) / [1.6.0](https://github.com/perseusrealdeal/ConsolePerseusLogger/releases/tag/1.6.0) | MIT | +| Star | [ConsolePerseusLogger](https://github.com/perseusrealdeal/ConsolePerseusLogger) / [1.7.0](https://github.com/perseusrealdeal/ConsolePerseusLogger/releases/tag/1.7.0) | MIT | # Third-party software @@ -355,15 +355,17 @@ extension Color { - Preconfigured GitHub config [.gitignore](/.gitignore) - Preconfigured GitHub CI [main.yml](/.github/workflows/main.yml) -# License MIT +# License + +`License:` MIT Copyright © 7530 - 7534 Mikhail A. Zhigulin of Novosibirsk
Copyright © 7533 - 7534 PerseusRealDeal - The year starts from the creation of the world according to a Slavic calendar. -- September, the 1st of Slavic year. It means that "Sep 01, 2024" is the beginning of 7533. +- September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. -## Other Required License Notices +## Other required license notices © 2025 The SwiftLint Contributors **for** SwiftLint
© GitHub **for** GitHub Action cirruslabs/swiftlint-action@v1
@@ -377,22 +379,22 @@ Copyright © 7533 - 7534 PerseusRealDeal Balance and Control kept by - Mikhail A. Zhigulin + Mikhail Zhigulin Source Code written by - Mikhail A. Zhigulin + Mikhail Zhigulin Documentation prepared by - Mikhail A. Zhigulin + Mikhail Zhigulin Product Approbation tested by - Mikhail A. Zhigulin + Mikhail Zhigulin diff --git a/Sources/PerseusDarkMode/CPLStar.swift b/Sources/PerseusDarkMode/CPLStar.swift index 9bb6c61..26ddbb1 100644 --- a/Sources/PerseusDarkMode/CPLStar.swift +++ b/Sources/PerseusDarkMode/CPLStar.swift @@ -1,6 +1,6 @@ // // CPLStar.swift -// Version: 1.6.0 +// Version: 1.7.0 // // Standalone ConsolePerseusLogger. // @@ -27,7 +27,7 @@ // Copyright © 7531 - 7534 PerseusRealDeal // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -62,6 +62,63 @@ protocol PerseusDelegatedMessage: AnyObject { var message: String { get set } } +public struct LogMessage { + + public let text: String + public let level: PerseusLogger.Level + public let localTime: PerseusLogger.LocalTime + public let owner: PerseusLogger.PIDandTID + public let user: PerseusLogger.User + public let fileline: PerseusLogger.Directives + + public func getMessage(mode: PerseusLogger.LineMode = .singleLine) -> String { + + var tags = "" + + // Type. + + let isTyped = + (log.format == .full) ? true : log.marks && (log.format != .textonly) + + tags = isTyped ? "\(level.tag)" : tags + + // Time. + + let isTimed = + (log.format == .full) ? true : log.marks && log.time && (log.format != .textonly) + + if isTimed { + let tag = "[\(localTime.date)] [\(localTime.time)]" + tags = tags.isEmpty ? "\(tag)" : "\(tags) \(tag)" + } + + // PID and TID. + + let withOwnerId = + (log.format == .full) ? true : log.owner && (log.format != .textonly) + + if withOwnerId { + let tag = "[\(owner.pid):\(owner.tid)]" + tags = tags.isEmpty ? "\(tag)" : "\(tags) \(tag)" + } + + // Path. + + let withPath = + (log.format == .full) ? true : log.directives && (log.format != .textonly) + + let messageText = + withPath ? "\(text), file: \(fileline.fileName), line: \(fileline.line)" : "\(text)" + + switch mode { + case .singleLine: + return tags.isEmpty ? "\(messageText)" : "\(tags) \(messageText)" + case .multiLine: + return tags.isEmpty ? "\(messageText)" : "\(tags)\r\n\(messageText)" + } + } +} + public class PerseusLogger { // MARK: - Typealiases @@ -71,9 +128,7 @@ public class PerseusLogger { public typealias PIDandTID = (pid: String, tid: String) // PID and Thread ID. public typealias Directives = (fileName: String, line: UInt) // #file and #line. - public typealias MessageDelegate = ( - (String, Level, LocalTime, PIDandTID, User, Directives) -> Void - ) + public typealias MessageDelegate = ((_ instance: LogMessage) -> Void) // MARK: - Constants @@ -90,7 +145,7 @@ public class PerseusLogger { public enum Output: String, Decodable, CaseIterable { case standard // In Use: Swift.print(""). case consoleapp // In Use: Logger structure from iOS 14.0, macOS 11.0, NSLog otherwise. - case custom // In Use: customActionOnMessage?(_:_:_:_:_:_:). + case custom // In Use: customActionOnMessage?(_:). } // log.message("Notification...", .notice, .custom, .enduser) @@ -187,6 +242,11 @@ public class PerseusLogger { // message } + public enum LineMode { + case singleLine + case multiLine + } + // MARK: - Properties public static var customActionOnMessage: PerseusLogger.MessageDelegate? @@ -207,6 +267,7 @@ public class PerseusLogger { // MARK: - Message Details Visibility Flags public static var format = MessageFormat.short + public static var linemode = LineMode.singleLine // [TYPE] [DATE] [TIME] [PID:TID] message, file: #, line: # public static var marks = true // [TYPE] @@ -270,52 +331,32 @@ public class PerseusLogger { return } - var message = "" - - // Path. + // Get message details. - let withDirectives = (format == .full) ? true : directives && (format != .textonly) - let fileName = (file.description as NSString).lastPathComponent - - if withDirectives { - message = "\(text()), file: \(fileName), line: \(line)" - } else { - message = "\(text())" - } - - // PID and TID. - - let withOwnerId = (format == .full) ? true : owner && (format != .textonly) - let idTuple = getPIDandTID() - - if withOwnerId { - message = "[\(idTuple.pid):\(idTuple.tid)] \(message)" - } - - // Time. - - let isTimed = (format == .full) ? true : marks && time && (format != .textonly) - let localTime = getLocalTime() - - if isTimed { - message = "[\(localTime.date)] [\(localTime.time)] \(message)" - } - - // Type. - - let isTyped = (format == .full) ? true : marks && (format != .textonly) - message = isTyped ? "\(type.tag) \(message)" : message + let details = LogMessage( + text: text(), + level: type, + localTime: getLocalTime(), + owner: getPIDandTID(), + user: user, + fileline: (fileName: (file.description as NSString).lastPathComponent, line: line) + ) // Print. if oput == .custom { - let directives: Directives = (fileName: fileName, line: line) - customActionOnMessage?(message, type, localTime, idTuple, user, directives) + customActionOnMessage?(details) } else { - print(message, type, oput) + print(details, type, oput) } } +} + +// MARK: - Contract for CPL json config profile + +extension PerseusLogger { + public static func loadConfig(_ profile: ProfileCPL) -> Bool { if let data = profile.json.data(using: .utf8) { if let jsonConfig = decodeJsonProfile(data) { @@ -345,12 +386,16 @@ public class PerseusLogger { log.message("CPL config file doesn't exist!", .error) return false } +} + +// MARK: - Implementation - // MARK: - Implementation +extension PerseusLogger { // swiftlint:disable:next cyclomatic_complexity - private static func print(_ text: String, _ type: Level, _ output: Output) { + private static func print(_ instance: LogMessage, _ type: Level, _ output: Output) { + let text = instance.getMessage(mode: log.linemode) let message = (text: text, type: type) if output == .standard { @@ -663,6 +708,11 @@ extension PerseusLogger { } public var text: String { report } + public var linemode: LineMode = .singleLine { + didSet { + removeMessages() + } + } // MARK: - Constants @@ -684,35 +734,32 @@ extension PerseusLogger { // MARK: - Contract - // swiftlint:disable:next function_parameter_count - public func report(_ text: String, - _ type: Level, - _ localTime: LocalTime, - _ owner: PIDandTID, - _ user: User, - _ dirs: Directives) { + public func report(_ instance: LogMessage) { - let text = text.replacingOccurrences(of: "\(type.tag) ", with: "") - lastMessage = "[\(localTime.date)] [\(localTime.time)] \(type.tag)\r\n\(text)" + lastMessage = instance.getMessage(mode: self.linemode) - if user == .enduser { - delegate?.message = text + if instance.user == .enduser { + delegate?.message = instance.text } } public func clear() { - report = "" + removeMessages() } // MARK: - Realization + private func removeMessages() { + report = "" + } + private func resizeReportIfNeeded() { let lmCount = lastMessage.count let nlCount = newLine.count // Can the last message be reported? - guard lmCount != 0, lmCount < limit else { + guard lmCount != 0, lmCount <= limit else { return } @@ -724,7 +771,7 @@ extension PerseusLogger { // What length to remove? let messages = report.components(separatedBy: newLine) - let messagesCount = messages.count - 1 + let messagesCount = messages.count var lengthToRemove = 0 var itemCount = 0 @@ -732,11 +779,11 @@ extension PerseusLogger { for item in messages { itemCount += 1 - let newLineLength = messagesCount == 0 ? 0 : nlCount + let newLineLength = messagesCount == 1 ? 0 : nlCount lengthToRemove += (item.count + newLineLength) - if itemCount == messagesCount, messagesCount > 2 { + if itemCount == messagesCount, messagesCount >= 2 { lengthToRemove -= nlCount // There's no new line in the report end } @@ -760,7 +807,7 @@ extension PerseusLogger { private func appendLastMessageToReport() { - guard lastMessage.isEmpty == false, lastMessage.count < limit else { + guard lastMessage.isEmpty == false, lastMessage.count <= limit else { return } diff --git a/Sources/PerseusDarkMode/TheDarkness.swift b/Sources/PerseusDarkMode/TheDarkness.swift index 32b18e2..55ab2a7 100644 --- a/Sources/PerseusDarkMode/TheDarkness.swift +++ b/Sources/PerseusDarkMode/TheDarkness.swift @@ -21,7 +21,7 @@ // Copyright © 7533 - 7534 PerseusRealDeal // // The year starts from the creation of the world according to a Slavic calendar. -// September, the 1st of Slavic year. +// September, the 1st of Slavic year. It means that "Sep 01, 2025" is the beginning of 7534. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal