axodotdev / axolotlsay

💬 a CLI for learning to distribute CLIs in rust
Apache License 2.0
24 stars 8 forks source link

Bubble width fix #2

Closed non-descriptive closed 1 year ago

non-descriptive commented 1 year ago

Should be good for a lot of cases, like I've presented in #1. Not sure if I wanna fix it for something like ¯\_( ͡° ͜ʖ ͡°)_/¯

Plecra commented 1 year ago

As a rule, the only true source of truth for text sizing is your font renderer... I've been wondering for a while if we can use terminal APIs to get the right behaviour for these alignment tasks.

Plecra commented 1 year ago

Yeah! Awesome :) Rust can ask terminal renderers for true text size with this:

// this leaves `msg` in the text buffer! Make sure it's overwritten if you dont want weirdness
print!("\r{msg}");
std::io::stdout().flush().unwrap();
let count = crossterm::cursor::position().unwrap().0 as usize;
print!("\r");

But there's a side effect of making our test suite much nastier, since we need to give the code a real TTY. unicode-width is a tidier solution in the end!

Plecra commented 1 year ago

Uhoh... that was probably a bit eager. Alacritty seems to get very confused by ligatures. Here it's rendering text at the wrong place in the input buffer. I get the sense things will be even more exciting with various linux terminals :D

marli@Elsie:/$ "¯\_( ͡° ͜ʖ ͡°)_/¯"   more
-bash: ¯\_( ͡° ͜ʖ ͡°)_/¯more: No such file or directory
non-descriptive commented 1 year ago

Yes, alacritty still doesn't support ligatures. And also I'm not sure whether axolotl should support speaking in this kind of emojis, since anyway half of the terminals will not be able to render half of the symbols in it. git bash, cygwin, default cmd, powershell, windows terminal, alacritty - on windows they render it very poorly on average for most smileys like that. Same stands for Z̯̮̦̲͓͇͔A̓̔L̠̦͓̻̩̲ͧ̾̍͝G̸̝ͥ̀̌ͫ̅̊͂O͔͓͔͚̳̫͑!̳͉̹̬͌́ fuckery aka multiple combining characters per symbol, which is basically unused in regular written text. Smiley above do some trickery, combining full-width characters (Japanees/ Chineese regular kanas aka CJK) with normal single width characters and library, I've added, doesn't make much distinction if they are that mixed.