Add windows terminal setting to lem-pdcurses #380
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
lem-pdcurses には、ワイド文字に関する処理がいろいろと入っていますが、
もう少し整理しようと思い、
windows-term-setting クラスを追加してみました。
ワイド文字対応の処理は、主に以下の3種類の幅の変換になっています。
(1) 表示の幅
(2) 位置(座標)の幅 (例えば、Windows コンソールでは、Unicode のサロゲートペアの文字が 2 で、それ以外の文字が 1 になります)
(3) カーソル移動の幅 (例えば、mintty では表示の幅で指定、ConEmu では位置の幅で指定、というように異なります)
それぞれについて、変換あり / 変換なし / 関数によるカスタマイズ、を、
*windows-term-setting*
のプロパティで選択できるようにしました。デフォルトの設定は、以下のようにしています。
○:変換あり
×:変換なし
これで、今後、対応する端末のタイプが増えても、
個別の名称で全箇所に分岐を追加する必要がなくなると思います。
(ただ、新しく Windows Terminal というのが出てきていて、
今後は Windows Console API が非推奨になりそうとのことで、
PDCurses 自体が不要になりそうですが。。。)
実際には、きれいにいかないケースもあって、現状、それらは個別に対応しています。
例えば、以下があります。
単純に左端から幅をカウントしていると、後から左画面を更新されて、
右画面の文字が消えたり、化けたりする。
このため、ゼロ幅文字 (#\u200b) を使って、
左画面の文字数と表示幅が常に一定になるように調整している (adjust-line のところ)。
仕方がないので、専用の処理を入れて対応している (print-sub のところ)。
具体的には、表示エリアを一度消去してから、
同じ文字コードを位置をずらして2回ずつ書いている。
(PDCurses の内部キャッシュの問題かもしれない)
関数によるカスタマイズの例は、現在工事中ですが、以下のページに載せる予定です。
https://gist.github.com/Hamayama/12d5e637fc684e1d7e58e96aad5d0728
(内容としては、Fix display of Emoji characters on lem-pdcurses #354 の件に対応したものになる予定です。
あいかわらず、こちらは分かりにくくなってしまうと思いますが。。。)