Skip to content

Commit b09ca26

Browse files
committed
Make detecting support for color and LineReader support uniform. Use shared schemes in Xcode.
1 parent ae2b7a8 commit b09ca26

File tree

5 files changed

+212
-7
lines changed

5 files changed

+212
-7
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0930"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "CCFC2AD2207A636B00EDDADD"
18+
BuildableName = "CommandLineKit.framework"
19+
BlueprintName = "CommandLineKit"
20+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "CCFC2AEB207A69B900EDDADD"
36+
BuildableName = "CommandLineKitTests.xctest"
37+
BlueprintName = "CommandLineKitTests"
38+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "CCFC2AD2207A636B00EDDADD"
46+
BuildableName = "CommandLineKit.framework"
47+
BlueprintName = "CommandLineKit"
48+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
53+
</TestAction>
54+
<LaunchAction
55+
buildConfiguration = "Debug"
56+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
57+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
58+
launchStyle = "0"
59+
useCustomWorkingDirectory = "NO"
60+
ignoresPersistentStateOnLaunch = "NO"
61+
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
63+
allowLocationSimulation = "YES">
64+
<MacroExpansion>
65+
<BuildableReference
66+
BuildableIdentifier = "primary"
67+
BlueprintIdentifier = "CCFC2AD2207A636B00EDDADD"
68+
BuildableName = "CommandLineKit.framework"
69+
BlueprintName = "CommandLineKit"
70+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
71+
</BuildableReference>
72+
</MacroExpansion>
73+
<AdditionalOptions>
74+
</AdditionalOptions>
75+
</LaunchAction>
76+
<ProfileAction
77+
buildConfiguration = "Release"
78+
shouldUseLaunchSchemeArgsEnv = "YES"
79+
savedToolIdentifier = ""
80+
useCustomWorkingDirectory = "NO"
81+
debugDocumentVersioning = "YES">
82+
<MacroExpansion>
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "CCFC2AD2207A636B00EDDADD"
86+
BuildableName = "CommandLineKit.framework"
87+
BlueprintName = "CommandLineKit"
88+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
89+
</BuildableReference>
90+
</MacroExpansion>
91+
</ProfileAction>
92+
<AnalyzeAction
93+
buildConfiguration = "Debug">
94+
</AnalyzeAction>
95+
<ArchiveAction
96+
buildConfiguration = "Release"
97+
revealArchiveInOrganizer = "YES">
98+
</ArchiveAction>
99+
</Scheme>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0930"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "CC7A60E6207A62A5007376A0"
18+
BuildableName = "CommandLineKitDemo.app"
19+
BlueprintName = "CommandLineKitDemo"
20+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "CC7A60E6207A62A5007376A0"
36+
BuildableName = "CommandLineKitDemo.app"
37+
BlueprintName = "CommandLineKitDemo"
38+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
<AdditionalOptions>
42+
</AdditionalOptions>
43+
</TestAction>
44+
<LaunchAction
45+
buildConfiguration = "Debug"
46+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+
launchStyle = "0"
49+
useCustomWorkingDirectory = "NO"
50+
ignoresPersistentStateOnLaunch = "NO"
51+
debugDocumentVersioning = "YES"
52+
debugServiceExtension = "internal"
53+
allowLocationSimulation = "YES">
54+
<BuildableProductRunnable
55+
runnableDebuggingMode = "0">
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "CC7A60E6207A62A5007376A0"
59+
BuildableName = "CommandLineKitDemo.app"
60+
BlueprintName = "CommandLineKitDemo"
61+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
62+
</BuildableReference>
63+
</BuildableProductRunnable>
64+
<EnvironmentVariables>
65+
<EnvironmentVariable
66+
key = "TERM"
67+
value = "xcode"
68+
isEnabled = "YES">
69+
</EnvironmentVariable>
70+
</EnvironmentVariables>
71+
<AdditionalOptions>
72+
</AdditionalOptions>
73+
</LaunchAction>
74+
<ProfileAction
75+
buildConfiguration = "Release"
76+
shouldUseLaunchSchemeArgsEnv = "YES"
77+
savedToolIdentifier = ""
78+
useCustomWorkingDirectory = "NO"
79+
debugDocumentVersioning = "YES">
80+
<BuildableProductRunnable
81+
runnableDebuggingMode = "0">
82+
<BuildableReference
83+
BuildableIdentifier = "primary"
84+
BlueprintIdentifier = "CC7A60E6207A62A5007376A0"
85+
BuildableName = "CommandLineKitDemo.app"
86+
BlueprintName = "CommandLineKitDemo"
87+
ReferencedContainer = "container:CommandLineKit.xcodeproj">
88+
</BuildableReference>
89+
</BuildableProductRunnable>
90+
</ProfileAction>
91+
<AnalyzeAction
92+
buildConfiguration = "Debug">
93+
</AnalyzeAction>
94+
<ArchiveAction
95+
buildConfiguration = "Release"
96+
revealArchiveInOrganizer = "YES">
97+
</ArchiveAction>
98+
</Scheme>

Sources/CommandLineKit/LineReader.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ public class LineReader {
8181
if isatty(inputFile) != 1 {
8282
return nil
8383
} else {
84-
self.termSupported = LineReader.readerSupport(termVar: self.currentTerm)
84+
self.termSupported = LineReader.supportedBy(terminal: self.currentTerm)
8585
}
86-
self.fullColorSupport = Terminal.fullColorSupport(termVar: self.currentTerm)
86+
self.fullColorSupport = Terminal.fullColorSupport(terminal: self.currentTerm)
8787
self.history = LineReaderHistory()
8888
self.completionCallback = completionCallback
8989
self.hintsCallback = hintsCallback
9090
}
9191

92-
private static func readerSupport(termVar: String) -> Bool {
93-
switch termVar {
92+
public static var supportedByTerminal: Bool {
93+
return LineReader.supportedBy(terminal: Terminal.current)
94+
}
95+
96+
public static func supportedBy(terminal: String) -> Bool {
97+
switch terminal {
9498
case "", "xcode", "dumb", "cons25", "emacs":
9599
return false
96100
default:

Sources/CommandLineKit/Terminal.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public struct Terminal {
4141
public static let current: String = ProcessInfo.processInfo.environment["TERM"] ?? ""
4242

4343
public static var fullColorSupport: Bool {
44-
return Terminal.fullColorSupport(termVar: Terminal.current)
44+
return Terminal.fullColorSupport(terminal: Terminal.current)
4545
}
4646

47-
public static func fullColorSupport(termVar: String) -> Bool {
47+
public static func fullColorSupport(terminal: String) -> Bool {
4848
// A rather dumb way of detecting colour support
49-
return termVar.contains("256")
49+
return terminal.contains("256")
5050
}
5151

5252
// Colour tables from https://jonasjacek.github.io/colors/

Sources/CommandLineKitDemo/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
import Foundation
3535
import CommandLineKit
3636

37+
print("Detected terminal: \(Terminal.current)")
38+
print(Terminal.fullColorSupport ? "Full color support" : "No color support")
39+
print(LineReader.supportedByTerminal ? "LineReader support" : "No LineReader support")
40+
3741
if let ln = LineReader() {
3842
ln.setCompletionCallback { currentBuffer in
3943
let completions = [

0 commit comments

Comments
 (0)