Giter Site home page Giter Site logo

Comments (5)

TooTallNate avatar TooTallNate commented on June 16, 2024

Hey @Marak. This sounds like a feature that should be implemented in colors.js IMO. It sounds like you should be altering the String.prototype.length getter in order to subtract the length of the ANSI color codes. This would fix the problem here, and any other potential lib that depends on String#length (which are probably out there).

Plus, if I do: 'Hello World!'.blue.length I would always expect it's length to be 12, and not 22. So this really does seem like a colors.js bug to me...

Just food for thought...

from cli-table.

TooTallNate avatar TooTallNate commented on June 16, 2024

Of course, the above it assuming that you're actually using colors.js. You never verified that in the OP, so I'm not sure...

from cli-table.

Marak avatar Marak commented on June 16, 2024

I thought about messing with String.prototype.length but my javascript spider sense told me not to do it.

I'll try it anyway and see what happens.

Actual library is kinda irrelevant, problem applies to ANSI escape codes in strings meant for terminal output.

Thanks for the advice!

from cli-table.

TooTallNate avatar TooTallNate commented on June 16, 2024

I'd think String.prototype.length would be doable, so long as you're safe about it. And ya, I get that the ANSI codes in general are the problem, but your colors.js aims to be a convenience wrapper around those escape codes, so continuing to abstract them away from the String interface (i.e. also abstracting them out of String#length) would be a good thing IMO.

This way, cli-table doesn't need to even know about the ANSI escape code, which I think it shouldn't...

from cli-table.

Marak avatar Marak commented on June 16, 2024

Fixed with #6. Thanks!

from cli-table.

Related Issues (20)

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.