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

Add ClearScrollback to replicate macOS Cmd+K behavior #1768

Closed
wants to merge 1 commit into from

Conversation

fcoury
Copy link

@fcoury fcoury commented Oct 1, 2022

Replicates the behavior of the Cmd+K command used on macOS's Terminal.app and iTerm.

Screen.Recording.2022-10-01.at.08.16.02.PM.mp4

Action

The new action is called SoftClear but completely open to a better name.

Example of its usage on a keybinding:

    normal:
        - action: [SoftClear]
          key: [Ctrl: 'k']

Feature Configuration

This PR also adds a new configuration setting soft_clear_offset that allows the user to specify an offset, counted from the top of the screen, of how many additional lines he/she wants to see when performing this soft clear. This overcomes a problem I face with iTerm with the same command, where it trims the first line of my prompt (see below), while retaining a sane default for most uses.

Example of use:

# Configure the soft clear offset
# If you use a prompt with more than one line, you might want to increase this
# value to avoid clearing the prompt when you use the soft clear command.
# Valid values: positive integers
# Default value: 0
soft_clear_offset: 1

And the issue I have today with iTerm that led me to add the new setting above:

Screen.Recording.2022-10-01.at.08.18.47.PM.mp4

Copy link
Member

@imsnif imsnif left a comment

Choose a reason for hiding this comment

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

Hey @fcoury - thank you for your patience!

I'm happy to accept this, but would ask for a few changes:

  1. How about if instead of roll_to_top we clear the viewport and then add canonical lines to it similar to how we initialize it in the constructor (viewport: vec![Row::new(columns).canonical()])? I think that will make things a little clearer
  2. Now that we've added actions through the CLI, let's add this one as well so the user has an immediate interface to it without having to configure it? Something like zellij action soft-clear?
  3. Given 2, I think we can remove the configuration option and add it as a flag to either the CLI or the bound key.
  4. Maybe we can rename the action to clear?

@fcoury
Copy link
Author

fcoury commented Nov 2, 2022

@imsnif not a problem! I'll get right to it as soon as time permits and get back to you!

Thank you!

@fcoury fcoury force-pushed the add-clear-pane-command branch from 61efd5e to 1e246e5 Compare November 5, 2022 19:59
@fcoury
Copy link
Author

fcoury commented Nov 5, 2022

@imsnif just rebased my branch from current main branch and gonna start working on addressing your feedback.

@fcoury fcoury temporarily deployed to cachix November 13, 2022 13:53 Inactive
@calebmeyer
Copy link

I'd love to see this as well!

I would call it Clear Scrollback, since clear already has a meaning in terminal land of "move the prompt to the top so no previous output is showing". This is an action we're taking on the scrollback lines, similar in scope to Edit Scrollback.

@fcoury fcoury force-pushed the add-clear-pane-command branch from 1e246e5 to 48d38c6 Compare March 9, 2023 01:25
@leomeloxp
Copy link

Hi, I just saw the #281 and the comment linking to this PR. You reference this as a soft clear, perhaps I'm confusing myself here but to my memory cmd + K on macOS completely kills the scrollback, resetting it to 0. It's the only difference between this command and Ctrl + L.

Either way, I'd love to be able to use cmd + k when inside of Zellij as it's probably my most used shortcut when working in the terminal. Thanks for getting this PR together.

@fcoury
Copy link
Author

fcoury commented Oct 8, 2023

Hey there @imsnif, finally decided to take another look at solving this. Let me tell you what I found so far:

1. How about if instead of `roll_to_top` we clear the viewport and then add canonical lines to it similar to how we initialize it in the constructor (`viewport: vec![Row::new(columns).canonical()]`)? I think that will make things a little clearer

The problem is that the current prompt is lost if we do that. Here's what the command looks like with the viewport solution you propose:

Resetting viewport:

ResetViewport.mp4

Here we lose our current prompt.

Adding canonical lines:

AddCanonicalLines.mp4

This way our prompt is kept as-is.

Do you think there's a better way to achieve this?

Thanks!

@fcoury fcoury force-pushed the add-clear-pane-command branch from 48d38c6 to 63f36a5 Compare October 8, 2023 22:49
@fcoury fcoury changed the title Add SoftClear action to replicate macOS Cmd+K behavior Add ClearOffset to replicate macOS Cmd+K behavior Oct 8, 2023
@fcoury fcoury requested a review from imsnif October 8, 2023 22:50
@fcoury
Copy link
Author

fcoury commented Oct 8, 2023

@imsnif ready for review 😊

@fcoury fcoury changed the title Add ClearOffset to replicate macOS Cmd+K behavior Add ClearScrollback to replicate macOS Cmd+K behavior Oct 9, 2023
@imsnif
Copy link
Member

imsnif commented Oct 9, 2023

Hey @fcoury - thanks for this, but it has already been implemented: #2239

In the docs: https://zellij.dev/documentation/keybindings-possible-actions#clear

@imsnif imsnif closed this Oct 9, 2023
@fcoury
Copy link
Author

fcoury commented Oct 9, 2023

Hey @fcoury - thanks for this, but it has already been implemented: #2239

In the docs: https://zellij.dev/documentation/keybindings-possible-actions#clear

Hey there, they don't seem to do the same think. This perfectly emulates what happens when you press Cmd+K on macOS.

If this doesn't seem like something we want to support, can it be introduced as a plugin? If so, do you have any examples?

Thank you!

@imsnif
Copy link
Member

imsnif commented Oct 9, 2023

What's the difference?

@fcoury
Copy link
Author

fcoury commented Oct 9, 2023 via email

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

Successfully merging this pull request may close these issues.

4 participants