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

[feature request] bind q to exit resource details buffer (quit-window and kill-buffer) #36

Open
CsBigDataHub opened this issue Oct 2, 2020 · 14 comments
Labels
enhancement New feature or request

Comments

@CsBigDataHub
Copy link

CsBigDataHub commented Oct 2, 2020

press q to exit from any resource details buffer that is created when enter is pressed.

Essentially running quit-window or kill-buffer

@CsBigDataHub CsBigDataHub changed the title [feature request] bind q to exit resource details buffer [feature request] bind q to exit resource details buffer (quit-window and kill-buffer) Oct 2, 2020
@abrochard abrochard added the enhancement New feature or request label Feb 5, 2021
@d1egoaz
Copy link
Contributor

d1egoaz commented Jun 16, 2021

would binding q be even possible?

as https://www.gnu.org/software/emacs/manual/html_node/elisp/Keymaps-and-Minor-Modes.html

Minor modes may bind commands to key sequences consisting of C-c followed by a punctuation character.

There is an existing minor mode when viewing the yaml details of a resource,

we could add something like:

(define-minor-mode kubel-yaml-editing-mode
  "Kubel Yaml editing mode.
Use C-c C-c to kubectl apply the current yaml buffer."
  :init-value nil
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-c C-c") #'kubel-apply)
            (define-key map (kbd "C-c q") #'kill-current-buffer)
            map))

Binding q does not work, I'm not sure why yet, maybe because it's a minor mode and other modes take precedence

            (define-key map (kbd "q") #'kill-current-buffer)

@d1egoaz
Copy link
Contributor

d1egoaz commented Jun 16, 2021

Huh! q worked for me when I was in edit mode (I'm using evil).

Which is undesirable if someone wanted to type the letter q :)

Anyhow, the following worked for me using evil.
Not sure if we'd like to add this to kube-evil.el as it changes the default action of q, usually used to define macros in evil.

Or maybe just add it as a comment/note in the readme/wiki.

(evil-define-key 'normal 'kubel-yaml-editing-mode "q" #'kill-current-buffer)

@Kyrremann
Copy link
Contributor

Kyrremann commented Jan 13, 2022

I've been looking into this today, and what I've managed to do is to override the kubel-get-resource-details function, and add the readonly-parameter to the kubel--exec function.

I also had to modify the function more, cause I never managed to set the optional describe-paramter. Also persoanlly I mostly want to describer the resource, not just get-it. For me it would be logical to describe, if you haven't specified `-y'.

Another thing I have problem with is that kubel-output always is set, so I can't if on that value, and use that to check if you need to get the resource and then call kubel-yaml-editing-mode.

This code kinda works (it doesn't without commenting out the last if)

(defun kubel-describe-resource-details-popup (&optional describe)
  "Get the details of the resource under the cursor

 DESCRIBE is the optional param to describe instead of get."
  (interactive "P")
  (let* ((resource (kubel--get-resource-under-cursor))
         (process-name (format "kubel - %s - %s" kubel-resource resource)))
		(setq kubel-output "") ; this is just because I don't know why it's always set
		(if (or (string-equal kubel-output "yaml") (transient-args 'kubel-describe-popup))
				(kubel--exec process-name (list "get" kubel-resource (kubel--get-resource-under-cursor) "-o" "yaml"))
			(kubel--exec process-name (list "describe" kubel-resource (kubel--get-resource-under-cursor)) t))

    ;(if (or (string-equal kubel-output "yaml") (transient-args 'kubel-describe-popup))
	;			((yaml-mode)
	;			 (kubel-yaml-editing-mode)))
    (goto-char (point-min))))

(advice-add 'kubel-get-resource-details :override #'kubel-describe-resource-details-popup)

When I put the kubel--exec inside the if
I haven't managed to get it to work with -y from transient-args, but maybe someone here have some tips?
It fails with the following:

if: Invalid function: (kubel--exec process-name (list "get" kubel-resource (kubel--get-resource-under-cursor) "-o" "yaml"))
Error in post-command-hook (transient--post-command): (wrong-type-argument number-or-marker-p nil)
Error in pre-command-hook (transient--pre-command): (wrong-type-argument (or eieio-object class) nil obj)

PS(this should be a new issue?): How come all of the parameters for each function needs to be prepended with -? For example calling kubel-get-resource-details, you can add -y. Would be easier to just use y.

@Kyrremann
Copy link
Contributor

Kyrremann commented Jan 17, 2022

I've done some more work on this one, and the more I look at it, the more strange I think it is that it uses the get-command. So my proposal is to rewrite the kube--get-... to just be kube--describe.... This is kinda similar to kubel--describe-resource, but this one also ends up using get as the functions. At least how I understand it, cause I can't see the optional be used at all.

Also, shouldn't kubel-quick-edit call a kubel-get... funciton, instead of a kubel-describe... function?

This is my take on the new function:

(defun kubel-describe-resource-details-popup (&optional _)
  "Describe the details of the resource under the cursor"
  (interactive "P")
  (let* ((resource (kubel--get-resource-under-cursor))
         (process-name (format "kubel - %s - %s" kubel-resource resource)))
		(kubel--exec process-name (list "describe" kubel-resource (kubel--get-resource-under-cursor)))
		(yaml-mode)
		(view-mode)))

The (yaml-mode) should probably account for different outputs. Such as json.

If you'd like @abrochard, I can make a PR with my change, and how I think it all could look like.

PS: There is also something strange with kubel-output, if you set it to wide, and try to quick edit a deployment, you get kubectl get deployments -o wide, that can't be the intended behaviour?

@abrochard
Copy link
Owner

This thread confuses me. I think there are multiple issues at hand:

  1. there isn't a separate between describe and get, which means that we can't tell if the kubel output is editable or not
  2. if we manage to tell that the kubel output isn't editable, we could set it to read-only and bind q to exist
  3. we default to yaml-mode when sometimes the output could be json
  4. that wide behavior is weird and I don't remember what is going on there
    Did I get everything?

@Kyrremann
Copy link
Contributor

Sounds like a good summary!

  1. We should only do get when the user has chosen -y, or used quick edit, most other commands should use describe or at least end up with a read-only view.
  2. q is solved with calling view-mode after any other mode.

@abrochard
Copy link
Owner

Sorry what is -y? Also I'm not so sure. I regularly switch to deployment view with R and then use enter to view and edit a deployment. I want to avoid making assumptions that could break workflows.
Also for 3 and 4, those should be separate issues.

@Kyrremann
Copy link
Contributor

If you press ctrl+u before enter, you will get the transient menu, and there you can add -y.

Im also afraid of breaking people's workflow, but should people use E/quick edit if they want to change a resource?

I think either adding a flag like I've did, or added a new shortcut is the way to go for this feature.

@abrochard
Copy link
Owner

Got it.
I see no problem with making the buffer readonly if describe was used and that seems like a good PR. But I wouldn't touch beyond that without a lot of thinking. I can see a flag like describe-by-default or something where enter runs describe instead of get. Not sure about the name though.

@Kyrremann
Copy link
Contributor

Agree with that, keep the scope small. I can make a PR with the name describe-by-defualt, so we can get going with the code, and think a bit more about the name.

@abrochard
Copy link
Owner

Sounds great, thank you!

@Kyrremann
Copy link
Contributor

Kyrremann commented Jan 28, 2022

I’ve been looking into this today, and I’m pretty sure I’ve mistaken how at describe works in kubel. Haven’t noticed before now that C-u ENT is the way to run describe instead get. Personally I would have done it the opposite, but that’s not really a up for discussion here*.

So I think the solution would be to make it read only when you run describe, as you can't really apply the files/blob you get (as it adds events for most/all resources). Trying that for now.

Another nice feature would be to set the buffers that pop up when you for example delete a resource, to be read-only mode.

  • Maybe we could make a flag that flips this? Setting this new flag to true makes all describe as default, and vice versa 🤷 Not sure if it’s worth the effort, at least compared to the other issues.

PS: This post was posted a bit earlier today, but wanted to make some more research before I posted, so ended up deleting it right after.

@Kyrremann
Copy link
Contributor

Kyrremann commented Jan 28, 2022

Maybe something for a new issue, but view-mode buffers that spawn a child process doesn't kill the process when you close the buffer.

So adding view-mode to the buffer that is spawned when you tail logs or port-forward, makes it so that you need to kill the process-buffer manually (M-x list-process and then tab on the line with the process, then you end up in a buffer that you kan kill with C-k).

A compromise may be to turn on read-only-mode, so that you at least don't start typing in the buffer 🤔

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

No branches or pull requests

4 participants