Skip to content

Use Hyperlink widget for links in message info popup. #1409

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

theViz343
Copy link
Member

@theViz343 theViz343 commented Jun 11, 2023

What does this PR do, and why?

This PR introduces the Hyperlink widget for message links in message information popups. This solves the issue of long urls being force-wrapped which results in them not being clickable from ZT.

Outstanding aspect(s)

  • The focus on the currently selected link is a bit off. It doesn't cover the link.

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

image

@zulipbot zulipbot added the size: S [Automatic label added by zulipbot] label Jun 11, 2023
@theViz343 theViz343 force-pushed the osc8-hyperlink-support-issue-1368 branch 2 times, most recently from 075b24a to c84a22f Compare June 11, 2023 19:18
@Subhasish-Behera
Copy link
Contributor

Hey @theViz343 ,I am getting the error

 File "/home/subhasishbehera/zulip-terminal/zulipterminal/ui_tools/buttons.py", line 11, in <module>
    import urwidgets
ModuleNotFoundError: No module named 'urwidgets'

@neiljp
Copy link
Collaborator

neiljp commented Jul 8, 2023

@Subhasish-Behera If you're using make then run that and it should check you have the required dependencies, or reinstall the editable zt package over the top (if not using make).

@theViz343 It would be useful to have the dependency change visible as a separate small commit, as we do when we change other requirements.

This commit adds the urwidgets library for including hyperlink support
in ZT using the OSC-8 escape sequence.
This commit introduces the use of the Hyperlink widget from the
Urwidgets library for displaying links in the message information popup.
@theViz343 theViz343 force-pushed the osc8-hyperlink-support-issue-1368 branch from c84a22f to e0e778c Compare July 10, 2023 11:54
Comment on lines +446 to +451
icon = urwid.Pile(
widget_list=[
urwid.SelectableIcon(caption, cursor_position=len(caption) + 1),
urwidgets.Hyperlink(uri=self.link),
]
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the rendering of the link defined in the link button like this would be cleaner, and it may be reasonable to refactor the layout into the button as a prep refactor for this.

However, right now this overall change affects the rendering quite a lot: links are not styled in the same way as the background of the button, or when selected. That makes it difficult to visually identify that the link and number/title are related to the link when many links are present.

I'm not sure if that's a limitation of the Hyperlink?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!

However, right now this overall change affects the rendering quite a lot: links are not styled in the same way as the background of the button, or when selected. That makes it difficult to visually identify that the link and number/title are related to the link when many links are present.

I'm not sure if that's a limitation of the Hyperlink?

Yes, it was.

I just released v0.2.0 which allows the use of Attrmaps (and other means) over Hyperlink widgets (and the rendered canvases). See AnonymouX47/urwidgets#3.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with:

        hyperlink = urwidgets.Hyperlink(uri=self.link)
        icon = urwid.Pile(
            widget_list=[
                urwid.SelectableIcon(caption, cursor_position=len(caption) + 1),
                # using `hyperlink.pack()[0]` instead of `len(self.link)` in case of wide characters
                urwidgets.TextEmbed((hyperlink.pack()[0], hyperlink)),
            ]
        )

to wrap the URL across lines instead of clipping with ellipsis.

The OSC 8 feature will still work perfectly on any terminal emulator with a spec-compliant implementation and behaviour will remain the same as before this PR on terminal emulators that don't support the feature.

@neiljp neiljp added the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback size: S [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants