mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
i tried so hard 😭
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ struct TerminalController: UIViewRepresentable {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return tv
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user