New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text/tabwriter: add cell width function #12073
Comments
CC @griesemer |
@jszwedko I think this is a reasonable suggestion, and in retrospect perhaps this would have been a better way to customize cell measurement than with the specific flags we have now. That said, I'm not sure how easy it would be to make this work given that part of the current implementation is using a state-machine like mechanism (but I haven't looked into it in detail). Specifically, my concern is how such a function would interact or possibly interfere with what we have already. Alternatively, an additional flag could be provided that would exclude escaped sequences of characters from the width computation. Or perhaps another escape character. Both these might be more in the current spirit of things even though perhaps less flexible than the function. If you want to give it a shot and come up with a concrete implementation, please feel free to go ahead. I'm happy to review but will push back if the result doesn't fit nicely with what we have. |
@griesemer yeah, looking more closely at the way the width is currently calculated does lead me to believe that it would be difficult to integrate a function like I suggested. I like the idea of a flag to exclude escaped characters, but it does feel like it should be a separate escape sequence to allow both features to be used concurrently. I'll mock that up and see what it looks like. Thanks for the feedback! |
This is somewhat related to the request to render CJK characters as two characters. In general, there are other classes of runes for which one would need to use alternative widths: fullwidth, modifiers, Jamo V+T, etc. If we make a change to the width handling, we should take these other cases in to account and allow supporting it. We could limit ourselves to determining width on a rune-by-rune basis. The column width of runes could look something like this (based on http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c, but slightly different):
|
Hello, everyone, I meet the same problem of printing CJK words, so I have to write a custom tabwriter (WeiZhang555/tabwriter). so the question is:
|
Changing the default is not an option, imo. CJK scripts are not the only What I could imagine, though, is allowing tabwriter to have an optional New(w io.Writer, opts ...Option) *Writer type Option ... func Padding(n int) Option func WidthFunc(func(cell []byte) int) Option Example: tabwriter.New(w, tabwriter.TabWidth(30), The flags are, unfortunately, not typed, otherwise they could be options. Something like that. That is quite an addition to the current package, even Note that the golang.org/x/text/width package also has support for On Mon, Jan 18, 2016 at 7:34 AM, zhangwei_cs notifications@github.com
|
Sounds really complicated, or even impossible! :-( |
Of course the alternative is to add a WriteFunc member to Writer. This is On Mon, Jan 18, 2016 at 10:25 AM, mpvl@golang.org wrote:
|
The implementation is really not hard. The biggest problem is coming up The second issue is to decide how the mapping looks like for fixed-width The problem with any fixed mapping, though, is that they don't work in all On Mon, Jan 18, 2016 at 10:48 AM, zhangwei_cs notifications@github.com
|
@griesemer And this is a very preliminary implementation, and I understand that it's not good enough, but at least it shows my thought. Thank you! |
CL https://golang.org/cl/18891 mentions this issue. |
Change https://golang.org/cl/202257 mentions this issue: |
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
Go's text/tabwriter package isn't aware of the ANSI Select Graphic Rendition (or SGR) escape sequences to change the terminal's foreground colour [1,2]. Using the sequences disrupt the alignment of the columns in the tabbed output. Therefore, unlike the existing POSIX shell implementation, running containers aren't marked in green in the Go version. [1] https://en.wikipedia.org/wiki/ANSI_escape_code [2] golang/go#12073 containers#318
I need this to work with ANSI colors. Would a PR be accepted? Could we have a new flag similar to |
I just found https://github.com/juju/ansiterm, I believe I can give it a try instead. |
What version of Go are you using (go version)?
1.4.2
What operating system and processor architecture are you using?
Linux / AMD64
What did you do?
What did you expect to see?
Where the first foo is red.
What did you see instead?
Where the first foo is red due to non-printable ANSI escape sequences being included in cell width calculations.
Proposal:
I realize that printing to the terminal may not be
text/tabwriter
s intended purpose, but I think it would be nice to be able to configure how the width of a cell is calculated as I can imagine further cases (similar to the special casing of HTML tags and entities currently) that would also benefit from this.Suggestion: Exposing an additional field on the
tabwriter.Writer
struct so as to maintain the function signature ofInit
andNewWriter
:If this function was
nil
, the existing width calculation could be used, but otherwise this function could be called with the contents of the cell.I can take a stab at the implementation of this, but I first wanted to see if such a change would be welcome.
The text was updated successfully, but these errors were encountered: