mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #644] Invert text on InputField focus #469
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#469
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rgrannell1 on GitHub (Sep 13, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/644
(may be related to #611)
Source Reference
Is it currently possible to invert an
InputField's content on focus? My use-case is I'm using anInputFieldto input commands to execute, and I'd like to invert when focused and "normal" when focused on another item.InputFielddoes not supportSetDynamicColors(which is fair from an API design standpoint), but supports several colour setters that accepttcellcolours. Is it possible to invert colours (SGR 7) usingInputFieldsetters andtcell?The closest "color" I can find is ColorReset
I don't want to hardcode
colorBlackandcolorWhitesince this may clash with a user's terminal scheme; I want to respect what colours are already in place.For example (using ANSI):
@rgrannell1 commented on GitHub (Sep 13, 2021):
(Side-note, but thank you for your work ❤️; tview is amazing and I plan to use it heavily for all my go CLIs)
@rivo commented on GitHub (Nov 9, 2021):
First of all, thanks for using
tviewand sorry for the late reply. There are multiple issues at play here. I realized that there was no way to listen for "focus" and "blur" events. So I added these to theBoxprimitive. This should allow you to change an input field's appearance when it's selected. See https://pkg.go.dev/github.com/rivo/tview#Box.SetFocusFunc and https://pkg.go.dev/github.com/rivo/tview#Box.SetBlurFunc (and the example below).Secondly, not being able to use SGR 7 is indeed related to #611. For now, I've added
tcell.Stylegetters and setters toInputField, which should allow you to use theStyle.Reverse()attribute.Lastly, using a terminal's default colours is tricky if not impossible. See https://github.com/gdamore/tcell/issues/292 for details. I don't know of any solution to this at the moment.
Here's an example that changes the input field's style when it has focus:
@rgrannell1 commented on GitHub (Nov 9, 2021):
thanks for responding! These changes look excellent, I'll test them out this evening!