~eliasnaur/gio-patches

gio: ui/widget: password-mode for editor v1 PROPOSED

~funvit
~funvit: 1
 ui/widget: password-mode for editor

 1 files changed, 10 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9506/mbox | git am -3
Learn more about email & git

[PATCH gio] ui/widget: password-mode for editor Export this patch

~funvit
From: Vitaliy Funtikov <funvit@gmail.com>

Ability to hide actual editor text, replacing it with asterisk(s) on
drawing.

Signed-off-by: Vitaliy Funtikov <funvit@gmail.com>
---
For issue #80

 widget/editor.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/widget/editor.go b/widget/editor.go
index 7ba8d3c..9cb9512 100644
--- a/widget/editor.go
+++ b/widget/editor.go
@@ -33,6 +33,9 @@ type Editor struct {
	// If not enabled, carriage returns are inserted as newlines in the text.
	Submit bool

	// Hide input, replacing each symbol with asterisk (*)
	Password bool

	eventKey     int
	scale        int
	font         text.Font
@@ -432,6 +435,13 @@ func (e *Editor) moveCoord(c unit.Converter, pos image.Point) {

func (e *Editor) layoutText(c unit.Converter, s *text.Shaper, font text.Font) ([]text.Line, layout.Dimensions) {
	txt := e.rr.String()
	if e.Password {
		txtLen := len(txt)
		txt = ""
		for i := 0; i < txtLen; i++ {
			txt += "*"
		}
	}
	opts := text.LayoutOptions{MaxWidth: e.maxWidth}
	textLayout := s.Layout(c, font, txt, opts)
	lines := textLayout.Lines
-- 
2.24.1
View this thread in the archives