<commit_before>""" Module "Helper" : Helper functions and classes

    Contains classes and functions for wrapping text, task modification status,
    text menus, date-time etc.
"""

# Standard Library Imports
import time
import curses
from datetime import datetime, timedelta
from dateutil import tz, relativedelta

# Custom Module Imports

import config as C
from screen import Screen
import global_objects as G
import debug as DEBUG
import content as CT
import menu as M


class Status(object):

    def __init__(self, task_type, checklist=[0, 0], due=''):
        if task_type == "habit":
            self.attributes = C.HabitStatus.copy()
        elif task_type == "habitpos":
            self.attributes = C.HabitPosStatus.copy()
        elif task_type == "habitneg":
            self.attributes = C.HabitNegStatus.copy()
        elif task_type == "checklist":
            self.attributes = C.ChecklistStatus.copy()
        else:
            self.attributes = C.TODODailyStatus.copy()
        self.checklist = checklist
        self.due = due
        self.x = 0
        self.y = 0
        self.newItem = False

    def ReturnLenString(self):
        length = 2*len([i for i in self.attributes if self.attributes[i]!=None])
        length-=2 #Deletion attribute is not shown in status line (represented with strikethrough)
        if self.checklist[1] != 0:
            # (Done/Total) - 4 extra symbols - '(', ')', '/' and a space
            length += 5 + len(str(self.checklist[0])) + len(str(self.checklist[1]))

        if self.due!='':
            length += len(self.due) + 3 # To account for a space

        return length

    def SetXY(self, x=0, y=0):
        self.x = x
        self.y = y

    def SetChecklist(self, checklist):
        self.checklist = checklist

    def SetDue(self, due):
        self.due = due

    def Display(self):
        X, Y = self.x, self.y

        if self.checklist[1] != 0:
            display_string = '('+str(self.checklist[0])+'/'+str(self.checklist[1])+')'
            Y -= (len(display_string))
            display_string = C.SYMBOL_DOWN_TRIANGLE + display_string
            G.screen.Display(display_string,X, Y,
                                            color=C.SCR_COLOR_LIGHT_GRAY, bold=True)
            Y -= 2

        if self.due != '':
            Y -= (len(self.due) + 1)
            G.screen.Display(C.SYMBOL_DUE + " " + self.due, X, Y,
                    color=C.SCR_COLOR_LIGHT_GRAY, bold=True)
            Y -= 2

        for (key, value) in self.attributes.items():
            if key == C.SYMBOL_DELETE:
                #Deletion status is shown with strikethrough, not needed here
                continue

            if value != None:
                if value:
                    G.screen.Display(key, X, Y,
                            color=C.SCR_COLOR_YELLOW, bold=True)
                else:
                    G.screen.Display(key, X, Y,
                            color=C.SCR_COLOR_DARK_GRAY, bold=True)
                Y -= 2

    def ToggleMarkUp(self):
        # Return if there is no up direction, or the delete option has already
        # been enabled or the edit status is true
        if ((not self.attributes.has_key("+")) or
            self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        if self.attributes["+"]:
            self.attributes["+"] = False

        else:
            # Only one of "-" and "+" can be activated at a time
            self.attributes["-"] = False
            self.attributes["+"] = True

    def ToggleMarkDown(self):
        # Return if there is no down direction, or the delete option has already
        # been enabled or the edit status is true
        if ((not self.attributes.has_key("-")) or
            self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        if self.attributes["-"]:
            self.attributes["-"] = False

        else:
            # Only one of "-" and "+" can be activated at a time
            self.attributes["+"] = False
            self.attributes["-"] = True

    def ToggleMark(self):
        # Return if the delete option has already been enabled or the edit
        # status is true
        if (self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        if self.attributes[C.SYMBOL_TICK]:
            self.attributes[C.SYMBOL_TICK] = False
        else:
            self.attributes[C.SYMBOL_TICK] = True

    def ToggleDelete(self):
        # Nothing can be enabled along with delete
        for key in self.attributes:
            if key != C.SYMBOL_DELETE:
                self.attributes[key] = False

        if self.attributes[C.SYMBOL_DELETE]:
            self.attributes[C.SYMBOL_DELETE] = False
        else:<commit_msg>Fixed a bug where unidirectional habits were getting new directions added<commit_after>""" Module "Helper" : Helper functions and classes

    Contains classes and functions for wrapping text, task modification status,
    text menus, date-time etc.
"""

# Standard Library Imports
import time
import curses
from datetime import datetime, timedelta
from dateutil import tz, relativedelta

# Custom Module Imports

import config as C
from screen import Screen
import global_objects as G
import debug as DEBUG
import content as CT
import menu as M


class Status(object):

    def __init__(self, task_type, checklist=[0, 0], due=''):
        if task_type == "habit":
            self.attributes = C.HabitStatus.copy()
        elif task_type == "habitpos":
            self.attributes = C.HabitPosStatus.copy()
        elif task_type == "habitneg":
            self.attributes = C.HabitNegStatus.copy()
        elif task_type == "checklist":
            self.attributes = C.ChecklistStatus.copy()
        else:
            self.attributes = C.TODODailyStatus.copy()
        self.checklist = checklist
        self.due = due
        self.x = 0
        self.y = 0
        self.newItem = False

    def ReturnLenString(self):
        length = 2*len([i for i in self.attributes if self.attributes[i]!=None])
        length-=2 #Deletion attribute is not shown in status line (represented with strikethrough)
        if self.checklist[1] != 0:
            # (Done/Total) - 4 extra symbols - '(', ')', '/' and a space
            length += 5 + len(str(self.checklist[0])) + len(str(self.checklist[1]))

        if self.due!='':
            length += len(self.due) + 3 # To account for a space

        return length

    def SetXY(self, x=0, y=0):
        self.x = x
        self.y = y

    def SetChecklist(self, checklist):
        self.checklist = checklist

    def SetDue(self, due):
        self.due = due

    def Display(self):
        X, Y = self.x, self.y

        if self.checklist[1] != 0:
            display_string = '('+str(self.checklist[0])+'/'+str(self.checklist[1])+')'
            Y -= (len(display_string))
            display_string = C.SYMBOL_DOWN_TRIANGLE + display_string
            G.screen.Display(display_string,X, Y,
                                            color=C.SCR_COLOR_LIGHT_GRAY, bold=True)
            Y -= 2

        if self.due != '':
            Y -= (len(self.due) + 1)
            G.screen.Display(C.SYMBOL_DUE + " " + self.due, X, Y,
                    color=C.SCR_COLOR_LIGHT_GRAY, bold=True)
            Y -= 2

        for (key, value) in self.attributes.items():
            if key == C.SYMBOL_DELETE:
                #Deletion status is shown with strikethrough, not needed here
                continue

            if value != None:
                if value:
                    G.screen.Display(key, X, Y,
                            color=C.SCR_COLOR_YELLOW, bold=True)
                else:
                    G.screen.Display(key, X, Y,
                            color=C.SCR_COLOR_DARK_GRAY, bold=True)
                Y -= 2

    def ToggleMarkUp(self):
        # Return if there is no up direction, or the delete option has already
        # been enabled or the edit status is true
        if ((not self.attributes.has_key("+")) or
            self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        #If it's already marked, unmark it
        if self.attributes["+"]:
            self.attributes["+"] = False

        else:
            self.attributes["+"] = True
            # Only one of "-" and "+" can be activated at a time
            if(self.attributes.has_key("-")):
                self.attributes["-"] = False

    def ToggleMarkDown(self):
        # Return if there is no down direction, or the delete option has already
        # been enabled or the edit status is true
        if ((not self.attributes.has_key("-")) or
            self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        #If it's already marked, unmark it
        if self.attributes["-"]:
            self.attributes["-"] = False

        else:
            self.attributes["-"] = True
            # Only one of "-" and "+" can be activated at a time
            if(self.attributes.has_key("+")):
                self.attributes["+"] = False

    def ToggleMark(self):
        # Return if the delete option has already been enabled or the edit
        # status is true
        if (self.attributes[C.SYMBOL_DELETE] or
            self.attributes[C.SYMBOL_EDIT]):
            return

        if self.attributes[C.SYMBOL_TICK]:
            self.attributes[C.SYMBOL_TICK] = False
        else:
            self.attributes[C.SYMBOL_TICK] = True

    def ToggleDelete(self):
        # Nothing can be enabled along with delete
        for key in self.attributes:
            if key != C.SYMBOL_DELETE:
                self.attributes[key] = False

        if self.attributes[C.SYMBOL_DELETE]:
            self.attributes[C.SYMBOL_DELETE] = False
        else:
{'fraction_non_alphanumeric': 0.10567632850241546, 'fraction_numerical': 0.004629629629629629, 'mean_word_length': 1.8407661520869067, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6479236', 'n_tokens_mistral': 2903, 'n_tokens_neox': 2760, 'n_words': 813}