Fix docker search output form when the description has CJK character#35034
Fix docker search output form when the description has CJK character#35034ChiuWang wants to merge 1 commit intomoby:masterfrom
Conversation
|
Please sign your commits following these rules: $ git clone -b "ellipsis" [email protected]:charrywanganthony/moby.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -fAmending updates the existing PR. You DO NOT need to open a new one. |
|
SGTM, anyone can verify current behavior with other writing systems such as Arabic/Hebrew or Mongolian? |
|
As far as i know,any system with usual Chinese(Japanese) fonts will display the character by |
|
ping @ripcurld0 you may know some images with other character sets ^^ |
|
@charrywanganthony looks like you need to |
|
https://en.m.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms contains some full-width symbols, half-width Katakana and half-width Hangul Jamo |
|
@thaJeztah the current code supports Hebrew characters pretty good. No need for code change. However, Hebrew text is printed in reverse. $ docker search ripcurld00dx/boaz |
|
I update the commit @thaJeztah , and set a more precise range for @AkihiroSuda . :) |
|
Can we use some existing unicode library such as https://godoc.org/golang.org/x/text/width ? |
|
Thx, this lib looks right for us. I'll check it soon. |
|
I did the change but met a problem. When i use vndr i will get the information How can I change vendor.conf manually to avoid the error |
|
Please just put EDIT: fix copy-paste error |
pkg/stringutils/stringutils.go
Outdated
There was a problem hiding this comment.
Please avoid using magic numbers
6bad739 to
640bf2f
Compare
pkg/stringutils/stringutils.go
Outdated
There was a problem hiding this comment.
These are already defined as width.EastAsianAmbiguous
There was a problem hiding this comment.
Thx for your help, I correct this, but the vendor problem still exists. @_@
2c48d5e to
a16d694
Compare
vendor.conf
Outdated
There was a problem hiding this comment.
Please remove *.go lines and just update commit hash of golang.org/x/text
There was a problem hiding this comment.
golang.org/x/text/width/gen.go
This was just my copy-paste error. I meant golang.org/x/text <commit hash>.
Sorry for causing confusion.
There was a problem hiding this comment.
problem still exists. @-@ Do I need to update the whole text package?
There was a problem hiding this comment.
Vendor check passed after I update text package. :)
|
看起来不错,除了 cc @yongtang @coolljt0725 请看一下 (PTAL) ? |
pkg/stringutils/stringutils_test.go
Outdated
There was a problem hiding this comment.
Is this expected? I don't think the whale emoji is a wide character?
There was a problem hiding this comment.
The character do takes two positions of a narrow one. And the test will pass only in this way, after we adopt https://godoc.org/golang.org/x/text/width
There was a problem hiding this comment.
Ah! Yes, you're right, I thought it only took a single width, but I see now.
Sorry for the noise 😊
Signed-off-by: Chao Wang <[email protected]>
|
WindowsRS1 failure is a known issue, and not related to the changes in this PR; #32219 |
thaJeztah
left a comment
There was a problem hiding this comment.
My concern with this PR is that it changes the behavior of the Ellipsis(), but not Truncate(). Therefore, these functions act different, which is very inconsistent.
For example, the following result in "t🐳s":
stringutils.Truncate("t🐳s", 3)But using ellipsis results in "t🐳":
stringutils.Ellipsis("t🐳s", 3)Looking at this package, I think it has become a collection of not-so-related functionality, and its scope is becoming more vague with this change. Let me try to explain that;
Ellipsis() is clearly targeted at displaying strings. Truncate() on the other hand is more ambigious; when used for displaying perhaps the string should be truncated at display width, not number of characters. However, because the purpose of the package is not well defined, it can be used in other contexts, and those can be problematic (e.g. limit a string's length to a maximum number of characters for storage).
I see this package has also been mentioned in #32989 (see @dnephin's gist), and based on the above, I think we should "dismantle" this package, and move code to places it will be used.
Having a look where things are used, and what we can do:
| Function | Where it's used | What to do |
|---|---|---|
GenerateRandomAlphaOnlyString() |
Only used in test (integration-cli) | integration-cli: RandomTmpDirPath() already mentions that it should not be used. integration-cli/cli/build/fakestorage/storage.go uses it. Other uses may not even need a random string; so either move it to the integration-cli, or perhaps it can be removed altogether. |
GenerateRandomASCIIString() |
Looks like it's not used | Probably can be removed |
Ellipsis() |
Only used in the CLI (https://github.com/docker/cli) | Move to that repository, and rewrite to indicate it uses displayWidth, not length. |
Truncate() |
Looks like it's not used | Move to the, and define its purpose, or perhaps rename it (TruncateDisplayWidth, rename the package to displayutils and name it displayutils.TrimWidth() - bad examples, but just to get you thinking), or remove it altogether |
InSlice() |
used in a couple of tests, and also in the seccomp and oci_linux parts |
It's a small function, and given that it's used in different contexts, I think we should copy it to those parts that use it, possibly renaming it for each purpose. |
ShellQuoteArguments() |
Looks like it's not used; also this isn't a "generic" string function - it's specifically for handling shell arguments. | Given that it isn't used, we can probably remove it. |
| if maxlen <= 3 { | ||
| return string(r[:maxlen]) | ||
| } | ||
| return string(r[:maxlen-3]) + "..." |
There was a problem hiding this comment.
If we're improving this function, perhaps this is the right moment to use the actual ellipsis ("…") character for this; not sure if that is one or two positions wide, but at least it allows showing more of the original string 👍
| //In a broad sense, wide characters include East Asian Wide, East Asian Fullwidth, and East Asian Ambiguous, | ||
| //see http://unicode.org/reports/tr11/ | ||
| kind := width.LookupRune(r).Kind() | ||
| if kind == width.EastAsianAmbiguous || kind == width.EastAsianWide || kind == width.EastAsianFullwidth { |
There was a problem hiding this comment.
Perhaps this should be used to a utility function, something like:
// charWidth returns the number of horizontal positions a character occupies,
// and is used to account for wide characters when displaying strings.
//
// In a broad sense, wide characters include East Asian Wide, East Asian Full-width,
// and East Asian Ambiguous (see http://unicode.org/reports/tr11/).
func charWidth(r rune) int {
switch width.LookupRune(r).Kind() {
case width.EastAsianAmbiguous, width.EastAsianWide, width.EastAsianFullwidth:
return 2
default:
return 1
}
}Then this loop could be something like;
var (
display []int
displayWidth int
)
rs := []rune(s)
for _, r := range rs {
cw := charWidth(r)
displayWidth += cw
display = append(display, cw)
}There was a problem hiding this comment.
OK , I will improve the code after we move the function to CLI repository.
There was a problem hiding this comment.
Thanks! Are you interested in working on that move?
There was a problem hiding this comment.
It will be a great pleasure :)
|
Thanks for your careful work @thaJeztah |
|
Awesome! First step would be to open a PR in https://github.com/docker/cli to have these utilities there. Once that is done, you can open a new PR in this repository to remove the things we no longer need (and make the other changes) I suggest we close this PR for now; does that sound good to you? |
|
OK. |
|
But I'm a little confused, what does |
|
That repository contains the Docker CLI; the parts of stringutils that are only used there (such as Happy to give more information/help if you need |
|
Yeah, I know this. What i'm comfused is the stringutils(moby) is in moby/moby/pkg/ ,but stringutils(cli) is in docker/cli/vendor/github.com/docker/docker/pkg/, this "vendor-relation" between moby and docker is somewhat equivocal.(sorry I'm a newbee ^-^) |
|
Ah yes; what we use in these repositories is "vendoring"; basically, instead of downloading dependencies when compiling, we keep a copy of all dependencies in the repository. Doing so, we know exactly which version of the dependency is used (the vendor.conf file contains the exact commit that was used), and also makes sure we can always build (even if the server hosting the dependency is down) In this case, the Docker CLI uses some packages from this (https://github.com/moby/moby) repository - but still under the old name (https://github.com/docker/docker - that will change soon). Here's some information about vendoring that I found https://blog.gopheracademy.com/advent-2015/vendor-folder/ |
|
If so, IMHO why not just change the code in this repository and then use vendor tools to update the package for CLI. But you recommend |
|
Well; the reason for moving it, is that usually, packages in a repository should be in that repository because the repository itself uses it (but they could be useful for other projects) I this case, the code is not used at all in this repository, so it's better to move it to the repository (Docker CLI) where it's actually used |
|
Thx! sorry for bothering u the beginner level question. |
|
Not at all; they're good questions! |
- What I did

fixes docker search output form when the description has CJK character
- How I did it
Every Chinese or Japanese character takes two position of a English charactor,
But technically many other languages or special symbol should be checked. But I didn't
find a search result case.
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
