i tried so hard 😭

This commit is contained in:
neon443
2025-08-24 15:29:49 +01:00
parent d1dd77fde3
commit 18e5dbe9bf
4 changed files with 29 additions and 11 deletions

View File

@@ -11,9 +11,8 @@ import SwiftUI
import SwiftTerm
struct MiniTerminalController: UIViewRepresentable {
func feed() {
}
@Binding var text: String
@Binding var cursorType: CursorType
func makeUIView(context: Context) -> TerminalView {
let tv = MiniTerminalDelegate(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: .zero))
@@ -23,7 +22,11 @@ struct MiniTerminalController: UIViewRepresentable {
}
func updateUIView(_ tv: TerminalView, context: Context) {
guard let tdelegate = tv as? MiniTerminalDelegate else { return }
tdelegate.text = text
tdelegate.cursorType = cursorType
tv.setNeedsLayout()
tv.layoutIfNeeded()
tv.layoutSubviews()
}
}

View File

@@ -12,8 +12,21 @@ import SwiftTerm
@MainActor
class MiniTerminalDelegate: TerminalView, TerminalViewDelegate {
func setCursorType(_ style: CursorType) {
getTerminal().setCursorStyle(style.stCursorStyle)
var text: String = ""
var cursorType = CursorType()
var hasConfigured: Bool = false
override func layoutSubviews() {
super.layoutSubviews()
if !hasConfigured && bounds.width > 0 && bounds.height > 0 {
self.getTerminal().resetNormalBuffer()
self.getTerminal().resetToInitialState()
self.getTerminal().softReset()
self.feed(text: "")
self.getTerminal().setCursorStyle(CursorStyle.blinkBar)
hasConfigured = true
}
}
nonisolated public func sizeChanged(source: TerminalView, newCols: Int, newRows: Int) {}
@@ -27,8 +40,8 @@ class MiniTerminalDelegate: TerminalView, TerminalViewDelegate {
nonisolated public func iTermContent (source: TerminalView, content: ArraySlice<UInt8>) {}
nonisolated public func rangeChanged(source: SwiftTerm.TerminalView, startY: Int, endY: Int) {}
public convenience required override init(frame: CGRect) {
self.init(frame: .zero)
public override init(frame: CGRect) {
super.init(frame: frame)
terminalDelegate = self
}

View File

@@ -39,7 +39,6 @@ struct TerminalController: UIViewRepresentable {
)
}
}
return tv
}

View File

@@ -38,10 +38,13 @@ struct SettingsView: View {
}
.pickerStyle(.segmented)
HStack {
ForEach(CursorShape.allCases, id: \.self) { type in
MiniTerminalController()
MiniTerminalController(text: .constant("asdjf"), cursorType: $hostsManager.settings.cursorType)
.frame(width: 100, height: 100)
}
}
Picker("Cursor", selection: $hostsManager.settings.cursorType.cursorShape) {
ForEach(CursorShape.allCases, id: \.self) { type in
Text(type.description).tag(type)