okraits / j4-make-config

Universal theme switcher and config generator for the i3 wm
http://www.okraits.de/index.php?section=projects&page=j4-make-config
185 stars 22 forks source link

More flexibility with config-blocks (i.e. more than just the two) #17

Open D-Vaillant opened 6 years ago

D-Vaillant commented 6 years ago

I've been implementing this at https://github.com/D-Vaillant/j4-make-config/tree/class but I wanted to have a forum for design feedback. For the sake of efficiency I've chosen to force all of the config block markers start with # $i3- (fixed in the PREFIX variable) so that we can pluck them out by just checking for PREFIX in line.

Some thoughts:

lasers commented 6 years ago

My thoughts.

EDIT: P.S. I looked at your class branch.

class: ./j4-make-config --list-themes
Traceback (most recent call last):
  File "./j4-make-config", line 320, in <module>
    printThemeList()
NameError: name 'printThemeList' is not defined
D-Vaillant commented 6 years ago

Oh, the class branch is a nightmare factory right now. The commits I just pushed make it work without immediately breaking but I haven't even really tested it with non-standard block names.

The ability to let people add multiple #'s is a good idea. I was thinking of using split('#'). Something like:

def foo(name="\t\t###!### $my-prefixfooblockcfgname"):
    # we can use a try/except block to filter out lines without the prefix
    head, blockconfigname = name.split(PREFIX)  # =["\t\t###!###", "fooblockcfgname"]
    # we can throw in an try/except block here to check if we don't have a '#'
    whitespace, tail = head.split('#')  # =["\t\t", a mess of strings]
    tail = '#' + ''.join(tail)

Right now it doesn't distinguish between the leading whitespace and any other leading character, so additional #'s end up commenting out the block. And this might break if someone uses PREFIX more than once in a line (which they shouldn't, but when it happens it just moves on.) It shouldn't be a difficult change for the # thing but it's fairly low priority for me right now.

I like the idea of preserving the block headers so I just added them back in. This has the upside of preserving any line that looks like a block header but doesn't have any blocks associated with it.

I changed the prefix in line to line.startswith(prefix) for j4Config. Makes more sense, cleaner.

lasers commented 6 years ago

@okraits ?

okraits commented 6 years ago

I'm busy right now with RL and other projects but I'm trying to have a look in the next days.