migueldeicaza / SwiftTerm

Xterm/VT100 Terminal emulator in Swift
MIT License
996 stars 146 forks source link

UITextInput improvements #170

Open migueldeicaza opened 3 years ago

migueldeicaza commented 3 years ago

Currently, the UITextInput implementation is using an out-of-band Character buffer, plus positions and ranges that are based on indexes into this out-of-band buffer.

This works for dictation, and input methods and I finally got it to work.

That said, it has a few problems:

How other terminals work

Shelly iSSH Termius Secure Term Shell Fish LibTerm
Input Method Busted, enters both the initial sequence and additional ones Filters out Chinese Works sometimes, and shows selection during marking, but struggled with vi and cat Works Works Works+shows selection during marking
Dictation Live, works Does not work Live, works Live, works Works, but is buggy (sends text, then cursor backs to the origin, makes it useless) Works
SpaceMove. no-op no-op Tracks+Funky no-op Tracks+Funky Goes through the motions, but does not do anything.

Tracks+Funky in SpaceMove means that the application does track the cursor with the space bar, and then attempts to send enough cursor key movements to the target to track the location. But also means that in the wrong context (say, "cat"), it just sends the sequences and just looks odd.

Lakr233 commented 3 years ago

Have you find any solution on Chinese input? It doesn’t work and the insertText isn’t getting called. :( Having no idea where to follow up next…

migueldeicaza commented 3 years ago

Hello!

Can you describe what you are trying to do, and how it fails?

I would need to know what keyboard you are using, how you are activating it, and which keystrokes you are using, so I can reproduce locally.

It works as far as I can tell with the main branch

Lakr233 commented 3 years ago

Let me answer the question first.

I am trying to fix an issue that the terminalView insertText won't get called when typing with Chinese keyboard.

No respond or future action created.

The system one with Chinese Pinyin Input Method.

.onAppear {
    terminal.terminalView.becomeFirstResponder()
}

which keystrokes

I don't get it.......... :(


For some more detail, I can provide you a demo project that I am currently using. Let me explain a little bit more.

Changes:

Terminal Setup Block:

terminalView.backgroundColor = .clear
terminalView.isOpaque = true
terminalView.backgroundColor = UIColor.clear
terminalView.nativeBackgroundColor = UIColor.clear

Demo Project Here

migueldeicaza commented 3 years ago

Interesting finding: this happens with the SwiftUI wrapper, but not with the view without SwiftUI.

If you open the SwiftTerm sample project for iOS (iOSTerminal), and configure the host in UIKitSshTerminal.View and add manually the password there, you can see that the Chinese text input works.

But when I tried it on my own app, that wraps the SwiftTerm into a SwiftUI, the auxiliary keyboard is not shown either.

This is what SwiftTerm shows:

image

Sadly, this is what SwiftTermApp (my SwiftUI-based app that uses the exact same code) shows. In this case, I have already entered a few keys, and the keyboard is never shown:

image

So at this point, I suspect something is going on with SwiftUI. Reveal shows that the keyboard is being activated on the regular version, and the size of the keyboard is larger:

image

While on the SwiftUI version, the keyboard starts up smaller, and does not get the region with the additional data:

image

(Ignore the yellow color, that is just a different style that I am using there).

migueldeicaza commented 2 years ago

I have implemented manual support for the cursor tracking, so this works, but it is not as good as it could be, because the data that I get is a proxy to the geometry for the caret that I get - which is not necessarily what we want on a terminal app. So a potential fix is to use a timer when we get close to the boundary to trigger a repeat operation - but I have not figured out how to get the boundary information