diff --git a/CHANGELOG.md b/CHANGELOG.md index 72ea801..3c99d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ Changes: * Render global 7tv emotes * Show tooltip with emote's name when hovering over it +* Clickable urls(#47) diff --git a/hasherino/components/chat_message.py b/hasherino/components/chat_message.py index 3d6d1ec..a63d162 100644 --- a/hasherino/components/chat_message.py +++ b/hasherino/components/chat_message.py @@ -1,6 +1,7 @@ from abc import ABC import flet as ft +import validators from hasherino.hasherino_dataclasses import Emote, Message from hasherino.pubsub import PubSub @@ -11,9 +12,16 @@ async def on_font_size_changed(self, new_font_size: int): ... -class ChatText(ft.Text, FontSizeSubscriber): +class ChatText(ft.Container, FontSizeSubscriber): def __init__(self, text: str, color: str, size: int, weight=""): - super().__init__(text, size=size, weight=weight, color=color, selectable=True) + try: + is_url = validators.url(text) + except validators.ValidationError: + is_url = False + + color = ft.colors.BLUE if is_url else color + content = ft.Text(text, size=size, weight=weight, color=color, selectable=True) + super().__init__(content=content, url=text) async def on_font_size_changed(self, new_font_size: int): self.size = new_font_size diff --git a/pyproject.toml b/pyproject.toml index 5f888de..e2a24bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ dependencies = [ "keyring == 24.2.0", "flet == 0.15.0", "certifi == 2023.7.22", + "validators == 0.22.0", ] [tool.isort]