@dfabulich has submitted pull requests to AsyncGlk and RemGlk-rs to support glk_style_measure and glk_style_distinguish. Previously these haven’t been supported in Parchment because the GlkOte protocol makes it tricky to obtain the current styles. While most of the time the RemGlk library is on the same computer, it doesn’t have to be, and I didn’t want to add something that would mysteriously stop working if someone tried setting up a remote client. I also didn’t want to implement it as an RPC because the performance would be pretty bad.
Dan has proposed that the client send styles at startup, as well as in arrange events. This makes a lot of sense! The approach is solid, but I’d like to get the community’s input on the specific protocol before we implement it.
/** Runner theme for glk_style_measure */
export interface Theme {
stylehints_enabled: boolean,
buffer: StyleEntry[],
grid: StyleEntry[],
}
/** Effective theme values for one Glk style */
export interface StyleEntry {
fg: number,
bg: number,
weight: -1 | 0 | 1,
oblique: 0 | 1,
/** Glk sense: 1 = proportional, 0 = fixed-width */
proportional: 0 | 1,
reverse: 0 | 1,
}
So starting with the StyleEntry interface, we’re sending the basic font details of each style. They’re all numbers, which makes it simple, but it is a little less human friendly than the GlkOte protocol usually is. In particular colours are sent as numbers rather than as a CSS colour in text. Anyone have a problem with that?
I think we could measure the font size too. As the client is responsible for turning a Glk font hint into its actual font size, it should be able to convert back again.
Next is the Theme interface. I think the stylehints_enabled flag would be better as a support capability instead. Then it just has the all the styles for buffer and grid windows in an array.
I think it would be better to make them maps, so that any styles which are identical to the base (normal) style can be skipped. The keys could be style names, or just their numbers. Numbers are simpler and more condensed, but the GlkOte protocol uses style names elsewhere, so I’m not sure.
Likewise I think the individual properties within a StyleEntry should also be optional. Non base styles which only change one thing could just send that thing. But if a client didn’t support, for example, colours, then it could just leave that out entirely too.
This is not so much about the protocol but the implementation, but Dan’s RemGlk-rs PR currently implements a default theme if no specific details are sent. I don’t like this, I think glk_style_measure should just continue to return 0 if it can’t actually measure a style, like it does now. Fake information is worse than no information.
Parchment now supports my additional styles Glk extension. They will not be sent in the protocol, and will not be measurable.