~seirdy/moac

CLI: warn if grapheme clusters are detected v1 APPLIED

Pranjal Kole: 1
 CLI: warn if grapheme clusters are detected

 2 files changed, 18 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/~seirdy/moac/patches/26040/mbox | git am -3
Learn more about email & git

[PATCH] CLI: warn if grapheme clusters are detected Export this patch

The uniseg package was used to detect grapheme clusters, because it is
the only one which supports it at the moment.

[Ticket: 19]
---
 cmd/moac-pwgen/main.go | 9 +++++++++
 cmd/moac/main.go       | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/cmd/moac-pwgen/main.go b/cmd/moac-pwgen/main.go
index 8405af2..60d3a43 100644
--- a/cmd/moac-pwgen/main.go
+++ b/cmd/moac-pwgen/main.go
@@ -12,6 +12,7 @@ import (
	"git.sr.ht/~seirdy/moac/v2/internal/sanitize"
	"git.sr.ht/~seirdy/moac/v2/pwgen"
	"git.sr.ht/~sircmpwn/getopt"
	"github.com/rivo/uniseg"
)

const (
@@ -152,6 +153,14 @@ func main1() int {
		return 1
	}

	graphemes := uniseg.NewGraphemes(strings.Join(args, ""))
	for graphemes.Next() {
		if len(graphemes.Runes()) > 1 {
			fmt.Fprintf(os.Stderr, "warning: charsets contain grapheme clusters, will be treated as distinct codepoints\n")
			break
		}
	}

	pwr.CharsetsWanted = charsets.ParseCharsets(setCharsetNames(args))
	pw, err := pwgen.GenPW(pwr)

diff --git a/cmd/moac/main.go b/cmd/moac/main.go
index adef3fe..52a336d 100644
--- a/cmd/moac/main.go
+++ b/cmd/moac/main.go
@@ -12,6 +12,7 @@ import (
	"git.sr.ht/~seirdy/moac/v2/internal/cli"
	"git.sr.ht/~sircmpwn/getopt"
	"golang.org/x/term"
	"github.com/rivo/uniseg"
)

const (
@@ -159,6 +160,14 @@ func getOutput() (output float64, exitEarly bool, err error) {
		return output, exitEarly, fmt.Errorf("moac: %w", err)
	}

	graphemes := uniseg.NewGraphemes(givens.Password)
	for graphemes.Next() {
		if len(graphemes.Runes()) > 1 {
			fmt.Fprintf(os.Stderr, "warning: charsets contain grapheme clusters, will be treated as distinct codepoints\n")
			break
		}
	}

	cmd := strengthCmd

	if len(os.Args) > optind {
-- 
2.33.1
Thanks; I'll apply this and also add it to go.mod/go.sum.

-- 
/Seirdy