kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
23.74k stars 958 forks source link

Reload config file without restart #1292

Closed Luflosi closed 3 years ago

Luflosi commented 5 years ago

What do you think of the possibility of reloading the config file without restarting kitty? While this may be a little difficult for some options, like those which are compiled into the shader code at startup, it should be fairly simple for some options that are just copied to some internal variable. I'm not asking to make most options reloadable, I'd just like to start with a couple easy ones. What do you think about this idea? If you're ok with this, I could make a pull request but I don't know where to start, maybe you can give me a couple tips. I've read #343, #635 and #684 but I am not quite satisfied with your answer that it's too much work, maybe you change your mind if someone else (me) is willing to implement it.

kovidgoyal commented 5 years ago

Having reloading for some options but not others is not worth it in my opinion, since that is just confusing. No one will be able to keep track of which options change and which do not. And implementing it for all options is waaay too much work. If you are willing to implement it for all options, then go ahead, I wont refuse the patch, but less than that is not a good idea, IMO.

If you want to implement it, you will basically need to carefully track each option to see how/where it is used and have the reload code change it accordingly. This is basically a lot of boring book-keeping.

Luflosi commented 5 years ago

Both iTerm2 and Alacritty support most config options or settings in case of iTerm2 to be changed without a restart but they don't support that with all of them. Why do you think that it's so confusing? As long as it is well documented, which ones require a restart and which ones don't, it should be ok IMHO.

kovidgoyal commented 5 years ago

Because there is no way for an end user to know to expect whether config option a will reload or not -- that is entirely dependent on the implementation details. Which means that if the user is trying to experiment with reloading the config file it will create another layer of confusion.

And not to mention that the config options that most people really want to change regularly, colors and such, are already dynamically changeable.

devth commented 5 years ago

+1 I think the entire world wants reloadable config.

TheConfuZzledDude commented 5 years ago

I think at least having a command to reload keyboard mappings from a config file would be enough, since that wouldn't confuse anyone, but would still be useful for the majority of times you'd want to reload the config for.

kbtz commented 5 years ago

What if the reload handles only options that have simple side effects, such as margin and padding? For example, Kitty looks great on i3 with a little padding but that gets in the way when using a "fullscreen" program such as vim. It would be great to have a way of removing that padding on the fly before I launch vim.

@kovidgoyal Would it be possible/ideal to achieve this through a kitten? Should I research into that?

Thanks!

kovidgoyal commented 5 years ago

You can implement it in a kitten or using the remote control facility as described here: https://sw.kovidgoyal.net/kitty/remote-control.html

jpmvferreira commented 5 years ago

Not sure if i should be asking here, given that the current status is close, but how is the progress going on this feature? Is there a workaround for similar results (such as, having your window manager close and open kitty at the same time such that it looked as if it were reloaded) while this feature is still being developed?

Luflosi commented 5 years ago

Nothing changed regarding the progress of this feature. Closing and reopening kitty would unfortunately not work well because the state of whatever was in the terminal before closing it can't be restored after opening it again, except with a terminal multiplexer like tmux. But that's not a very elegant/convenient solution.

jpmvferreira commented 5 years ago

Ah right, well hopefully such feature is implemented in the future, as it can be very handy, in my case to switch color schemes on the fly.

Thanks!

kovidgoyal commented 5 years ago

This feature is not being developed. You can control various aspects of kitty at runtime using the remote control protocol. https://sw.kovidgoyal.net/kitty/remote-control.html

Luflosi commented 5 years ago

Yeah, colors can be changed using the remote control protocol. See https://github.com/dexpota/kitty-themes#previews for an example.

JeanMertz commented 4 years ago

I can see how it would be difficult to support auto-reloading of all configuration options, and I also understand that "some work, others don't" isn't great, but I do think that "keyboard mappings auto-reload, nothing else" is perfectly explainable.

I'm not making a judgement on the complexity to make this work out of the box, or even the priority of such a feature compared to others on the list (or the desire for any contributor to actually implement it, for that matter), but I did want to add my vote for such a feature, as it greatly improves the workflow while tweaking your Kitty settings.

i-tub commented 4 years ago

I came up with a hack to reload the config with a tiny kitten. DISCLAIMER: I bet that this doesn't work for all config settings, and for all I know it might crash your kitty if you change the "wrong" setting. However, it works for changing keyboard mappings, which was what I cared about. Use at your own risk.

from kitty import cli, constants, fast_data_types

def main(args):
    pass

def handle_result(kargs, answer, target_window_id, boss):
    args, rest = cli.parse_args([])
    opts = cli.create_opts(args)
    boss.keymap = opts.keymap.copy()
    fast_data_types.set_options(opts, constants.is_wayland(), args.debug_rendering,
                                args.debug_font_fallback)

handle_result.no_ui = True

Also note that it passes an empty list to parse_args(), so any arguments you used when you originally started kitty are effectively thrown out. That works for me since I start kitty with no arguments, but YMMV. I suppose there's a way of re-using the original arguments but that's left as an exercise to the reader.

To use it, save it to ~/.config/kitty/reload.py and add some mapping to your kitty.conf, for example:

map kitty_mod+0 kitten reload.py
metalelf0 commented 4 years ago

+1 to this. I'd love to be able to have a set of "reloadable" options, like e.g. font face, padding/margin, and such, without needing a full kitty restart. My work flow is to start kitty, open 2-3 tabs with at least a couple splits each (servers, compilers, and stuff), and then every time I want to change a kitty setting I need to kill all processes and restart everything. Do you think it would be viable to use kittens to reload individual options (like, e.g., kitty @ reload-font-face ~/.config/kitty.conf)? I tried working on reloading font face, but I'm kinda stuck.

kovidgoyal commented 4 years ago

In general no. Options are used in both python and C and while kittens can change the former, they cannot change the latter, without a dedicated API exposed to python from the C code.

kovidgoyal commented 4 years ago

FYI, in current master there is now a remote control command to adjust margins and padding per window.

subnut commented 4 years ago

umm... @kovidgoyal , I tried as @i-tub suggested....... but, it isn't working AttributeError: 'CLIOptions' object has no attribute 'debug_gl'

EDIT: Nevermind, I found another, cleaner way to do what I wanted.

ThatOneCalculator commented 3 years ago

umm... @kovidgoyal , I tried as @i-tub suggested....... but, it isn't working AttributeError: 'CLIOptions' object has no attribute 'debug_gl'

EDIT: Nevermind, I found another, cleaner way to do what I wanted.

Could you share that cleaner way?

subnut commented 3 years ago

@ThatOneCalculator I just wanted to change the colors, not reload the whole config file. There's already a method to do that, just read the docs once.....

It should be in the Remote control section of the docs I used kitty @ set-colors -a -c <path-to-config-file>

anttikissa commented 3 years ago

I just discovered kitty, and my use case for this would be to be able to edit something in the config file and then immediately see the results (and having them persisted as well for future use).

My workaround for this (using macOS) is to configure macos_quit_when_last_window_closed to yes, and then run this in another terminal:

while true; do kitty vim .config/kitty/kitty.conf; done

Combined with vim set up so that it will open the file in the position I left it (see :help restore-cursor), this was more than sufficient for my purposes.

Alveel commented 3 years ago

This can be accomplished without having to first enable remote control, using the kitty shell window:

However, unfortunately, it doesn't work for new panels you open in the same session, only existing.

Luflosi commented 3 years ago

It should work in master and in the next version, see the commit that closed this issue.

sathishmanohar commented 1 year ago

In latest releases Ctrl+Shfit+F5 reloads the config as per the commit mentioned above.