Skip to content

Wrapping doesn't work properly with tabs. #166

@eth-p

Description

@eth-p

When implementing the wrapping, I failed to account for files that use tabs for indentation and/or alignment.

Image

image

Test File

# Leading Spaces
    70 ----------------------------------------------------------- 70
    71 ------------------------------------------------------------ 71
    72 ------------------------------------------------------------- 72
    73 -------------------------------------------------------------- 73
    74 --------------------------------------------------------------- 74
    75 ---------------------------------------------------------------- 75
    76 ----------------------------------------------------------------- 76
    77 ------------------------------------------------------------------ 77
    78 ------------------------------------------------------------------- 78
    79 -------------------------------------------------------------------- 79
    80 --------------------------------------------------------------------- 80
    81 ---------------------------------------------------------------------- 81
    82 ----------------------------------------------------------------------- 82
    83 ------------------------------------------------------------------------ 83
    84 ------------------------------------------------------------------------- 84
    85 -------------------------------------------------------------------------- 85

# Leading Tab (4 or 8 Spaces / Tab)
	70 ----------------------------------------------------------- 70
	71 ------------------------------------------------------------ 71
	72 ------------------------------------------------------------- 72
	73 -------------------------------------------------------------- 73
	74 --------------------------------------------------------------- 74
	75 ---------------------------------------------------------------- 75
	76 ----------------------------------------------------------------- 76
	77 ------------------------------------------------------------------ 77
	78 ------------------------------------------------------------------- 78
	79 -------------------------------------------------------------------- 79
	80 --------------------------------------------------------------------- 80
	81 ---------------------------------------------------------------------- 81
	82 ----------------------------------------------------------------------- 82
	83 ------------------------------------------------------------------------ 83
	84 ------------------------------------------------------------------------- 84
	85 -------------------------------------------------------------------------- 85

# Alignment
1	1
22	2
333	3
4444	4
55555	5
666666	6
7777777	7
88888888	8

Solutions

There are a couple of solutions that I think might solve this issue:

A. Replace \t with 4 or 8 spaces.

Pros:

  • Easy to implement.
  • Configurable for user's choice of either 4 or 8 characters.

Cons:

  • Output is different from source file (maybe only do it if wrapping and styling is enabled?)
  • Breaks tab alignment:
    1	2
    34	 5
    

B. Replace \t with n spaces, aligning to a 4 or 8 character boundary.

Pros:

  • Correct tab alignment.
  • Configurable for user's choice of either 4 or 8 characters.

Cons:

  • Output is different from source file (maybe only do it if wrapping and styling is enabled?)

C. Interpret \t and add n characters to the width counter variable.

Pros:

  • Output is the same as source file.

Cons:

  • More difficult to implement.

  • Different terminal emulators align tabs differently (e.g. 4/8 characters)

  • Breaks tab alignment:

    image


If I were to say, I think solution B would be the best way to handle it. It avoids the issue with terminal emulators having different sizes for the tab character (and it could be a configuration option), and it won't run into alignment or wrapping issues like solutions A and C.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions