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: add initial session name to layout template #789

Merged
merged 9 commits into from
Nov 8, 2021
Merged

feat: add initial session name to layout template #789

merged 9 commits into from
Nov 8, 2021

Conversation

jaeheonji
Copy link
Member

@jaeheonji jaeheonji commented Oct 15, 2021

This PR resolve #611

proposal

---
session:
  - name: "SESSION_NAME"
template:
  ...
tabs:
  ...

Instead of using session_name, a session structure is used. (for future scalability)

expected results

  1. When Zellij is launched (with layouts), the session name is initialized to the name in the layouts.
  2. When the -s flag and layouts are used together (like zeliij -s SOMTHING --layout-path SOME.yaml), the flag of session name takes a priority.

@imsnif imsnif requested a review from a-kenji October 18, 2021 08:53
@jaeheonji jaeheonji marked this pull request as ready for review October 21, 2021 10:47
@jaeheonji
Copy link
Member Author

I tried to implement the functionality as simple as possible. If this is ok, I'll add an e2e test.

@jaeheonji jaeheonji changed the title draft: add initial session name to layout template feat: add initial session name to layout template Oct 21, 2021
Copy link
Contributor

@a-kenji a-kenji left a comment

Choose a reason for hiding this comment

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

Thank you for taking the time submitting this pr!
This is already pretty good.

For now when we start a session with a name, then detach, and then start it again.
We get an error message.

 Use attach command to connect to it or specify a different name.

I would personally prefer if either we could have an option to reattach or not
while already starting with the layout, or at least have the reattach the default option.
What do you think?

zellij-utils/src/input/layout.rs Outdated Show resolved Hide resolved
@jaeheonji
Copy link
Member Author

@a-kenji thank you for your review :)

That part I didn't even think of! I totally agree your opinion.
so, I'll proceed as follows:

---
session:
  name: 'SESSION_NAME'
  attach: true # default `true`. If session exists, re-attach.

@a-kenji
Copy link
Contributor

a-kenji commented Oct 25, 2021

@jaeheonji
This would look good to me!

@jaeheonji
Copy link
Member Author

@a-kenji

While developing for attach option, I suddenly had the following thoughts. I'm wondering about your opinion on this.

The layout system is responsible for setting the default UI when Zellij is startup. and The role of attach is to attach to an existing session.

Here, my sudden thought is that it makes more sense(natural) to use the attach command than to put the attach option in the layout.

Because, accessing an existing session through the attach option in the layout file seems to fade the meaning of the rest of the settings in the layout file (like tab, plugins etc..).

Sorry for the sudden change of opinion, but I'd like to ask your opinion on this 😄

@a-kenji
Copy link
Contributor

a-kenji commented Oct 26, 2021

Hey! While that is certainly true for now, the goal is merging the config file with the layout file in order to make it possible specifying any option on loading the layout. That of course can also just be the layout.

I agree it would make the existing configuration of plugins pointless for that session, but because it already is running with that name I think it is safe to assume most of the layout, if not all would already be running.

@jaeheonji
Copy link
Member Author

Oh.. Thank you for solving my question. The purpose seems to have become clearer :)

@a-kenji
Copy link
Contributor

a-kenji commented Oct 28, 2021

@jaeheonji
Thank you for the work!
There is still one little inconsistency:
When creating a new session with the -s flag we now attach to an existing
session instead of getting the error.

Apart from that I believe everything does work as expected!

@jaeheonji
Copy link
Member Author

Thanks for review! @a-kenji
I have a schedule today, so I'll update the part you informed me by tomorrow :)

* attach option only works when layout template exists.
@jaeheonji
Copy link
Member Author

jaeheonji commented Nov 1, 2021

@a-kenji I updated attach options to work only when there is a layout template argument.

And as the main function has more functions, the code seems to be massive. It seems that refactoring is necessary in the future.

EDIT: releated to #824

@a-kenji
Copy link
Contributor

a-kenji commented Nov 1, 2021

@jaeheonji
This is still a little off from the desired behavior, but very close.
I think rather than check for the layout template argument,
you rather want to check where the layout name is coming from,
since you should be able to create a session, with a name,
and a layout path argument.

Thanks for the great work!
And I agree the main function is in need for some maintenance soon.

@jaeheonji
Copy link
Member Author

jaeheonji commented Nov 1, 2021

@a-kenji Ok! I didn't understand.
Then, let's take a look at the overall flow for confirmation once again.

  • -s options always have priority, so If a name is given through the -s option, a session is created with that name. Also, it ignores the attach condition of the layout. (therefore, if the name already exists, an error is displayed.)

  • If there is no -s option, the name of the layout is checked.

    • If the name of the layout does not exist or the layout itself does not exist, a session is created with a random name.
    • If the layout has a name:
      • If a session with the same name already exists, it connects to the session or displays an error according to the attach option in layout. (the default of attach is true)
      • Otherwise, create a session with the name of the layout.

Is this the behavior we expect?

@a-kenji
Copy link
Contributor

a-kenji commented Nov 1, 2021

@jaeheonji
Yes, that is exactly the behavior I think we would expect!
Sorry for not being clearer before!

@jaeheonji
Copy link
Member Author

Good! We all don't have to be sorry :)

If the above is implemented, the length of the code will be longer and there will be many overlapping parts. (probably there will be many flows)

So, I'll try the implementation once with refactoring.

@a-kenji
Copy link
Contributor

a-kenji commented Nov 1, 2021

@jaeheonji
Just a heads up, in #829 there is a refactor of the main function already.
Do you wish to base upon that refactor?
It seems to make things much clearer.

@jaeheonji
Copy link
Member Author

@a-kenji
That would be good. (I have now confirmed that #829 is going on.)

The work on #829 is exactly what I was looking for. After the refactoring is done, it would be nice to implement it in that code base.

@ken-matsui
Copy link
Contributor

Thank you all so much for considering using my refactor. It still has a bit confusing parts, so I really would welcome your suggestion!

@jaeheonji
Copy link
Member Author

@a-kenji

I added features (#789 (comment)) from the latest sources (refactored). please could you do a review?

Copy link
Contributor

@a-kenji a-kenji left a comment

Choose a reason for hiding this comment

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

LGMT!

@a-kenji
Copy link
Contributor

a-kenji commented Nov 8, 2021

@jaeheonji,
thank you for keeping at it!
This looks great now I think.

@a-kenji a-kenji merged commit 4838f0b into zellij-org:main Nov 8, 2021
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.

Add session_name to layouts
3 participants