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

Markers with multiple tasks #312

Open
lambtho12 opened this issue Oct 15, 2021 · 6 comments
Open

Markers with multiple tasks #312

lambtho12 opened this issue Oct 15, 2021 · 6 comments

Comments

@lambtho12
Copy link

In my setup (vit 2.1.0, taskwarrior 2.6.0), I would like to have different markers for different tags, for instance

tag.frog.label = 🐸 
tag.in.label = 📥 
tag.office.label = 💼 

I expect that a task tagged with frog label office would show all three emoji in the marker column. But it appears that tag-related markers only show up if this is the only tag on that task (even if I tag frog foo, the frog emoji will not appear).

Am I missing something here? Is this intended?

@thehunmonkgroup
Copy link
Member

It should work that way. If it's not, please attach an example config, and a modified dummy install script that reproduces the issue, and I'll have a look at it.

@lambtho12
Copy link
Author

lambtho12 commented Oct 18, 2021

Here you go

#!/bin/sh

set -e
set -u

TMP_DIR="$(mktemp --directory --suffix .vit)"
VIT_DIR="$TMP_DIR/vit"
TASK_DIR="$TMP_DIR/task"
TASKRC="$TMP_DIR/taskrc"

echo "
This script will create a dummy TaskWarrior database and VIT configuration.
"
read -p "Press enter to continue... " DUMMY

echo "Creating dummy task configuration..."
mkdir "$TASK_DIR"
cat > "$TASKRC" <<EOT
data.location=$TASK_DIR
EOT
export TASKRC
echo -e "report.next.columns = id,start.age,project,description,urgency\n report.next.labels = ID,Active,Project,Description,Urg" >> "$TASKRC"

echo "Creating dummy VIT configuration..."
mkdir "$VIT_DIR"
touch "$VIT_DIR/config.ini"
echo -e "[marker]\ntag.label= \ntag.frog.label = 🐸\ntag.dog.label = 🐶\ntag.house.label = 🏠" >> "$VIT_DIR/config.ini"

echo "Adding some dummy tasks..."
task add a
task add b
task +LATEST start
task add c
task +LATEST start
task +LATEST modify project:foo
task 1 mod +frog
task 2 mod +frog +dummytag
task 3 mod +frog +dog +house

echo "Complete!

Copy and paste the following two export statements into your current
shell sesison to activate the dummy installation.

export TASKRC=${TASKRC}
export VIT_DIR=${VIT_DIR}

When complete, you can simply exit the current shell session, or copy and paste
the following 'unset' commands to revert the current shell session to the
TaskWarrior/VIT defaults.

unset TASKRC
unset VIT_DIR
"

Here is the result (vit 2.1.0, taskwarrior 2.6.0)
2021-10-18_10-23

@thehunmonkgroup
Copy link
Member

The code that handles setting markers for tags is here: https://github.com/vit-project/vit/blob/2.x/vit/formatter/markers.py#L43-L57

The current logic is like this:

  1. If there's no tags, use tag.none.label
  2. If there's one tag and it has a custom label, use it, otherwise use tag.label
  3. Otherwise, use tag.label

So I think you're misunderstanding the current implementation. Basically, if it has one tag, we can display a custom label, otherwise the label is more meant to signify "this task has tags".

It's possible to adjust the code, but I'm not sure I want to do this. Markers are meant to be simple indications of non-displayed columns, and if you want more detail, then you add that column to the report.

@lambtho12
Copy link
Author

Indeed, I misunderstood the current logic. I will adapt accordingly. Thank you for the detailed explanation.

@thehunmonkgroup
Copy link
Member

In case you didn't know, formatters can be overridden by your own custom formatters.

This means you can override the default Markers class and provide the custom formatting functionality you desire when formatting tag markers.

I took a few minutes and got this working:

from vit.formatter.markers import Markers as MarkersBase

class Markers(MarkersBase):
    def format_tags(self, width, text_markup, tags):
        if not tags:
            color = self.colorizer.tag_none()
            label = self.labels['tag.none.label']
            return self.add_label(color, label, width, text_markup)
        elif len(tags) == 1:
            tag = list(tags)[0]
            color = self.colorizer.tag(tag)
            custom_label = 'tag.%s.label' % tag
            label = self.labels['tag.label'] if not custom_label in self.labels else self.labels[custom_label]
            return self.add_label(color, label, width, text_markup)
        # This is the new logic, the rest is just a copy of the existing
        # format_tags() method.
        elif len(tags) > 1 and not self.labels['tag.label']:
            labels = []
            for tag in list(tags):
                # Last color will be the one used.
                color = self.colorizer.tag(tag)
                custom_label = 'tag.%s.label' % tag
                if custom_label in self.labels:
                    labels.append(self.labels[custom_label])
            label = ''.join(labels)
            return self.add_label(color, label, width, text_markup)
        else:
            color = self.colorizer.tag('')
            label = self.labels['tag.label']
            return self.add_label(color, label, width, text_markup)

You would simply follow the directions at https://github.com/vit-project/vit/blob/2.x/CUSTOMIZE.md#formatters for placing that code into your VIT user directory, the file would live at [VIR_DIR]/formatter/markers.py.

Of course with this method you'd have to track any changes to the format_tags method in the core Markers class if you wanted them, but it does accomplish your immediate goal.

I may yet include that new logic in VIT core, why don't you play with the override version for a bit and see if it works OK?

@lambtho12
Copy link
Author

Awesome! Thank you very much

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

No branches or pull requests

2 participants