mirror of
https://gitea.com/gitea/tea.git
synced 2026-03-11 00:03:32 +01:00
Update to charm libraries v2 (#923)
Reviewed-on: https://gitea.com/gitea/tea/pulls/923 Reviewed-by: techknowlogick <9+techknowlogick@noreply.gitea.com> Co-authored-by: Michal Suchanek <msuchanek@suse.de> Co-committed-by: Michal Suchanek <msuchanek@suse.de>
This commit is contained in:
committed by
techknowlogick
parent
3372c9ec59
commit
c797624fcf
@@ -21,7 +21,7 @@ import (
|
||||
"code.gitea.io/tea/modules/httputil"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
gogit "github.com/go-git/go-git/v5"
|
||||
"github.com/urfave/cli/v3"
|
||||
"golang.org/x/term"
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// IsQuitting checks if the user has aborted the interactive prompt
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// EditIssue interactively edits an issue
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// CreateLogin create an login interactive
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// CreateMilestone interactively creates a milestone
|
||||
|
||||
@@ -5,16 +5,18 @@ package interact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"charm.land/lipgloss/v2"
|
||||
)
|
||||
|
||||
// printTitleAndContent prints a title and content with the gitea theme
|
||||
func printTitleAndContent(title, content string) {
|
||||
hasDarkBG := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
|
||||
style := lipgloss.NewStyle().
|
||||
Foreground(theme.GetTheme().Blurred.Title.GetForeground()).Bold(true).
|
||||
Foreground(theme.GetTheme().Theme(hasDarkBG).Blurred.Title.GetForeground()).Bold(true).
|
||||
Padding(0, 1)
|
||||
fmt.Print(style.Render(title), content+"\n")
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// PromptPassword asks for a password and blocks until input was made.
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// CreatePull interactively creates a PR
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
// MergePull interactively creates a PR
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"code.gitea.io/tea/modules/theme"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/charmbracelet/huh"
|
||||
"charm.land/huh/v2"
|
||||
)
|
||||
|
||||
var reviewStates = map[string]gitea.ReviewStateType{
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/charmbracelet/glamour"
|
||||
"charm.land/glamour/v2"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
@@ -15,19 +15,23 @@ import (
|
||||
// If the input could not be parsed, it is printed unformatted, the error
|
||||
// is returned anyway.
|
||||
func outputMarkdown(markdown string, baseURL string) error {
|
||||
var styleOption glamour.TermRendererOption
|
||||
var renderer *glamour.TermRenderer
|
||||
var err error
|
||||
if IsInteractive() {
|
||||
styleOption = glamour.WithAutoStyle()
|
||||
renderer, err = glamour.NewTermRenderer(
|
||||
glamour.WithBaseURL(baseURL),
|
||||
glamour.WithPreservedNewLines(),
|
||||
glamour.WithWordWrap(getWordWrap()),
|
||||
)
|
||||
} else {
|
||||
styleOption = glamour.WithStandardStyle("notty")
|
||||
renderer, err = glamour.NewTermRenderer(
|
||||
glamour.WithStandardStyle("notty"),
|
||||
glamour.WithBaseURL(baseURL),
|
||||
glamour.WithPreservedNewLines(),
|
||||
glamour.WithWordWrap(getWordWrap()),
|
||||
)
|
||||
}
|
||||
|
||||
renderer, err := glamour.NewTermRenderer(
|
||||
styleOption,
|
||||
glamour.WithBaseURL(baseURL),
|
||||
glamour.WithPreservedNewLines(),
|
||||
glamour.WithWordWrap(getWordWrap()),
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Print(markdown)
|
||||
return err
|
||||
|
||||
@@ -4,20 +4,22 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/huh"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"charm.land/huh/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"charm.land/lipgloss/v2/compat"
|
||||
)
|
||||
|
||||
var giteaTheme = func() *huh.Theme {
|
||||
theme := huh.ThemeCharm()
|
||||
type myTheme struct {}
|
||||
|
||||
title := lipgloss.AdaptiveColor{Light: "#02BA84", Dark: "#02BF87"}
|
||||
func (t myTheme) Theme (isDark bool) *huh.Styles {
|
||||
theme := huh.ThemeCharm(isDark)
|
||||
|
||||
title := compat.AdaptiveColor{Light: lipgloss.Color("#02BA84"), Dark: lipgloss.Color("#02BF87")}
|
||||
theme.Focused.Title = theme.Focused.Title.Foreground(title).Bold(true)
|
||||
theme.Blurred = theme.Focused
|
||||
return theme
|
||||
}()
|
||||
|
||||
// GetTheme returns the Gitea theme for Huh
|
||||
func GetTheme() *huh.Theme {
|
||||
return giteaTheme
|
||||
}
|
||||
func GetTheme() myTheme {
|
||||
var t myTheme
|
||||
return t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user