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
|
import SwiftTerm
|
||||||
|
|
||||||
struct MiniTerminalController: UIViewRepresentable {
|
struct MiniTerminalController: UIViewRepresentable {
|
||||||
func feed() {
|
@Binding var text: String
|
||||||
|
@Binding var cursorType: CursorType
|
||||||
}
|
|
||||||
|
|
||||||
func makeUIView(context: Context) -> TerminalView {
|
func makeUIView(context: Context) -> TerminalView {
|
||||||
let tv = MiniTerminalDelegate(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: .zero))
|
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) {
|
func updateUIView(_ tv: TerminalView, context: Context) {
|
||||||
|
guard let tdelegate = tv as? MiniTerminalDelegate else { return }
|
||||||
|
tdelegate.text = text
|
||||||
|
tdelegate.cursorType = cursorType
|
||||||
tv.setNeedsLayout()
|
tv.setNeedsLayout()
|
||||||
tv.layoutIfNeeded()
|
tv.layoutIfNeeded()
|
||||||
|
tv.layoutSubviews()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,21 @@ import SwiftTerm
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
class MiniTerminalDelegate: TerminalView, TerminalViewDelegate {
|
class MiniTerminalDelegate: TerminalView, TerminalViewDelegate {
|
||||||
func setCursorType(_ style: CursorType) {
|
var text: String = ""
|
||||||
getTerminal().setCursorStyle(style.stCursorStyle)
|
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) {}
|
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 iTermContent (source: TerminalView, content: ArraySlice<UInt8>) {}
|
||||||
nonisolated public func rangeChanged(source: SwiftTerm.TerminalView, startY: Int, endY: Int) {}
|
nonisolated public func rangeChanged(source: SwiftTerm.TerminalView, startY: Int, endY: Int) {}
|
||||||
|
|
||||||
public convenience required override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
self.init(frame: .zero)
|
super.init(frame: frame)
|
||||||
terminalDelegate = self
|
terminalDelegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ struct TerminalController: UIViewRepresentable {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tv
|
return tv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,13 @@ struct SettingsView: View {
|
|||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
|
|
||||||
ForEach(CursorShape.allCases, id: \.self) { type in
|
HStack {
|
||||||
MiniTerminalController()
|
ForEach(CursorShape.allCases, id: \.self) { type in
|
||||||
|
MiniTerminalController(text: .constant("asdjf"), cursorType: $hostsManager.settings.cursorType)
|
||||||
|
.frame(width: 100, height: 100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Picker("Cursor", selection: $hostsManager.settings.cursorType.cursorShape) {
|
Picker("Cursor", selection: $hostsManager.settings.cursorType.cursorShape) {
|
||||||
ForEach(CursorShape.allCases, id: \.self) { type in
|
ForEach(CursorShape.allCases, id: \.self) { type in
|
||||||
Text(type.description).tag(type)
|
Text(type.description).tag(type)
|
||||||
|
|||||||
Reference in New Issue
Block a user