qrtui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package qrtui 提供扫码登录的 bubbletea 全屏界面。

替代旧 runLogin 的 fmt.Println 轮询堆行(状态行无限累积,长时间等待或 屏幕小时把二维码顶出视野)。bubbletea 的 View() 是纯函数:二维码块固定 输出,spinner + 状态行原地刷新,布局恒定不抖动。

形态:inline(非 alt-screen)——登录成功后二维码保留在终端历史可追溯; 退出后控制权交回。CONFIRMED 的会话持久化由调用方在 Program 退出后执行, 避免 persistLogin 的 stdout 打印 clobber 视图。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	// QR termqr.Render 的输出(已含 quiet zone 与半高方块),固定不变。
	QR string
	// QRURL 二维码原始 URL(展示给无法识别二维码的终端用户)。
	QRURL string
	// Check 轮询一次扫码状态。返回 (code, raw, setCookie, err):
	//   - code=WAITING/SCANNED/CONFIRMED/EXPIRED
	//   - raw/setCookie 仅 CONFIRMED 有效(持久化用)
	//   - err 非空时进入 stateError,自动重试
	Check func(ctx context.Context) (code mmpb.QrcodeCode, raw json.RawMessage, setCookie string, err error)
	// PollCtx 轮询上下文(注入 cookie)。默认 context.Background,生产由调用方传 CookieCtx。
	PollCtx context.Context
	// Now 时钟注入(测试「Xs 前检查」展示)。
	Now func() time.Time
}

Deps 注入依赖(测试 seam)。Check 是对 CheckQrcode 的封装,内部调 kit.RawDo + model.DecodeQrcodeStatus;调用方负责 ctx 的 cookie 注入。

type Result

type Result struct {
	Confirmed bool
	Raw       json.RawMessage // CONFIRMED 响应,传给 persistLogin 提取 UserID
	SetCookie string          // Set-Cookie 头,会话信件
}

Result Run 的返回。Confirmed=true 时 Raw/SetCookie 有效,调用方据此持久化。

func Run

func Run(deps Deps, output io.Writer) (Result, error)

Run 接管终端,返回登录结果。caller 在返回后按 Confirmed 决定是否持久化。

output 默认 os.Stdout;测试可注入 bytes.Buffer(但 tea.Program 仍耦合终端, 真实交互需 TTY——非 TTY 由调用方提前守卫,见 runLogin)。

Jump to

Keyboard shortcuts

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