Code Monkey home page Code Monkey logo

Comments (7)

michaelpj avatar michaelpj commented on June 1, 2024 1

Yeah, the most important thing is just documenting what they're supposed to be so clients can put the right thing in!

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

You are absolutely right!
This is something that I completely forgot to specify.

I am aware that I unfortunately don't support (yet) variable-width characters (e.g. tabs, but also some other unicode characters if I recall correctly), which will break the output (though colors should still be applied correctly).
What would be a correct way of handling those?

from diagnose.

michaelpj avatar michaelpj commented on June 1, 2024

I think if you just say that the column numbers are code-point offsets in the line, then you're fine. All you have to worry about then is creating your markers, which I guess require generating whitespace which takes up a given number of code points (easy) and generating a marker element that takes up a given number of code points (also easy?).

I actually have no idea how tabs work 😅

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

All you have to worry about then is creating your markers, which I guess require generating whitespace which takes up a given number of code points (easy) and generating a marker element that takes up a given number of code points (also easy?).

If everything has been correctly implemented, then all this should already be the case.
This still requires some testing on some weird looking Unicode strings though.

I actually have no idea how tabs work sweat_smile

As far as I'm aware, they just are single byte characters which are rendered differently depending on many factors (editor configuration, terminal emulators, user environment, etc).
However, in the case of this library, this may produce very inconsistent output, as tabs will be output as simple spaces.
So this is something that I have to look after.
prettyprinter may also include a way to work with tabs, which would solve all these problems I believe.


Thanks for the issue! 🙂

from diagnose.

sofia-m-a avatar sofia-m-a commented on June 1, 2024

The solution which I want to integrate into my error library Chapelure is to use wcswidth. Sadly there is not yet a standalone binding package for this on Hackage (although there is Graphics.Text.Width from vty). A proper wcswidth implementation handling emoji and double-width unicode characters, together with some preset for converting tabs into n spaces, seems to be the most 'standard' approach, although there's hardly a consensus between text editors, programming language diagnostics, and terminals about what a 'column' is.

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

Thanks for the link to wcwidth/wcswidth. I actually didn't know about it!
As for a Haskell implementation, there are two ways to go for:

I do not want to depend on vty, as it is a very big dependency and does not currently work on Windows.
Edit: just found at that this package is actually available on Hackage: https://hackage.haskell.org/package/wcwidth

A proper wcswidth implementation handling emoji and double-width unicode characters, together with some preset for converting tabs into n spaces, seems to be the most 'standard' approach

This is ideally what I would like to follow, now knowing that functions like those exist. 😀

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

Using wcwidth + space conversion for TABs seems to work perfectly!
image
The space after the weird sum is a TAB, and is rendered above as 4 spaces (though this is now configurable).
Both the 🎉 emoji and the chinese character take 2 cells, which has correctly been identified.

Thanks again everybody for all the precisions and the issue itself!

from diagnose.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.