mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor: add terminal output and forms package (#1124)
- `internal/terminal`: streams and the prompting policy, interactive forms (issue, PR, review, merge, milestone), editor / pager / browser launching, JSON and `--jq` output. - An aligned table renderer and a record renderer for human output; both strip control and escape characters from server-supplied text so titles and bodies cannot inject terminal sequences. Reviewed-on: https://gitea.com/gitea/tea/pulls/1124 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
This commit is contained in:
1 parent
88b91faa54
commit
faea86cd94
27 files changed
+1941
-1
No files matched your search
@@ -0,0 +1,39 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// MergePullChoice is one selectable open pull request for interactive merge.
|
||||
type MergePullChoice struct {
|
||||
Number int64
|
||||
Title, Head string
|
||||
}
|
||||
|
||||
// MergeForm collects which pull request to merge.
|
||||
type MergeForm interface {
|
||||
SelectPull(context.Context, []MergePullChoice) (int64, error)
|
||||
}
|
||||
|
||||
// SelectPull prompts for a pull request on stderr.
|
||||
func (p *FormPrompter) SelectPull(ctx context.Context, choices []MergePullChoice) (int64, error) {
|
||||
if len(choices) == 0 {
|
||||
return 0, errors.New("no open pull requests match the current branch")
|
||||
}
|
||||
options := make([]huh.Option[int64], 0, len(choices))
|
||||
for _, choice := range choices {
|
||||
options = append(options, huh.NewOption(fmt.Sprintf("#%d: %s (%s)", choice.Number, choice.Title, choice.Head), choice.Number))
|
||||
}
|
||||
selected := choices[0].Number
|
||||
err := p.runForm(ctx, huh.NewForm(huh.NewGroup(
|
||||
huh.NewSelect[int64]().Title("Select a PR to merge:").Options(options...).Value(&selected),
|
||||
)))
|
||||
return selected, err
|
||||
}
|
||||
Reference in new issue
Block a user