Package
ConsoleKitTerminal
ConsoleKitTerminal provides utilities for interacting with a console in a Swift application. It provides:Overview
Utilities for sending text (including styles and colors, when supported) to a terminal.
Utilities for reading input from a terminal.
ConsoleLoggerandConsoleFragmentLogger, SwiftLogLogHandlerimplementations for customizable logging to a console.
Topics
Classes
class ActivityIndicatorAn instance of aActivityIndicatorTypethat can be started, failed, and succeeded.class TerminalGeneric console that uses a mixture of Swift standard library and Foundation code to fulfill protocol requirements.
Protocols
protocol ActivityBarAnActivityIndicatorTypethat renders an activity bar on a single line.protocol ActivityIndicatorTypeActivityIndicatorTypes are responsible for drawing / rendering the currentActivityIndicatorStateto theConsole.protocol ConsoleProtocol for powering styled Console I/O.protocol LoggerFragmentA fragment of a log message.protocol TimestampSourceA protocol to allow mocking the timestamp for tests
Structures
struct AndFragmentCombine the current fragment with another, which will be written after the current fragment finishes.struct AnySendableHashableASendableversion of the standard library’sAnyHashabletype.struct ConsoleFragmentLoggerOutputs logs to aConsolevia aLoggerFragmentpipeline.struct ConsoleStyleRepresentation of a style for outputting to a Console in different colors with differing attributes. A few suggested default styles are provided.struct ConsoleTextA collection ofConsoleTextFragments. Represents stylized text that can be outputted to aConsole.struct ConsoleTextFragmentA single piece ofConsoleText. Contains a rawStringand the desiredConsoleStyle.struct CustomActivityAn activity indicator with customizable frames and success and failure messages.struct FragmentOutputThe output of aLoggerFragment, including some intermediary state used for things like deduplicating separators.struct IfMaxLevelFragmentMake the current fragment conditional, only calling itsoutputmethod if the record’sloggerLevelismaxLevelor lowerstruct LabelFragmentWrites the label of the logger, and requests a separator for the next fragment.struct LevelFragmentWrites the level of the logged message, and requests a separator for the next fragment.struct LiteralFragmentWrites the given text to the output. This type does not request a separator for the next fragmentstruct LoadingBarLoading-style implementation ofActivityBar.struct LogRecordInformation about a specific log message, including information from the logger the message was logged to.struct LoggerSourceFragmentWrites the source of the logged message. By default the source is the name of the module the message was logged in.struct MessageFragmentWrites the logged message to the output, and requests a separator for the next fragment.struct MetadataFragmentWrites the combined metadata to the output, and requests a separator for the next fragment only if the metadata was not empty.struct ProgressBarProgress-style implementation ofActivityBar.struct SeparatorFragmentstruct SourceLocationFragmentWrites the file location of the logged message, including the line. This fragment requests a separator for the next fragment.struct SystemTimestampSourceThe defaultTimestampSource, which gets the time from the system.struct TimestampFragmentWrites a formatted timestamp based on the time obtained from theTimestampSource.
Functions
func defaultLoggerFragment() -> DefaultLoggerFragmentTypeALoggerFragmentwhich implements the default logger message format.func timestampDefaultLoggerFragment(timestampSource: some TimestampSource) -> some LoggerFragmentALoggerFragmentwhich implements the default logger message format with a timestamp at the front.
Operators
func + (ConsoleText, ConsoleText) -> ConsoleTextAppends aConsoleTextto anotherConsoleText.func += (inout ConsoleText, ConsoleText)Appends aConsoleTextto anotherConsoleTextin-place.
Type Aliases
typealias ConsoleLoggerOutputs logs to aConsoleusing thedefaultLoggerFragment().typealias DefaultLoggerFragmentTypeThe complete explicit type of thedefaultLoggerFragment(). Unfortunately, we have to spell it out instead of just letting it besome LoggerFragmentin order to define theConsoleLoggeralias properly.
Enumerations
enum ActivityIndicatorStatePossible states to draw / render andActivityIndicatorType.enum ConsoleClearSupported methods for clearing theConsole.enum ConsoleColorSupported colors for creating aConsoleStyleforConsoleText.