Earu / EasyChat

A modular Garry's Mod chat addon for both users and developers. (EOL 2025)
https://steamcommunity.com/sharedfiles/filedetails/?id=1182471500
GNU General Public License v3.0
90 stars 31 forks source link

Tabulation characters ('\t') are not rendered in chat #109

Closed stepa2 closed 1 year ago

stepa2 commented 1 year ago

E.g. following E2 code displays as 'FirstSecondThird' in chat but 'First Second Third' in console.

print("First","Second","Third")
Earu commented 1 year ago

Hi, thank you for opening this issue. Could you please check these details:

stepa2 commented 1 year ago

It works with no third-party chat addons installed. I am pretty sure that is because RichText or what control is used in engine supports tabulation rendering.

Earu commented 1 year ago

Are you in x64 or default?

stepa2 commented 1 year ago

dev branch

Earu commented 1 year ago

After testing and asking multiple people, heres what I found:

I'm not sure whether replacing \t by 4 or 6 spaces in these panels is a good idea, if you want to copy something it might look weird if it's done. Can't see how to fix this otherwise as both problems come from things I do not have control over.

stepa2 commented 1 year ago

It is probable that surface text drawing functions not handle tabs. https://github.com/Earu/EasyChat/blob/5b8601ab82a0abdded61c6ea74b12bc386441366/lua/easychat/chathud.lua#L608-L611

One way to handle tabs is to separate text in tab-only parts and tab-less parts. When you find tab-only part, you don't need to render that part, just render next (tab-less) part on position round(start_of_tabs + tab_count * tab_size, tab_size). Note that you can't just use math.Round here, you need

local function round(num, roundval) return math.Round(num / roundval) * roundval end
Earu commented 1 year ago

It's not the surface library, the chat hud renders tabulations properly, it stems from the chatbox UI components