Skip to content

cmd/list: Re-enable highlighting of running containers - #494

Merged
debarshiray merged 1 commit into
containers:masterfrom
martymichal:reenable-running-container-highlighting
Jul 22, 2020
Merged

debarshiray merged 1 commit into
containers:masterfrom
martymichal:reenable-running-container-highlighting

Conversation

@martymichal

Copy link
Copy Markdown
Member

The rewritten Toolbox did not highlight running containers because the
code uses a special table writter from 'text/tabwriter' that does not
support ANSI color codes[0]. The solution used here is to use color
codes on every lines of the output (including headers) and make the
color codes use the same number of characters.

@martymichal martymichal added 3. Enhancement Improvement to an existing feature 6. Minor Change Should not cause breakage labels Jul 8, 2020
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

debarshiray pushed a commit to martymichal/toolbox that referenced this pull request Jul 22, 2020
The rewritten Toolbox did not highlight running containers because the
code uses a special table writter from 'text/tabwriter' that does not
support ANSI color codes[0]. The solution used here is to use color
codes on _every_ lines of the output (including headers) and make the
color codes use the same number of characters.

In my terminals (Tilix, GNOME Terminal) the output looks alright.

[0] golang/go#35017

containers#494
@debarshiray
debarshiray force-pushed the reenable-running-container-highlighting branch from 4c23829 to 3b1dee8 Compare July 22, 2020 13:29
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray

Copy link
Copy Markdown
Member

Nice. Well done!

Both GNOME Terminal and Tilix ultimately use VTE for terminal emulation; so I tried xterm to have something different, and it seems to work well there too.

I will look at the actual code now.

Comment thread src/cmd/list.go Resolved
Comment thread src/cmd/list.go Resolved
The Go implementation did not highlight running containers because it
uses a special table writer from 'text/tabwriter' that does not
support colored output [0].

The trick used here is to use ANSI SGR terminal escape sequences [1]
on every line output by the table writer, including headers, and make
the escape sequences use the same number of characters. eg., even
though it's idiomatic to use "\033[0m" to reset the SGR attributes,
such as color; each non-colored line is prefixed with "\033[0;00m" to
ensure that it has the same number of characters as "\033[1;32m", which
is used for bold green output.

Therefore, not only are the non-colored lines wrapped in a redundant
pair of ANSI SGR terminal escape sequences, they are carefully crafted
to match the escape sequences for colored output.

Tested on VTE and xterm.

[0] golang/go#35017
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters

containers#494
Comment thread src/cmd/list.go Resolved
@debarshiray
debarshiray force-pushed the reenable-running-container-highlighting branch from 3b1dee8 to 61a5f51 Compare July 22, 2020 21:40
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray
debarshiray merged commit 61a5f51 into containers:master Jul 22, 2020
@debarshiray

Copy link
Copy Markdown
Member

I merged everything, except the part about supporting Podman < 2.0.0. I will leave it up to you to decide what best to do.

One thing that comes to mind is whether we should be skipping the escape sequences when the output is not attached to a terminal device? People using toolbox list | less might appreciate it.

Either way, we can use separate PRs to address them.

Thanks again for working on this!

@martymichal martymichal added this to the Release 0.1.0 milestone Jul 23, 2020
@kindermoumoute

Copy link
Copy Markdown

Nice hack 👍

@martymichal

Copy link
Copy Markdown
Member Author

I merged everything, except the part about supporting Podman < 2.0.0. I will leave it up to you to decide what best to do.

I think we can keep things like this. Podman overall moves very quickly forward (all supported versions of Fedora are already on V2) and only the very stable distros (Debian, CentOS, RHEL,..) will have to wait a bit. I don't think it's that important.

One thing that comes to mind is whether we should be skipping the escape sequences when the output is not attached to a terminal device? People using toolbox list | less might appreciate it.

Yes, this is something that should be done.

@debarshiray

Copy link
Copy Markdown
Member

I merged everything, except the part about supporting Podman < 2.0.0.
I will leave it up to you to decide what best to do.

I think we can keep things like this. Podman overall moves very quickly
forward (all supported versions of Fedora are already on V2) and only the
very stable distros (Debian, CentOS, RHEL,..) will have to wait a bit. I don't
think it's that important.

Ok, that makes sense.

DaliborKr added a commit to DaliborKr/toolbox that referenced this pull request May 27, 2026
Show containers created from images that don't meet Toolbx requirements
in yellow in the 'toolbox list' output. This gives users a visual hint
that the container may not work as expected.

The yellow color is only applied when the container is stopped. Running
containers are shown in green as usual, following the coloring approach
introduced in [1].

Containers with incompatible images are identified by the
`com.github.containers.toolbox.image-unknown=true` label, which is set
during container creation when the image fails the compatibility check.

[1] containers#494

containers#1707

Signed-off-by: Dalibor Kricka <[email protected]>
DaliborKr added a commit to DaliborKr/toolbox that referenced this pull request Jun 29, 2026
Show containers created from images that don't meet Toolbx requirements
in yellow in the 'toolbox list' output. This gives users a visual hint
that the container may not work as expected.

The yellow color is only applied when the container is stopped. Running
containers are shown in green as usual, following the coloring approach
introduced in [1].

Containers with incompatible images are identified by the
`com.github.containers.toolbx.image-unknown=true` label, which is set
during container creation when the image fails the compatibility check.

[1] containers#494

containers#1707

Signed-off-by: Dalibor Kricka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. Enhancement Improvement to an existing feature 6. Minor Change Should not cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants