Skip to content

Commit

Permalink
Adding Styles
Browse files Browse the repository at this point in the history
  • Loading branch information
KC-2001MS committed Jul 28, 2024
1 parent 75b5b15 commit c36aea2
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 14 deletions.
102 changes: 102 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/SwiftLI-Package.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftLI"
BuildableName = "SwiftLI"
BlueprintName = "SwiftLI"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftLITests"
BuildableName = "SwiftLITests"
BlueprintName = "SwiftLITests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
78 changes: 78 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/sclt.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "sclt"
BuildableName = "sclt"
BlueprintName = "sclt"
ReferencedContainer = "container:">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
26 changes: 23 additions & 3 deletions Sources/SwiftLI/CLI Basic Components/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct Label: View {
let title: String

let footer: Bool

let style: LabelStyle

/// Initializer to realize method chain
/// - Parameters:
Expand All @@ -23,12 +25,14 @@ public struct Label: View {
header: String,
title: String,
image: String,
footer: Bool = false
footer: Bool = false,
style: LabelStyle = .automatic
) {
self.header = "\(header)"
self.title = title
self.image = image
self.footer = footer
self.style = style
}

public init(
Expand All @@ -47,16 +51,32 @@ public struct Label: View {
self.image = image
self.title = title
self.footer = false
self.style = .automatic
}

public init(
image: String,
title: String
) {
self.header = ""
self.image = image
self.title = title
self.footer = false
self.style = .automatic
}

/// What the view displays
public var body: [any View] {
return []
return style.makeBody(configuration: LabelStyleConfiguration(icon: Text(content: image), title: Text(content: title)))
}

/// Methods for rendering text
public func render() {
print("\(header)\(image)\(title)\u{001B}[0m", terminator: footer ? "\n" : "")
Group(header: header, contents: body, footer: footer).render()
}

public func labelStyle(_ style: LabelStyle) -> Self {
return .init(header: self.header, title: self.header, image: self.image, footer: self.footer, style: style)
}

/// Modifier to adapt foreground color to existing text
Expand Down
64 changes: 64 additions & 0 deletions Sources/SwiftLI/Style/LabelStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// LabelStyle.swift
// SwiftLI
//
// Created by Keisuke Chinone on 2024/07/26.
//


public struct LabelStyleConfiguration {
var icon: View

var title: View
}

public protocol LabelStyle {
typealias Configuration = LabelStyleConfiguration

@ViewBuilder
func makeBody(configuration: Self.Configuration) -> [any View]
}

public struct DefaultLabelStyle: LabelStyle {
public func makeBody(configuration: Configuration) -> [any View] {
configuration.icon
Spacer()
configuration.title
}
}

public struct IconOnlyLabelStyle: LabelStyle {
public func makeBody(configuration: Configuration) -> [any View] {
configuration.icon
}
}

public struct TitleOnlyLabelStyle: LabelStyle {
public func makeBody(configuration: Configuration) -> [any View] {
configuration.title
}
}

public struct TitleAndIconLabelStyle: LabelStyle {
public func makeBody(configuration: Configuration) -> [any View] {
configuration.icon
Spacer()
configuration.title
}
}

public extension LabelStyle where Self == DefaultLabelStyle {
static var automatic: Self { .init() }
}

public extension LabelStyle where Self == IconOnlyLabelStyle {
static var iconOnly: Self { .init() }
}

public extension LabelStyle where Self == TitleOnlyLabelStyle {
static var titleOnly: Self { .init() }
}

public extension LabelStyle where Self == TitleAndIconLabelStyle {
static var titleAndIcon: Self { .init() }
}
7 changes: 2 additions & 5 deletions Sources/SwiftLI/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public struct Text: View, Sendable, Equatable {
self.contents = [String(repeating: repeating, count: count)]
self.footer = footer
}
/// Initializer to realize method chain
/// - Parameters:
/// - header: Hetter to specify display style
/// - contents: String to display

init(
header: String,
contents: Array<String>,
Expand All @@ -76,7 +73,7 @@ public struct Text: View, Sendable, Equatable {
}

init(
header: String,
header: String = "",
content: String,
footer: Bool = false
) {
Expand Down
8 changes: 2 additions & 6 deletions Sources/sclt/Subcommands/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ struct LabelCommand: ParsableCommand {

Group {
Group {
Text("init(_ title: String,unicodeImage: Int)")
Label("init(_ title: String,unicodeImage: Int)", unicodeImage: 0x2705)
.forgroundColor(Color.cyan)

Spacer()

Text("\"Label\",0x2705")
Text("\"init(_ title: String,unicodeImage: Int)\",0x2705")
.fontWeight(.thin)
.forgroundColor(.red)

Spacer()

Label("Label", unicodeImage: 0x2705)
}
.newLine()
}
Expand Down

0 comments on commit c36aea2

Please sign in to comment.