Skip to content

Commit 5659ba0

Browse files
Addressing features/bugs with the terminal (#1117)
* Implementing changing cursor style for terminal along with adding in the setting. * renaming to Cursor, fixing a bug in the case statement * Fix formatting error * Update SwiftTerm to reflect main * small fix for update NSView * Fix lint error * Setting SwiftTerm to 1.2.0 target and changing preferences view.
1 parent 0b1118c commit 5659ba0

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ identifier_name:
1515
# paths to ignore during linting.
1616
excluded:
1717
- CodeEditModules/.build # Where Swift Package Manager checks out dependency sources
18-
18+
- DerivedData
1919
opt_in_rules:
2020
- empty_count
2121
- closure_spacing

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,7 +3748,7 @@
37483748
repositoryURL = "https://github.com/migueldeicaza/SwiftTerm.git";
37493749
requirement = {
37503750
kind = exactVersion;
3751-
version = 1.0.7;
3751+
version = 1.2.0;
37523752
};
37533753
};
37543754
58F2EB15292FB74D004A9BDE /* XCRemoteSwiftPackageReference "CodeEditTextView" */ = {

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ extension AppPreferences {
2727
/// The font to use in terminal.
2828
var font: TerminalFont = .init()
2929

30+
// The cursor style to use in terminal
31+
var cursorStyle: TerminalCursorStyle = .block
32+
33+
// Toggle for blinking cursor or not
34+
var cursorBlink: Bool = false
35+
3036
/// Default initializer
3137
init() {}
3238

@@ -37,6 +43,11 @@ extension AppPreferences {
3743
self.optionAsMeta = try container.decodeIfPresent(Bool.self, forKey: .optionAsMeta) ?? false
3844
self.shell = try container.decodeIfPresent(TerminalShell.self, forKey: .shell) ?? .system
3945
self.font = try container.decodeIfPresent(TerminalFont.self, forKey: .font) ?? .init()
46+
self.cursorStyle = try container.decodeIfPresent(
47+
TerminalCursorStyle.self,
48+
forKey: .cursorStyle
49+
) ?? .block
50+
self.cursorBlink = try container.decodeIfPresent(Bool.self, forKey: .cursorBlink) ?? false
4051
}
4152
}
4253

@@ -50,6 +61,12 @@ extension AppPreferences {
5061
case system
5162
}
5263

64+
enum TerminalCursorStyle: String, Codable {
65+
case block
66+
case underline
67+
case bar
68+
}
69+
5370
struct TerminalFont: Codable {
5471
/// Indicates whether or not to use a custom font
5572
var customFont: Bool = false

CodeEdit/Features/AppPreferences/Sections/TerminalPreferences/TerminalPreferencesView.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ struct TerminalPreferencesView: View {
2626
PreferencesSection("Font") {
2727
fontSelector
2828
}
29+
PreferencesSection("Cursor") {
30+
cursorStyle
31+
cursorBlink
32+
}
2933
}
3034
}
3135

@@ -41,6 +45,24 @@ struct TerminalPreferencesView: View {
4145
}
4246
.frame(width: inputWidth)
4347
}
48+
private var cursorStyle: some View {
49+
Picker("Terminal Cursor Style: ", selection: $prefs.preferences.terminal.cursorStyle) {
50+
Text("Block")
51+
.tag(AppPreferences.TerminalCursorStyle.block)
52+
Text("Underline")
53+
.tag(AppPreferences.TerminalCursorStyle.underline)
54+
Text("Bar")
55+
.tag(AppPreferences.TerminalCursorStyle.bar)
56+
}
57+
.frame(width: inputWidth)
58+
}
59+
60+
private var cursorBlink: some View {
61+
HStack {
62+
Toggle("Cursor Blink", isOn: $prefs.preferences.terminal.cursorBlink)
63+
Text("Blink cursor")
64+
}
65+
}
4466

4567
private var optionAsMetaToggle: some View {
4668
HStack {

CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ struct TerminalEmulatorView: NSViewRepresentable {
7373
}
7474
}
7575

76+
private func getTerminalCursor() -> CursorStyle {
77+
let blink = prefs.preferences.terminal.cursorBlink
78+
switch prefs.preferences.terminal.cursorStyle {
79+
case .block:
80+
return blink ? .blinkBlock : .steadyBlock
81+
case .underline:
82+
return blink ? .blinkUnderline : .steadyUnderline
83+
case .bar:
84+
return blink ? .blinkBar : .steadyBar
85+
}
86+
}
87+
7688
/// Gets the default shell from the current user and returns the string of the shell path.
7789
private func autoDetectDefaultShell() -> String {
7890
let bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)
@@ -176,6 +188,7 @@ struct TerminalEmulatorView: NSViewRepresentable {
176188
terminal.selectedTextBackgroundColor = selectionColor
177189
terminal.nativeForegroundColor = textColor
178190
terminal.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
191+
terminal.cursorStyleChanged(source: terminal.getTerminal(), newStyle: getTerminalCursor())
179192
terminal.layer?.backgroundColor = .clear
180193
terminal.optionAsMetaKey = optionAsMeta
181194
}
@@ -205,6 +218,7 @@ struct TerminalEmulatorView: NSViewRepresentable {
205218
view.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
206219
view.layer?.backgroundColor = .clear
207220
view.optionAsMetaKey = optionAsMeta
221+
view.cursorStyleChanged(source: view.getTerminal(), newStyle: getTerminalCursor())
208222
view.appearance = colorAppearance
209223
if TerminalEmulatorView.lastTerminal[url.path] != nil {
210224
TerminalEmulatorView.lastTerminal[url.path] = view

0 commit comments

Comments
 (0)