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

Terminal colors not restored after "kitty +kitten diff" #637

Closed
blueyed opened this issue Jun 14, 2018 · 10 comments
Closed

Terminal colors not restored after "kitty +kitten diff" #637

blueyed opened this issue Jun 14, 2018 · 10 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Jun 14, 2018

I am using https://github.com/chriskempson/base16-shell to setup terminal colors, and after using kitty +kitten diff CHANGELOG.rst LICENSE (in kitty's source tree), the colors are not properly restored.

That might only be about the background color.

I am using solorized-{dark,light} normally, but also tried other themes.

To reproduce this:

  1. git clone git://github.com/chriskempson/base16-shell.git
  2. source base16-shell/scripts/base16-grayscale-light.sh
  3. The background should be gray
  4. Run kitty +kitten diff CHANGELOG.rst LICENSE
  5. Exit with "q"
  6. The background is black

Re-sourcing base16-shell/scripts/base16-grayscale-light.sh fixes it.

I've also seen this in some other context (using the hints kitten IIRC).

btw: with non-existing files I get the following (separate issue).
It displays the traceback for FileNotFoundError at the top, but does not clean the screen before - therefore it looks really messy.

Traceback (most recent call last):-i)❯❯ grbc                  ⟳(c) ⟳(m) 🐍? !9543 ⌚14:33:54
  File "/usr/bin/../lib/kitty/kittens/tui/loop.py", line 191, in _run_job
    result = func(*args, **kw)larized light
  File "/usr/bin/../lib/kitty/kittens/diff/main.py", line 41, in generate_diff
    is_binary = isinstance(data_for_path(path), bytes)zed-light.
  File "/usr/bin/../lib/kitty/kittens/diff/collect.py", line 144, in data_for_path4:34:06 ――
    ans = raw_data_for_path(path)❯❯ gp -f                                      ⟳(c) ⟳(m) 🐍?
  File "/usr/bin/../lib/kitty/kittens/diff/collect.py", line 134, in raw_data_for_path
    with open(path, 'rb') as f:zed-light -> fix-solarized-light (stale info)
FileNotFoundError: [Errno 2] No such file or directory: '…/lib/base16/base16-shell/CHANGELOG.rst'6-shell ❯   ――――――――――――――――― ☶ ✖4:1y @8519d21 !9545 ⌚14:34:09 ――
 λ fix-solarized-light@b[+45/-1]✗❯❯ gfa                                        ⟳(c) ⟳(m) 🐍?
Press Enter to quit. 
―― ❮ ~df/lib/base16/base16-shell ❯   ――――――――――― ☵ ✖4:1y:1,2,3 @efa06ce !9553 ⌚14:39:44 ――
 λ m@o✗❯❯ kitty +kitten diff CHANGELOG.rst LICENSE                                       🐍?
F

Using kitty v0.11.0-11-ga157f3c.

@kovidgoyal
Copy link
Owner

I'll look at he background color not being restored when I have a moment, but I cannot replicate your second issue. When one of the files is not found, the traceback appears below the prompt not at the top. The only way it could possibly appear at the top is if the terminal was already in alternate screen mode.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Jun 14, 2018

I took a quick look, and the diff kitten does set the default foreground/background colors, as a performance optimization. I'll add some code to it, to restore them on exit.

@blueyed
Copy link
Contributor Author

blueyed commented Jun 14, 2018

Thanks for fixing this so quickly!

As for the second issue: that happens only when running it from a non-kitty terminal (urxvt).
I've seen that you improved the error handling there also, which fixes it when running it from urxvt, too (i.e. the error appears below the command).

However, running kitty +kitten diff CHANGELOG.rst LICENSE (i.e. a successful diff) will change the colors to solarized-light (when using the dark variant), and does not display the diff colored (it uses real/dark black only). When exiting, the terminal is in light mode, but with the fg being dark black (not the solarized one).
Is using kitty +kitten … from another terminal a supported use case?
If so, what does it do then?

@kovidgoyal
Copy link
Owner

No, all kitty's kittens are kitty only. They use various features that are kitty specific. https://sw.kovidgoyal.net/kitty/kittens/diff.html#why-does-this-work-only-in-kitty

@maximbaz
Copy link
Contributor

I didn't look into the code yet, but the latest commit fe3b10a actually introduced this issue for me - now I exit the diff and my screen remains white.

@kovidgoyal
Copy link
Owner

Should be fixed with the next commit

@maximbaz
Copy link
Contributor

Still happens for me with 59743fd, and that commit also started printing a trace when I exit the diff with q:

❯ python . +kitten diff ~/tmp/one.txt ~/tmp/two.txt
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "./__main__.py", line 96, in <module>
    main()
  File "./__main__.py", line 87, in main
    namespaced(['+', first_arg[1:]] + sys.argv[2:])
  File "./__main__.py", line 49, in namespaced
    func(args[1:])
  File "./__main__.py", line 44, in run_kitten
    run_kitten(kitten)
  File "./kittens/runner.py", line 88, in run_kitten
    runpy.run_module('kittens.{}.main'.format(kitten), run_name=run_name)
  File "/usr/lib/python3.6/runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "./kittens/diff/main.py", line 514, in <module>
    main(sys.argv)
  File "./kittens/diff/main.py", line 502, in main
    loop.loop(handler)
  File "./kittens/tui/loop.py", line 412, in loop
    self._report_error_loop(tb, term_manager)
  File "./kittens/tui/loop.py", line 418, in _report_error_loop
    self.loop_impl(handler, term_manager.tty_fd, waiting_for_write=False)
  File "./kittens/tui/loop.py", line 374, in loop_impl
    with handler:
  File "./kittens/tui/handler.py", line 38, in __enter__
    self.initialize()
  File "./kittens/tui/loop.py", line 142, in initialize
    self.cmd.set_default_colors()
  File "./kittens/tui/operations.py", line 275, in f
    handler.write(func(*a, **kw))
  File "./kittens/tui/operations.py", line 240, in set_default_colors
    item(fg, 10)
  File "./kittens/tui/operations.py", line 238, in item
    ans += '\x1b]{};{}\x1b\\'.format(num, color_as_sharp(which if isinstance(which, Color) else to_color(which)))
  File "./kitty/rgb.py", line 60, in to_color
    x = raw.strip().lower()
AttributeError: 'NoneType' object has no attribute 'strip'

@kovidgoyal
Copy link
Owner

cd6a467

@maximbaz
Copy link
Contributor

Now everything is good again, thanks 😉

@kovidgoyal
Copy link
Owner

Oh and just FYI @blueyed you migh be interested in this FAQ: https://sw.kovidgoyal.net/kitty/faq.html#how-do-i-change-the-colors-in-a-running-kitty-instance

metayan pushed a commit to metayan/kitty that referenced this issue Jun 20, 2018
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

3 participants