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

feat(app): add Go Back and Last View #2799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tyzbit
Copy link
Contributor

@tyzbit tyzbit commented Jul 19, 2024

Go Back walks back through the history until at the oldest saved view

Last View switches between the current and previous views like how "cd -" works

@tyzbit tyzbit changed the title feat(app): add Previous View and Go Back feat(app): add Go Back and Last View Jul 19, 2024
@tyzbit tyzbit force-pushed the tyzbit/quick-return branch 2 times, most recently from be13aa3 to f6bff90 Compare July 19, 2024 04:07
@tyzbit tyzbit marked this pull request as draft July 19, 2024 15:33
@tyzbit tyzbit marked this pull request as ready for review July 19, 2024 15:49
@tyzbit tyzbit marked this pull request as draft July 19, 2024 18:28
@tyzbit tyzbit marked this pull request as ready for review July 19, 2024 20:31
@tyzbit
Copy link
Contributor Author

tyzbit commented Aug 5, 2024

Closes #1786 and #869

Features from these requests not included are:

  • It is not possible to go forward again through the history. If you go back, the very last view you were on is removed from the history. - doesn't remove anything from history, just rearranges it.
  • There is no overview to let you see the history and pick a specific view from it.

This PR implements the most powerful parts of the feature requests. Better navigation and richer history could be added later while keeping this functionality intact.

Supersedes #1090

internal/view/app.go Outdated Show resolved Hide resolved
internal/view/app.go Outdated Show resolved Hide resolved
@KevinGimbel
Copy link

Tested the feature locally and I have some questions:

  • When I look at containers (Select Pod -> Enter) I cannot go back to the pods with - or b
  • Same when using Describe (d)

Is this intended? I assume these "views" are somehow different from the generic Object views (Pod, StatefulSet, Deployment, ...)?

In general I really like this feature! Especially - seems useful! Thank you @tyzbit!

@tyzbit
Copy link
Contributor Author

tyzbit commented Aug 7, 2024

I would defer to someone more familiar with the codebase but Views seem to correlate mostly with Kubernetes resources (with the exception of contexts). Maybe the most accurate way to define them is the screens you get when you use a command (e.g. :pods).

When you dive into a resource, you get a trail of breadcrumbs at the bottom.

image

For demonstration, I went to pods, namespaces and then deployments and then selected a Deployment and hit Enter to go to the Pod, then hit enter again to go to the container, then I checked the cmdHistory:

image

k9s doesn't add breadcrumb-related navigation to the command history at the present time.

In terms of addressing the difference in expectations, maybe I could update the documentation and help to clarify that Go Back and Last View only work with k8s resources and contexts?

@KevinGimbel
Copy link

In terms of addressing the difference in expectations, maybe I could update the documentation and help to clarify that Go Back and Last View only work with k8s resources and contexts?

I think that's a good idea, just to make it clear what to expect from the feature 👍

@tyzbit
Copy link
Contributor Author

tyzbit commented Aug 9, 2024

I updated the README.

@KevinGimbel
Copy link

Thanks!

One tiny remark:

Your commit changed all * to - for lists - I assume some plugin or editor configuration on your side is making these changes? It makes reviewing the actual code changes hard, and I wonder if future changes will revert this due to different editor configs.

My 2ct would be to revert these style-changes so only the new documentation is added, but I guess @derailed has the final call here :)

Go Back walks back through the history until at the oldest saved view

Last View switches between the current and previous views like how "cd -" works
@tyzbit
Copy link
Contributor Author

tyzbit commented Aug 12, 2024

@KevinGimbel those formatting changes were not intentional, I've changed my settings so it doesn't happen again. While I was at it, I squashed my commits.

@KevinGimbel
Copy link

@tyzbit thank you! Looks good to me now. @derailed in my opinion this could be added to the next released :)

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyzbit Nice work! Good concept. Just a few items to clean up and simplify.

@@ -355,6 +355,8 @@ K9s uses aliases to navigate most K8s resources.
| To view and switch to another Kubernetes context (Pod view) | `:`ctx⏎ | |
| To view and switch directly to another Kubernetes context (Last used view) | `:`ctx context-name⏎ | |
| To view and switch to another Kubernetes namespace | `:`ns⏎ | |
| To switch between the last active view/command (like how "cd -" works) | `-` | Navigation that adds breadcrumbs to the bottom are not commands |
| To go back through previous views/commands | `b` | Same as above |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 'b' is already in use in some views aka to run benchmarks ;(
Perhaps we can use '-' as the last 2 cmd toggle as you have here but then useuse '<' and '>' to nav the command history?

@@ -691,6 +693,54 @@ func (a *App) helpCmd(evt *tcell.EventKey) *tcell.EventKey {
return nil
}

// previousView returns to the view prior to the current one in the history
func (a *App) previousView(evt *tcell.EventKey) *tcell.EventKey {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be named previousCmd to avoid confusion

return evt
}
cmds := a.cmdHistory.List()
if !(len(cmds) > 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dialog here feels a bit heavy, I think best to use a flash for this instance.
Also not keen on !(len(cmds) > 1. This is len(cmds) <=1 return.
But... as noted below better to defer these calls to cmdHistory.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally all these should be on cmdHistory apis. ie the logic for toggle last view and fwd/backwd should be methods on the history and not view logic imho i.ie toggleLastCmd, prevCmd, nextCmd, etc..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally if we surfaced a cmdHistory view all the necessary apis would be already there.

}

// lastView switches between the last view and this one a la `cd -`
func (a *App) lastView(evt *tcell.EventKey) *tcell.EventKey {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above these are commands and not views since sub-views are not part of the cmd history.

if len(n) > 1 {
// only one argument is expected
return false
} else if len(n) == 1 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are done here no need for the else clause.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not keen on the vararg with only one option. Best to leave Pop as such and introduce PopN(n int)

@derailed derailed added enhancement New feature or request question Further information is requested labels Aug 15, 2024
@tyzbit
Copy link
Contributor Author

tyzbit commented Sep 13, 2024

Thank you for the great feedback. I'm working on addressing the comments; some planned changes:

  • Navigate history with [ and ] instead of B (I prefer this over < and > because it is not necessary to hold shift)
  • Add a view to see your history visually and pick a specific point in the history to go to. I think this will aid greatly in training users in using the new features.
  • cmdHistory will keep a more accurate history of your commands such as saving the last command used as well as the current command (therefore duplicates are possible and the assumption that history[0] is the current command will be broken, requiring some other updates)

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

Successfully merging this pull request may close these issues.

3 participants