question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: show non printable charactors

See original GitHub issue
  • If your text file encoding is UTF-8 with BOM, \ufeff is invisible, you don’t known can remove BOM whether or not.
  • For indention, you use 4 whitespace instead TAB (\t), but you don’t known current indent delimitor is \t or 4 whitespace.
  • For word wrap, if line number is disabled, you don’t known the next line is break word or break by \n.

Describe the solution you’d like

Add a preference to setting non printable chars (such as whitespace, \n, \t…) can show or not.

Describe alternatives you’ve considered

Codemiror (JavaScript edition) ACE editor (JavaScript edition) TextWarrior (Java edition)

    private static final String GLYPH_NEWLINE = "\u21b5"; //↵
    private static final String GLYPH_SPACE = "\u00b7"; //·
    private static final String GLYPH_TAB = "\u00bb"; //»

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
massivemadnesscommented, Aug 24, 2020

@liyujiang-gzu It works pretty well, but it’s just too laggy when working with large files (especially scrolling), the reason is amount of spans. Right now I have no idea how to optimize this, so I don’t think it would be a good idea to implement this in the next version Here’s the file for tests JavaScriptAPI.zip

P.S I forgot to change tab size on screenshots

1reaction
liyujiang-gzucommented, Aug 2, 2020

Simple code :

            val nonPrintable = Pattern.compile(
                "[\\s\u0000-\u001f\u0020\u007f-\u009f\u00ad\u061c" +
                    "\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]"
            )
            val matcher = nonPrintable.matcher(text.subSequence(lineStart, lineEnd))
            while (matcher.find()) {
                text.setSpan(
                    NonPrintableSpan(color = "#ff666666".toColorInt()),
                    matcher.start() + lineStart, matcher.end() + lineStart,
                    Spannable.SPAN_INCLUSIVE_INCLUSIVE
                )
            }
/**
 * Created by liyujiang on 2020/08/01
 */
class NonPrintableSpan(@param:ColorInt private val color: Int) : ReplacementSpan() {
    override fun getSize(
        paint: Paint,
        text: CharSequence,
        start: Int,
        end: Int,
        fm: FontMetricsInt?
    ): Int {
        val subSequence = text.subSequence(start, end)
        if (TextUtils.equals(subSequence, "\ufeff")) {
            return paint.measureText(" ").toInt()
        }
        return if (TextUtils.equals(subSequence, "\t")) {
            paint.measureText("    ").toInt()
        } else paint.measureText(subSequence.toString())
            .toInt()
    }

    override fun draw(
        canvas: Canvas, text: CharSequence, start: Int, end: Int,
        x: Float, top: Int, y: Int, bottom: Int, paint: Paint
    ) {
        val subSequence = text.subSequence(start, end)
        val codePoint = Character.codePointAt(subSequence, 0)
        var replaceStr = subSequence.toString()
        when (codePoint) {
            0xfeff -> replaceStr = "\u00a4"
            0x9 -> replaceStr = "\u3009"
            0x20 -> replaceStr = "\u002e"
            else -> {
            }
        }
        paint.color = color
        paint.textSize = 8.dpToPx().toFloat()
        canvas.drawText(replaceStr, x, y.toFloat(), paint)
    }

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show non-printable characters in SWT a text widget
How is it possible to display non-printable characters in an SWT StyledText widget in a way it's done by Swing with an empty...
Read more >
25.7 Show Non-Printing Characters with cat -v or od -c
Instead, try cat -v . It turns non-printable characters into a printable form. In fact, although most manual pages don't explain how, you...
Read more >
View non-printable unicode characters - SoSci Survey
View non-printable unicode characters. Online tool to display non-printable characters that may be hidden in copy&pasted strings.
Read more >
Grep - Looking for non printable or higher range ascii characters
We faced an issue when someone copied a string from somewhere in one of the metadata xml files that contained ascii characters 239...
Read more >
Series Order - Michael Connelly
Follow the Harry Bosch series or The Lincoln Lawyer series or the Renée Ballard series or Other Main Characters. Click Here For A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found