dbordak / telephone-line

A new implementation of Powerline for Emacs
GNU General Public License v3.0
554 stars 51 forks source link

Centering segments in telephone-line mode #53

Closed ogdenwebb closed 6 years ago

ogdenwebb commented 6 years ago

I like the way of polybar in this regard: it provides modules-[left, center, right] variables to place there your modules(segments in terms of telephone-line) and this frees the user from unnecessary fuss. Besides telephone line has only telephone-line-lhs and telephone-line-rhs. Is it even possible to center some segment without tweaking the package from your side?

Would you add an extra center/middle variable?

dbordak commented 6 years ago

This might be possible, but it'd be pretty difficult. I've been considering it, but I was never really sure if there was much of a demand for this, besides the fact that it probably wouldn't work too well with an lhs+rhs.

Consider, any time any of the center-aligned segments changes length, they all move. With lhs/rhs, you sorta sort them in priority order -- only the buffer name and minor modes tend to change locations.

If you want it, though, I'll see if it'd be possible

ogdenwebb commented 6 years ago

Yeah, I really want to get this one. Even if centering doesn't stack well with lhs and rhs, an user can create only centered segments(if I understand your note about lhs+rhs correctly).

Consider, any time any of the center-aligned segments changes length, they all move.

Probably we need ability to create fixed-length segments in this case.

I don't know how much it will useful, but powerline for Emacs has ability to centering elements powerline-themes.el#L146

dbordak commented 6 years ago

Ok, it's very rough, but I think I've got this working centering-demo

It isn't documented yet, so here's how you can use it:

(setq telephone-line-center
        '((segment pairs...)
          center
          (segment pairs...)))

You need to put a center keyword in the middle (bare -- don't put it in a pair like everything else, this is no longer a proper alist) to mark where it switches from using right-separators to left-separators (left-right is reversed for appearance)

dbordak commented 6 years ago

Things that don't work:

There's no concept of a center subseparator; there's nothing put where the 'center keyword shows up. You can see that in the example above between 0 and NO. I'm not going to add anything here, however; I think a space should be fine (otherwise, you can probably add your own graphic if you need -- it's not something I think I should automate anyway).

The center keyword doesn't necessarily end up in the center of the screen; the entire center supersegment will be centered, yes, but the left and right halves can be of any length; to center them, they'd need to be equal. I'm also not going to try to change this because forcing centering on the keyword would mean the supersegment isn't centered on unequal halves, which is just as bad.

EDIT: Basically, imagine you have length-4 stuff before the center keyword, and length-2 after it. I could handle it like this: |..<****|**>..| or like this: |.<****|**>...|

In the former case, the entire <*|*> is centered, though the middle bar is not, and in the latter it's the opposite. I went with the former.

dbordak commented 6 years ago

Right, and to give you a full example, here's what I had to generate the center in that screenshot above:

(setq telephone-line-center
        '((nil    . (telephone-line-misc-info-segment))
          (accent . (telephone-line-major-mode-segment))
          (evil   . (telephone-line-airline-position-segment))
          center
          (evil   . (telephone-line-evil-tag-segment))
          (accent . (telephone-line-vc-segment
                     telephone-line-erc-modified-channels-segment
                     telephone-line-process-segment))
          (nil    . (telephone-line-simple-minor-mode-segment
                     telephone-line-narrow-segment
                     telephone-line-simple-buffer-info-segment
                     telephone-line-simple-buffer-name-segment))))
dbordak commented 6 years ago

I'm going to change the 'center keyword thing because it's a bit too magic. Either telephone-line-center will be a cons of the left and right halves of the center, or I'll split it into telephone-line-center-lhs and telephone-line-center-rhs. Opinion?

The latter would make it easier to customize in customize, but the former would probably internally be a cleaner interface. I think the latter is more idiomatic though?

ogdenwebb commented 6 years ago

Awesome. :+1:

In the former case, the entire <|> is centered, though the middle bar is not, and in the latter it's the opposite. I went with the former.

Yes, the former is better for me too.

I'll split it into telephone-line-center-lhs and telephone-line-center-rhs. Opinion?

Imagine we have center-lhs and center-rhs, how to align only one segment in this case? If center-lhs and center-rhs will work with one segment, it's okay in my opinion. But as a user I want to put my segment in some variable and forget about them, i.e. I find their customization with two part of center segment a bit annoying. Not sure about customize, because I'm not using that.

dbordak commented 6 years ago

Doing one segment, regardless of which method I use, is going to be ugly no matter what. You'll need to mirror it with a nil segment of the same color on the other side (this includes what I have right now -- you'd need to put a nil segment before/after the 'center). I have to do this so that there's some way of inserting two types of separators -- any way of automating that would be extremely complicated and magic, I think.

dbordak commented 6 years ago

Oh right, that said, if you're not using a separator, or if your single centered segment is using nil for its color, then there's no need to mirror it.

dbordak commented 6 years ago

I've decided on using telephone-line-center-(l/r)hs. I figure since it wasn't obvious to you that you (almost always) need both, it's better to make it more explicit that way. Doing a pair makes it somewhat more hidden.

ogdenwebb commented 6 years ago

I figure since it wasn't obvious to you that you (almost always) need both

I don't oppose using telephone-line-center-(l/r)hs, but it was a bit kinky at first glance. Now I can accept this. I mean no difference between just a single segment and segment with an extra segment for alignment in fact.

Though customization of segments is taking up a lot of time, so there's no point for me to be bothered about this split.

dbordak commented 6 years ago

Well, the other thing is that keeping it this way means that customizing the center is as similar as possible to customizing the left and right. The first solution was an improper alist, which I don't like, and the other option was a pair of alists, which I think requires more explanation than the whole lhs/rhs thing.

Anyway, once the latest commit is up on MELPA, you should be good to go, I think.

dbordak commented 6 years ago

Looks like it's up. Tell me when you try it out!

ogdenwebb commented 6 years ago

b3eaf4b works without any troubles for me. Thank you for your work! Also I'm glad that it works directly as telephone-line-lhs/rhs. :champagne:

p.s. What's your Emacs font?

dbordak commented 6 years ago

p.s. What's your Emacs font?

Iosevka, it's my favorite font https://be5invis.github.io/Iosevka/