Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing features/bugs with the terminal #1117

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ extension AppPreferences {
/// The font to use in terminal.
var font: TerminalFont = .init()

// The cursor style to use in terminal
var cursorStyle: TerminalCursorStyle = .steadyBlock

/// Default initializer
init() {}

Expand All @@ -37,6 +40,7 @@ extension AppPreferences {
self.optionAsMeta = try container.decodeIfPresent(Bool.self, forKey: .optionAsMeta) ?? false
self.shell = try container.decodeIfPresent(TerminalShell.self, forKey: .shell) ?? .system
self.font = try container.decodeIfPresent(TerminalFont.self, forKey: .font) ?? .init()
self.cursorStyle = try container.decodeIfPresent(TerminalCursorStyle.self, forKey: .cursorStyle) ?? .steadyBlock
bombardier200 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -50,6 +54,14 @@ extension AppPreferences {
case system
}

enum TerminalCursorStyle: String, Codable {
case blinkBlock
case steadyBlock
case blinkUnderline
case steadyUnderline
case blinkingBar
case steadyBar
}
bombardier200 marked this conversation as resolved.
Show resolved Hide resolved
struct TerminalFont: Codable {
/// Indicates whether or not to use a custom font
var customFont: Bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct TerminalPreferencesView: View {
PreferencesSection("Font") {
fontSelector
}
PreferencesSection("Style") {
carrotSelector
}
}
}

Expand All @@ -41,6 +44,23 @@ struct TerminalPreferencesView: View {
}
.frame(width: inputWidth)
}
private var carrotSelector: some View {
Picker("Terminal Carrot Style: ", selection: $prefs.preferences.terminal.cursorStyle) {
bombardier200 marked this conversation as resolved.
Show resolved Hide resolved
Text("Blink Block")
.tag(AppPreferences.TerminalCursorStyle.blinkBlock)
Text("Steady Block")
.tag(AppPreferences.TerminalCursorStyle.steadyBlock)
Text("Blink Underline")
.tag(AppPreferences.TerminalCursorStyle.blinkUnderline)
Text("Steady Underline")
.tag(AppPreferences.TerminalCursorStyle.steadyUnderline)
Text("Blinking Bar")
.tag(AppPreferences.TerminalCursorStyle.blinkingBar)
Text("Steady Bar")
.tag(AppPreferences.TerminalCursorStyle.steadyBar)
}
.frame(width: inputWidth)
}

private var optionAsMetaToggle: some View {
HStack {
Expand Down
18 changes: 18 additions & 0 deletions CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ struct TerminalEmulatorView: NSViewRepresentable {
return "/bin/zsh"
}
}
private func getTerminalCarrot() -> CursorStyle {
bombardier200 marked this conversation as resolved.
Show resolved Hide resolved
switch prefs.preferences.terminal.cursorStyle {
case .blinkBlock:
return CursorStyle.blinkBlock
case .steadyBlock:
return CursorStyle.steadyBlock
case .blinkUnderline:
return CursorStyle.blinkUnderline
case .steadyUnderline:
return CursorStyle.steadyUnderline
case .blinkingBar:
return CursorStyle.blinkBar
case .steadyBar:
return CursorStyle.steadyBar
}
}

/// Gets the default shell from the current user and returns the string of the shell path.
private func autoDetectDefaultShell() -> String {
Expand Down Expand Up @@ -176,6 +192,7 @@ struct TerminalEmulatorView: NSViewRepresentable {
terminal.selectedTextBackgroundColor = selectionColor
terminal.nativeForegroundColor = textColor
terminal.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
terminal.cursorStyleChanged(source: terminal.getTerminal(), newStyle: getTerminalCarrot())
terminal.layer?.backgroundColor = .clear
terminal.optionAsMetaKey = optionAsMeta
}
Expand Down Expand Up @@ -205,6 +222,7 @@ struct TerminalEmulatorView: NSViewRepresentable {
view.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
view.layer?.backgroundColor = .clear
view.optionAsMetaKey = optionAsMeta
view.cursorStyleChanged(source: terminal.getTerminal(), newStyle: getTerminalCarrot())
view.appearance = colorAppearance
if TerminalEmulatorView.lastTerminal[url.path] != nil {
TerminalEmulatorView.lastTerminal[url.path] = view
Expand Down