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

Deduplicate code in zellij-server screen #1453

Merged
merged 2 commits into from
Jun 13, 2022

Conversation

har7an
Copy link
Contributor

@har7an har7an commented Jun 3, 2022

Hi,

this is an attempt to deduplicate the code for Screen in zellij-server. It's made up of three distinct "improvements" (if I didn't mess up the partial adds, mind):

  1. 4b5c63e Replaces the following code blocks:
                screen
                    .bus
                    .senders
                    .send_to_server(ServerInstruction::UnblockInputThread)
                    .unwrap();
    with a new function:
                screen.unblock_input();
  2. 9c2e0ef deduplicates the following constructs:
                        if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
                            active_tab.new_pane(pid, Some(client_id));
                        } else {
                            log::error!("Active tab not found for client id: {:?}", client_id);
                        }
    with a new macro:
                        active_tab!(screen, client_id, |tab: &mut Tab| tab
                            .new_pane(pid, Some(client_id)));
  3. Is a small change and consists of moving screen.render() to the bottom of the inner loop after the match, so it is always executed by those match arms that don't explicitly "opt-out" (by calling continue).

I hope that this aids the codes readability. Happy to take any feedback you can give me!

zellij-server/src/screen.rs Outdated Show resolved Hide resolved
@har7an
Copy link
Contributor Author

har7an commented Jun 7, 2022

Also I read in one of the previously existent comments that screen.update_tabs() calls screen.render() eventually, which is why I added a continue after every update_tabs(). Is this really the case or has this changed in the meantime?

@jaeheonji jaeheonji self-requested a review June 7, 2022 08:34
@har7an har7an force-pushed the feature/refactor-server-screen branch from 7b10993 to cdf3e93 Compare June 7, 2022 08:39
@har7an
Copy link
Contributor Author

har7an commented Jun 7, 2022

@jaeheonji I fixed the merge conflicts, could you restart the pipelines, please?

Also I hope I didn't miss any of the newly added commands...

@har7an
Copy link
Contributor Author

har7an commented Jun 13, 2022

Hey @a-kenji could you maybe have a look at these changes? @imsnif seems to be busy and due to the many modifications to screen.rs I fear that soon I will miss a change when rebasing...

which is a convenience function to send the `UnblockInputThread` signal
to the zellij server.
as a convenience macro that attempts to get the currently active tab. If
the tab is found, it executes a closure (passed by the caller) on this
tab. Otherwise, a standardized error message is printed to the error
log.

This standardizes and deduplicates the loads of:

```
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
    active_tab.$FUNCTION(...);
} else {
    log::error!("Active tab not found for client id: {:?}", client_id);
}
```

previously present in the code.
@har7an har7an force-pushed the feature/refactor-server-screen branch from cdf3e93 to f949cb9 Compare June 13, 2022 10:23
@imsnif
Copy link
Member

imsnif commented Jun 13, 2022

Hey @har7an ! The third refactor (with the render) while very important both for readability and even performance, is not necessarily a trivial one. Maybe it is, but there's quite some hidden and implied behaviour around when and how many times we render.

I'd definitely like to address that part separately. Since I'm going on vacation for a couple of weeks now - how about we separate that particular piece out and go ahead with the first two refactors if @jaeheonji think they're good? (I haven't looked through the code myself)

Then we can potentially tackle the rendering as a separate issue (and I think we can even include some more performance and readbility optimizations there).

@har7an
Copy link
Contributor Author

har7an commented Jun 13, 2022

The third refactor (with the render) while very important both for readability and even performance, is not necessarily a trivial one. Maybe it is, but there's quite some hidden and implied behaviour around when and how many times we render.

Humm, I was suspecting there's more to it. :)
I mean I wrote it such that it doesn't change the status quo except that I removed all calls to render when there is an update_tabs before it. But I will leave that decision to you, since you're the one responsible for the code and won't be here to extinguish any fires it causes. ;)

Since I'm going on vacation for a couple of weeks now - how about we separate that particular piece out and go ahead with the first two refactors

That's fine by me. I understand that you will want to have a look at the rendering mechanism first before you make any decisions regarding that? In this case I won't be looking at it any further until you return.

In the meantime if you know of some other files that contain amounts of repetition similar to screen.rs I could offer to have a stab at these as well.

@har7an har7an force-pushed the feature/refactor-server-screen branch from f949cb9 to 929d93d Compare June 13, 2022 14:42
@har7an
Copy link
Contributor Author

har7an commented Jun 13, 2022

@imsnif I dropped the third commit, I have it stashed locally in case we want to come back to it some day.

Enjoy your vacation!

@jaeheonji
Copy link
Member

@imsnif Thank you for your commenting! Good. At this point, I think it would be better to proceed with only the previous two refactorings. (Hope you have a nice vacation 😉)

@har7an Thank you for your efforts :) I will merge as soon as CI is completed.

@jaeheonji jaeheonji merged commit 13d9110 into zellij-org:main Jun 13, 2022
@har7an har7an deleted the feature/refactor-server-screen branch October 23, 2022 15:34
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.

3 participants