qrcode

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateQRCodeImage

func CreateQRCodeImage(text string, size int, filename string) error

func ShowByUrl

func ShowByUrl(uri string, timeout time.Duration) error

func ShowByUrlWithSize

func ShowByUrlWithSize(uri string, timeout time.Duration, width, height int) error

ShowByUrlWithSize 显示二维码,可以自定义显示大小

func ShowQRCodeWithCallback added in v0.0.5

func ShowQRCodeWithCallback(imageURL string, timeout time.Duration, successChan <-chan bool, cancelChan chan<- bool, timeoutChan chan<- bool) error

ShowQRCodeWithCallback 使用 lipgloss 和 bubbletea 展示二维码,支持外部通知与交互

参数: - imageURL: 二维码图片的 URL,会通过 HTTP GET 下载 - timeout: 显示超时时间,倒计时结束后自动退出 - successChan: 接收登录成功通知,外部向此 channel 发送 true 会立即退出并显示成功提示 - cancelChan: 发送用户取消通知,当用户按 q/Ctrl+C/Esc 时,向此 channel 发送 true - timeoutChan: 发送超时通知,当倒计时结束时,向此 channel 发送 true

返回: - error: 仅当下载或解码图片失败时返回错误,其他情况(取消/超时/成功)均返回 nil

实现逻辑:

1. 下载并转换二维码图片

  • 从 imageURL 下载图片
  • 将图片转换为终端字符串(使用半块字符 █▀▄ 渲染)

2. 创建 bubbletea Model

  • 初始化 qrModel,设置二维码内容和倒计时
  • 启动 bubbletea 程序

3. 监听外部登录成功通知

  • 如果提供了 successChan,启动 goroutine 监听
  • 接收到通知后,通过 p.Send() 发送 loginSuccessMsg
  • 触发 Model 的 Update 方法,设置 loginDone=true 并退出

4. 等待程序结束并处理最终状态

  • interrupted: 向 cancelChan 发送 true
  • timeout: 向 timeoutChan 发送 true
  • loginDone: 不发送任何通知,由外部已经知道

设计要点: - 所有 channel 均为可选,传 nil 表示不需要该通知 - 用户取消和超时的提示信息已在 UI 中显示,无需返回错误,避免重复显示 - bubbletea 程序是阻塞运行的,直到退出前不会返回

func ShowQRCodeWithLipgloss added in v0.0.5

func ShowQRCodeWithLipgloss(imageURL string, timeout time.Duration) error

ShowQRCodeWithLipgloss 使用lipgloss和bubbletea展示二维码(基于字符渲染)

参数: - imageURL: 二维码图片的 URL,会自动下载并转换为终端字符显示 - timeout: 显示超时时间

返回: - error: 下载或显示错误,正常结束返回 nil

说明:这是简化版本,内部调用 ShowQRCodeWithCallback 但不接收任何通知

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL