@@ -33,8 +33,8 @@ import (
3333)
3434
3535const (
36- defQRCodeSz = 9000 // default limit for encoded image size, seen values 6174, 8462
37- maxQRCodeSz = 1 << 16 - 1
36+ defQRCodeSz = 9000 // default limit for encoded image size, seen values 6174, 8462
37+ maxQRCodeSz = 1 << 16 - 1 // maximum allowed QR code image size.
3838 imgPrefix = "data:image/png;base64,"
3939)
4040
@@ -267,15 +267,10 @@ func (*Huh) RequestQR(ctx context.Context, _ io.Writer) (string, error) {
267267 3. right-click the QR code image;
268268 4. choose Copy Image.`
269269
270- // check limQrCodeSz value for sanity
271- if limQrCodeSz < defQrCodeSz || maxQrCodeSz < limQrCodeSz {
272- limQrCodeSz = defQrCodeSz
273- }
274-
275270 var imageData string
276271 q := huh .NewForm (huh .NewGroup (
277272 huh .NewText ().
278- CharLimit (limQrCodeSz ).
273+ CharLimit (qrCharLimit () ).
279274 Value (& imageData ).
280275 Validate (func (s string ) error {
281276 if ! strings .HasPrefix (s , imgPrefix ) {
@@ -292,3 +287,12 @@ func (*Huh) RequestQR(ctx context.Context, _ io.Writer) (string, error) {
292287 }
293288 return imageData , nil
294289}
290+
291+ // qrCharLimit returns the effective character limit for the QR code input
292+ // field.
293+ func qrCharLimit () int {
294+ if defQRCodeSz <= limQRCodeSz && limQRCodeSz <= maxQRCodeSz {
295+ return limQRCodeSz
296+ }
297+ return defQRCodeSz
298+ }
0 commit comments