holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.6k stars 116 forks source link

Code ligatures support #584

Closed RadioNoiseE closed 1 year ago

RadioNoiseE commented 1 year ago

Is it possible to specify font features (for example calt) in a-shell (like using config)? That would be quiet useful. (I don't know much about iOS development.)

holzschu commented 1 year ago

I'm not sure what calt means (and I could not find a lot of documentation about what it is, or how it is supported in iOS).

RadioNoiseE commented 1 year ago

Emm, that's just the name of a OpenType font feature. I'll try of I can find a documentation about that on iOS. I'm not very sure if iOS supports it because in Pages we can't specify that too. (But Adobe Illustrator has that.

RadioNoiseE commented 1 year ago

Yes I think I find it in the documentation

https://developer.apple.com/documentation/uikit/uifontdescriptor/featurekey

image

(The UIFontDescripor.FeatureKey).

And calt means contextual alternatives, it can be used for things like Fira-code ligatures.

(Anyway, thanks for this great app!)

holzschu commented 1 year ago

I gave it a try. On all the monospace fonts I have installed (not that many, but still) featureKey is nil.

Do you have a pointer to a monospace font with that feature? (the terminal representation works better with monospaced fonts, but you can load non-monospaced fonts)

update: even Fira Code has featureKey: nil.

updatex2: I have it working on my machine! It's just a matter of setting the right CSS variable. Now should that be an option, or should that be always activated? Is there any chance someone installs a font like Fira Code and doesn't want the code ligatures?

RadioNoiseE commented 1 year ago

Great!

But maybe you have misunderstood the feature of a font.

So there are many features available for a font, for instance there are also:

And my idea is that we can have a command like config -f <feature name> to allow users to specify the features for the font they want. And if they don't, they can just simply ignore it (don't set it).

While is something like calt.

Also, not only Fira Code but most fonts have features, and that's why I think this feature request is a not bad idea.

Thanks a lot!

holzschu commented 1 year ago

I see your point. Because a-Shell uses HTML and JavaScript to render the terminal, it's a CSS value, so the possible values are:

See https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-ligatures for reference. I don't see an option for "all" or "glyph decomposition", and apparently the various options cannot be combined. If you have other examples of fonts with similar features that I could test, that would be great.

RadioNoiseE commented 1 year ago

(I see?), but that's not really a problem.

Features like ccmp are enabled by default in typestters that isn't really needed in a text editor (like vim in a-shell). It is used to combine Chinese, Japanese and Korean ideographic characters. I mentioned it just as an example of a font feature.

(BTW: I also don't know about web and CSS)

And the ones you listed above is already really nice. Actually we don't want our text editor to act like a typesetter (LoL).

For the font that can be used to test, how about Iosevka?

https://github.com/be5invis/Iosevka

It seems to have many features that can be used to test. Also it seems to support some Programming Language Specific features (see fig). image But that's low priority.

(I don't know a lot about CSS so I'm not quite sure if we can specify font feature by the TeX way (like <fontname>:<features>) or need to use a wrapper like thing (I.e., like the fontspec package we have in TeX).

Have a nice day.

holzschu commented 1 year ago

Hi, if you want to test, the new config option is available on the TestFlight version of a-Shell mini: https://testflight.apple.com/join/REdHww5C

Ligatures are on by default, but can be deactivated with config -l none (and reactivated with config -l contextual). From my tests:

RadioNoiseE commented 1 year ago

Fantastic!

I tested it and it worked perfectly with Fira Code. (The problem with normal did occurred.)

image image

However with Iosevka, although I'm sure the font supports code ligatures, seems like it doesn't work.

(I haven't tested Haskel and JetBrains.)

I'll try to figure out why Iosevka didn't work (so I'll leave this issue open but tomorrow is weekday and I have to go to school so hopefully I'll have to continue on the next weekend).

And this works perfectly on normal fonts, thank you so much!

-- (I have to use Iosevka (actually, sarasa) because I need a font that supports CJK characters while the iOS fallback font is ugly.) So maybe it doesn't work because of its large char set or the wrong script (script = cjk) or something else. --

holzschu commented 1 year ago

I did not manage to install Sarasa (because it's too large) but I have ligatures with Iosevka. There was a twist: Iosevka-fixed does not have coding ligatures, but Iosevka-term has them. contextual and discretionary-ligatures have different ligatures set, as shown on their web page.

On the Sarasa documentation page (https://picaq.github.io/sarasa/), ligatures take ages to activate (again, on my underpowered iPad Pro (...)). Maybe we need to wait a while for the webView to load the ligatures the first time.

RadioNoiseE commented 1 year ago

Ohh! I installed the fixed one. Now everything is okey. Many thanks!