Skip to content
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

Colors don't apply inside gnu screen session in konsole #231

Closed
AndydeCleyre opened this issue Oct 20, 2015 · 4 comments
Closed

Colors don't apply inside gnu screen session in konsole #231

AndydeCleyre opened this issue Oct 20, 2015 · 4 comments
Milestone

Comments

@AndydeCleyre
Copy link
Contributor

Hi,

Using the 1.6.0 release and the following script, the plumbum-colored strings don't appear colored inside a screen session inside konsole, though they do outside of screen.

Here's my .screenrc:

escape ``
bind "j" prev
bind "k" next
bind "l" screen
defscrollback 300000
termcapinfo xterm ti@:te@
msgwait 2

And here's the script (see last few lines):

#!/usr/bin/env python3

from sys import argv
from time import time
from random import random

from plumbum import local
from plumbum.colors import red as pred, green as pgreen
from clint.textui.colored import red, green


EDITOR = local['subl']['-w']


if __name__ == '__main__':
    initial_names = argv[1:]
    with local.tempdir() as tmp:
        name_file = tmp / 'txtnamer_{}_{}_{}'.format(local.cwd.basename, time(), random())
        name_file.write('\n'.join(initial_names).encode())
        EDITOR(name_file)
        lines = name_file.read().decode().strip().split('\n')
    if len(lines) == len(initial_names):
        for file, dst in zip(map(local.path, initial_names), lines):
            if file.basename != dst:
                print(red(file.basename), green(dst), '', sep='\n')# clint, works inside screen
                print(pred | file.basename, pgreen | dst, '', sep='\n')# plumbum, doesn't work inside screen
                file.move(dst)
@henryiii
Copy link
Collaborator

Plumbum's color library looks for the $TERM variable to try to set color on or off. Can you try echo $TERM in a shell? I get screen as the result. I'm not sure whether color should always be on for screen, though.

clint uses .isatty() only, and then has an environment variable that can be set. Maybe it would make sense to assume at least basic color output if $TERM is not xterm, etc.

You can enforce color using:

from plumbum import colors
colors.use_color = 3 # 0 is off, 1 is 8 color, 2 is 16, 3 is 512, and 4 is 24 bit color

And that will turn on color regardless of the terminal type.

@AndydeCleyre
Copy link
Contributor Author

Thanks, it's screen for me as well, and setting use_color works. I would support color working inside screen by default, but I'm not sufficiently familiar with the potential problem cases.

@henryiii
Copy link
Collaborator

Found the docs on screen, and did some testing. Screen forces 8 color mode default, so added that plumbum.colors, and you can set term screen-256color to get 256 color mode, so added support for that too. Also changed the default to be level 3 color vs. no color, unless of course isatty() is false.

@henryiii henryiii added this to the v1.6.1 milestone Oct 20, 2015
@AndydeCleyre
Copy link
Contributor Author

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants