Skip to content

Conversation

mgazza
Copy link
Contributor

@mgazza mgazza commented Oct 18, 2023

Punt/ Preview PR
Change the font to one that has a bold derivative - (I probably should use fyne bundle instead of go embed).
Add the handling code for supporting underlining and bold.
Make that info available for downstream consumption for fyne.

depends on :
#45
fyne-io/fyne#4244

@andydotxyz andydotxyz marked this pull request as draft October 18, 2023 16:41
@andydotxyz andydotxyz changed the title Draft: Add bold and underline functionality Add bold and underline functionality Oct 18, 2023
@andydotxyz
Copy link
Member

(converted to draft on GitHub rather than in the text)

@mgazza mgazza force-pushed the add-bold-underline branch 2 times, most recently from fa0ae3b to be74aa6 Compare October 24, 2023 09:21
@andydotxyz
Copy link
Member

Trying to come back to a backlog of PRs and I see this one - it seems to have blinking work in it as well, maybe the wrong base branch?
Also as there is discussion about underline and strikethrough in TextStyle I wonder if that changes the API design here?

@mgazza
Copy link
Contributor Author

mgazza commented Nov 13, 2023

Hey, sorry I've been really busy with other things recently. Certainly there's mention of blinking in this PR. That is because it depends on #45

@mgazza mgazza force-pushed the add-bold-underline branch from be74aa6 to 43baa67 Compare February 2, 2024 10:45
@mgazza
Copy link
Contributor Author

mgazza commented Jun 14, 2024

image

depends on
fyne-io/fyne#4244
#85 ( cherry-picked into this )

@mgazza mgazza force-pushed the add-bold-underline branch from 43baa67 to b4a2dc9 Compare June 14, 2024 12:12
@andydotxyz
Copy link
Member

I had a glance through this, I'm not sure about the weight of the renderer on this - it seems like a lot of TextGrid is copied in, but I'm not sure why.

@mgazza
Copy link
Contributor Author

mgazza commented Jun 17, 2024

I can't encapsulate it because the renderer isn't exported. This a huge issue IMO. I don't know the best way to resolve it.

@mgazza
Copy link
Contributor Author

mgazza commented Jun 17, 2024

We could move the blinking down to the text grid render but I'm not sure what value that would give

@andydotxyz
Copy link
Member

I can't encapsulate it because the renderer isn't exported. This a huge issue IMO. I don't know the best way to resolve it.

But why do you need to tweak the renderer implementation? Can't it be delegated to?

@mgazza
Copy link
Contributor Author

mgazza commented Jun 17, 2024 via email

@andydotxyz
Copy link
Member

For blink I need to swap the fg and bg colours and I can either do that in the renderer or via the style.

Oh I see, this pattern was adopted earlier - I kinda missed how much was duplicated sorry.
Something between the two was in my head. The first was new public APIs which were not needed, and putting it all in the renderer is fine but we've got much more code to manage now.

What I had thought was happening before was that the style information was being used as the source, internally it was toggling when blinking and so the renderer had the updated model to get the visuals right. The TextGridStyle is an interface after all so it can return different colour values as it blinks. By delegating I meant that we encapsulate a TextGrid (along with its renderer) and provide a layer on top that manages complex things like toggling blink or handling hyperlink taps etc... the core rendering is still in the UI library...

But that leaves us with this PR. Is it right to pull in all the new code from Fyne TextGrid here to get the copy of the code working as it is upstream? I guess we kindof have to with what is in place now? Unless a simplification refactor could be done first?

@mgazza
Copy link
Contributor Author

mgazza commented Jun 19, 2024 via email

@andydotxyz
Copy link
Member

No, renderers cannot be made public. However is the BgColor and FgColor being methods not exactly the thing you need to be able to influence the colours on any particular render pass?

@mgazza
Copy link
Contributor Author

mgazza commented Jun 19, 2024 via email

@andydotxyz
Copy link
Member

In my mind that is where our "wrapping" widget comes in - we know the original state and we track a blink flag, toggling the state that is passed into the embedded TextGrid

@andydotxyz
Copy link
Member

Anything more I can do to help with the tidy-up here?

@mgazza mgazza force-pushed the add-bold-underline branch from b4a2dc9 to 707591b Compare October 27, 2024 12:49
@mgazza
Copy link
Contributor Author

mgazza commented Oct 27, 2024

If it's not public, we can't employ consumption over inheritance. Could you maybe take a stab at what your thinking here?

@andydotxyz
Copy link
Member

If it's not public, we can't employ consumption over inheritance. Could you maybe take a stab at what your thinking here?

I don't understand this question sorry. My point about blinking was that the colours are being asked for from an interface - and we can return different colours for the fg/bg as the blink occurs. Internally we manage blink state but the renderer would remain entirely the standard textgrid as we are just manipulating the widget state - no need to hook into a renderer.

@mgazza
Copy link
Contributor Author

mgazza commented Oct 27, 2024

Blinking is already in the main branch. This PR is about bold and underlining. I think I'm confused as these couple of features have been left for awhile.

@andydotxyz
Copy link
Member

The discussion, as far as I'm aware, is what was done with blinking is now resulting in constantly pulling renderer from upstream Fyne into this project to maintain a tweak for blinking.

I don't know if it was missed at the time but this is really undesirable, causes a maintenance overhead and goes against the design of widget and renderer separation.

This PR should be trivial but because of earlier decisions it is not - this is what I was hoping we could resolve.

If you are keen to land this feature we could back out the blinking, add this in easily, and then review the renderer situation with fresh eyes to get blinking back?
I think it's not until this PR demonstrated the tight coupling that had been introduced that I realised how much of an issue it was.

@mgazza
Copy link
Contributor Author

mgazza commented Oct 28, 2024

it was discussed here.
the previous commits were a lot less invasive.
I wonder if the way forward is to push this widget down into fyne?

@andydotxyz
Copy link
Member

I wonder if the way forward is to push this widget down into fyne?

I don't understand this - the widget is already in Fyne. What exists here seems to be a copy/paste of the renderer which you're now working to keep in sync as the upstream widget changes.

@mgazza
Copy link
Contributor Author

mgazza commented Oct 28, 2024

The widget for a text grid exists in fyne, but it doesn't respect The Open-closed principal, the term grid was added in #45. This PR add's bold and underline to the termgrid. The confusion may come from the diff as the termgrid renderer was moved to its own file in this commit

@mgazza mgazza force-pushed the add-bold-underline branch from 24e9952 to b1ea76f Compare October 28, 2024 12:15
@andydotxyz
Copy link
Member

I'm not confused and have tried to outline before that I am aware this is not new code but has come to light it's tight connection to an existing widget.

Without getting into the semantics of it all widgets are open to extension so I don't think it's correct to say that it's not open-closed. I have illustrated above ways that I think it is in fact possible to do what was achieved through copy and paste last time.

Do you think it is untrue to say that without the copying out of the renderer this PR would have been far simpler?

I think the issue is on me for having agreed to cloning the renderer in the first place, I did not fully understand how tightly this caused the two to be tied - which is what has become clear in this PR.

I hope this explains at least my previous messages, I don't think that I am confused about the scope of this change. But with the required render changes it looks like this requires more custom rendering which is not the case.

@andydotxyz
Copy link
Member

I'm trying to get on top of this and seeing what I can do to help.

With the updates to Fyne on develop (adding Scroll to TextGrid) there have been a lot of refactoring internally which makes the duplicated TextGridRenderer in here more problematic (TextGrid now has renderers for the widget, it's content (which may or may not be in a scroller) and one per row as well for re-use during scrolling).

I'm guessing that the best thing for me to do is work on the termGrid code so it fits with the new Fyne changes and then the differences for this PR can be re-worked on that?...

@drunlade
Copy link

drunlade commented Jun 9, 2025

@andydotxyz Any progress with this? It's been around a while and Bold/Underline seems like a pretty base thing for term text-grid to support. Without it, many programs and outputs just render incorrectly.

EDIT: Just to add, I was working around the lack of support by using the duplicate of the renderer and using these changes there. However, since you de-duplicated it and it's all now under "internal" I can't override it or duplicate it or anything.

@andydotxyz
Copy link
Member

@andydotxyz Any progress with this? It's been around a while and Bold/Underline seems like a pretty base thing for term text-grid to support. Without it, many programs and outputs just render incorrectly.

It's not my PR to progress so I think I am the wrong person to answer. Bold should now be in TextGrid upstream - all you need to hook in is a monospaced bold font in your custom theme.
Underline is supported upstream - the reason I refactored the Terminal code was that it should never have been needed to add that code here.

EDIT: Just to add, I was working around the lack of support by using the duplicate of the renderer and using these changes there. However, since you de-duplicated it and it's all now under "internal" I can't override it or duplicate it or anything.

It sounds like your code was going to run into the same problem as this PR - duplicating the renderer of an upstream widget is a very bad idea. The features have been added upstream but anyone with custom renderer implementations won't know that and/or will have very complex merges ahead as they try to pull our code in from upstream.

@drunlade
Copy link

drunlade commented Jun 9, 2025

@andydotxyz Then that's my mistake then, the existence of this PR still open made me assume the feature was not yet supported. Perhaps close this PR as it sounds like you're saying this is redundant? Or ask @mgazza to confirm it's redundant and close it?

It sounds like your code was going to run into the same problem as this PR...

Completely true, but until I had a working solution, this had to be the solution.

So to confirm, you're saying that Bold and Underline are supported and that Terminal now correctly renders Bold and Underline text when the session outputs it?

@andydotxyz
Copy link
Member

So to confirm, you're saying that Bold and Underline are supported and that Terminal now correctly renders Bold and Underline text when the session outputs it?

No. I am saying that both are /supported/ in the TextGrid that Terminal uses. Underlines will appear as they are coded in as lines. The bold font will not appear until the terminal (or your app's custom theme) introduce the added fonts necessary to have bold, monospaced (not bundled in Fyne to save space). This PR adds them, among other no-longer required changes.

@drunlade
Copy link

drunlade commented Jun 9, 2025

That clarifies it, thanks. I'll chat to the PR owner about what that means for this work. As you say, it seems some it certainly redundant.

@drunlade
Copy link

@mgazza I suggest this is closed, almost everything here is replaced with a couple of minor changes. I'll try and find the time to PR those changes.

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

Successfully merging this pull request may close these issues.

3 participants