VMConfigDisplayConsoleView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Copyright © 2021 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import SwiftUI
  17. struct VMConfigDisplayConsoleView: View {
  18. @Binding var config: UTMConfigurationTerminal
  19. private var textColor: Binding<Color> {
  20. Binding<Color> {
  21. if let consoleTextColor = config.foregroundColor,
  22. let color = Color(hexString: consoleTextColor) {
  23. return color
  24. } else {
  25. return Color.white
  26. }
  27. } set: { newValue in
  28. config.foregroundColor = newValue.cgColor!.hexString
  29. }
  30. }
  31. private var backgroundColor: Binding<Color> {
  32. Binding<Color> {
  33. if let consoleBackgroundColor = config.backgroundColor,
  34. let color = Color(hexString: consoleBackgroundColor) {
  35. return color
  36. } else {
  37. return Color.black
  38. }
  39. } set: { newValue in
  40. config.backgroundColor = newValue.cgColor!.hexString
  41. }
  42. }
  43. var body: some View {
  44. Section(header: Text("Style")) {
  45. VMConfigConstantPicker("Theme", selection: $config.theme.bound)
  46. ColorPicker("Text Color", selection: textColor)
  47. ColorPicker("Background Color", selection: backgroundColor)
  48. VMConfigConstantPicker("Font", selection: $config.font)
  49. HStack {
  50. Stepper(value: $config.fontSize, in: 1...72) {
  51. Text("Font Size")
  52. }
  53. NumberTextField("", number: $config.fontSize, prompt: "12")
  54. .frame(width: 50)
  55. .multilineTextAlignment(.trailing)
  56. }
  57. Toggle("Blinking cursor?", isOn: $config.hasCursorBlink)
  58. }
  59. 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.") {
  60. DefaultTextField("", text: $config.resizeCommand.bound, prompt: "stty cols $COLS rows $ROWS\n")
  61. }
  62. }
  63. }
  64. struct VMConfigDisplayConsoleView_Previews: PreviewProvider {
  65. @State static private var config = UTMConfigurationTerminal()
  66. static var previews: some View {
  67. Form {
  68. VMConfigDisplayConsoleView(config: $config)
  69. }
  70. #if os(macOS)
  71. .scrollable()
  72. #endif
  73. }
  74. }