Skip to content

Commit

Permalink
config(qemu): re-introduce blinking cursor option
Browse files Browse the repository at this point in the history
Resolves #4296
  • Loading branch information
osy committed Sep 4, 2022
1 parent 3f540f9 commit b2dea7e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Configuration/UTMConfigurationTerminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct UTMConfigurationTerminal: Codable, Identifiable {
/// Command to send when the console is resized.
var resizeCommand: String?

/// Terminal has a blinking cursor.
var hasCursorBlink: Bool = true

let id = UUID()

enum CodingKeys: String, CodingKey {
Expand All @@ -45,6 +48,7 @@ struct UTMConfigurationTerminal: Codable, Identifiable {
case font = "Font"
case fontSize = "FontSize"
case resizeCommand = "ResizeCommand"
case hasCursorBlink = "CursorBlink"
}

init() {
Expand All @@ -58,6 +62,7 @@ struct UTMConfigurationTerminal: Codable, Identifiable {
font = try values.decode(QEMUTerminalFont.self, forKey: .font)
fontSize = try values.decode(Int.self, forKey: .fontSize)
resizeCommand = try values.decodeIfPresent(String.self, forKey: .resizeCommand)
hasCursorBlink = try values.decodeIfPresent(Bool.self, forKey: .hasCursorBlink) ?? true
}

func encode(to encoder: Encoder) throws {
Expand All @@ -71,6 +76,7 @@ struct UTMConfigurationTerminal: Codable, Identifiable {
try container.encode(font, forKey: .font)
try container.encode(fontSize, forKey: .fontSize)
try container.encodeIfPresent(resizeCommand, forKey: .resizeCommand)
try container.encode(hasCursorBlink, forKey: .hasCursorBlink)
}
}

Expand All @@ -88,6 +94,7 @@ extension UTMConfigurationTerminal {
fontSize = fontSizeNum.intValue
}
resizeCommand = oldConfig.consoleResizeCommand
hasCursorBlink = oldConfig.consoleCursorBlink
}

#if os(macOS)
Expand All @@ -102,6 +109,7 @@ extension UTMConfigurationTerminal {
fontSize = fontSizeNum.intValue
}
resizeCommand = oldConfig.consoleResizeCommand
hasCursorBlink = oldConfig.consoleCursorBlink
}
#endif
}
Expand Down
1 change: 1 addition & 0 deletions Platform/Shared/VMConfigDisplayConsoleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct VMConfigDisplayConsoleView: View {
.frame(width: 50)
.multilineTextAlignment(.trailing)
}
Toggle("Blinking cursor?", isOn: $config.hasCursorBlink)
}

DetailedSection("Resize Console Command", description: "Command to send when resizing the console. Placeholder $COLS is the number of columns and $ROWS is the number of rows.") {
Expand Down
1 change: 1 addition & 0 deletions Platform/iOS/Display/VMDisplayTerminalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ extension VMDisplayTerminalViewController {
terminalView.nativeForegroundColor = UIColor(textColor)
terminalView.nativeBackgroundColor = UIColor(backgroundColor)
}
terminalView.getTerminal().setCursorStyle(style.hasCursorBlink ? .blinkBlock : .steadyBlock)
}
}

Expand Down
5 changes: 3 additions & 2 deletions Platform/iOS/VMDisplayHostedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ struct VMDisplayHostedView: UIViewControllerRepresentable {
mvc.delegate = context.coordinator
mvc.setDisplayScaling(state.displayScale, origin: state.displayOrigin)
vc = mvc
case .serial(let serial, _):
vc = VMDisplayTerminalViewController(port: serial)
case .serial(let serial, let id):
let style = vm.qemuConfig.serials[id].terminal
vc = VMDisplayTerminalViewController(port: serial, style: style)
vc.delegate = context.coordinator
}
context.coordinator.vmStateCancellable = session.$vmState.sink { vmState in
Expand Down
1 change: 1 addition & 0 deletions Platform/macOS/Display/VMDisplayTerminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension VMDisplayTerminal {
terminalView.nativeBackgroundColor = NSColor(backgroundColor)
}
terminalView.getTerminal().resize(cols: windowConfig.columns, rows: windowConfig.rows)
terminalView.getTerminal().setCursorStyle(config.hasCursorBlink ? .blinkBlock : .steadyBlock)
let size = window.frameRect(forContentRect: terminalView.getOptimalFrameSize()).size
let frame = CGRect(origin: window.frame.origin, size: size)
window.minSize = size
Expand Down

0 comments on commit b2dea7e

Please sign in to comment.