displays = {}
windows = {}
tabs = {}

class Display:
    def __init__(self, uuid):
        self.uuid = uuid
        self.connections = [] # maybe set()?
        self.windows = [] # maybe set()?
    
    def attach(self, connection):
        self.connections.append(connection)

    def detach(self, connection):
        self.connections.remove(connection)

class Window:
    def __init__(self, uuid,
            title = "__unnamed__",
            grid_column = (0, 0),
            grid_row = (0, 0)):
        self.uuid = uuid
        self.title = title

        self.grid_column = grid_column
        self.grid_row = grid_row

        self.parents = set()

        self.tabs = [] # Maybe set()?

    def set_title(self, title):
        self.title = title
        # TODO: PUSH TITLE CHANGE
    
    def set_grid_column(self, grid_column):
        self.grid_column = grid_column
        # TODO: PUSH CHANGE
    
    def set_grid_row(self, grid_row):
        self.grid_row = grid_row
        # TODO: PUSH CHANGE
    
    def add_tab(self, tab):
        self.tabs.append(tab)
        # TODO: PUSH CHANGE
    
    def remove_tab(self, tab):
        self.tabs.remove(tab)
        # TODO: CHECK REF COUNT AND FREE IF 0
        # TODO: PUSH CHANGE

class Tab:
    def __init__(self, uuid,
            title = "__unnamed__"):
        self.uuid = uuid
        self.content = ""

    def clear(self):
        self.content = ""
        # TODO: PUSH CHANGE

    def write_ln(self, data):
        self.write(data + "\n")

    def write(self, data):
        self.content += data
        # TODO: PUSH CHANGE

    def write_index(self, data, cursor): # Maybe also send snippet of before and after incase of multiedit?
        self.content = self.content[:cursor] + data + self.content[cursor:]
        # TODO: PUSH CHANGE