mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix(font): do not fail on non-admin for Windows
This commit is contained in:
parent
16d278ace3
commit
c93d637128
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"oh-my-posh/environment"
|
||||||
"oh-my-posh/font"
|
"oh-my-posh/font"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -32,7 +33,10 @@ This command is used to install fonts and configure the font in your terminal.
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
fontName = args[1]
|
fontName = args[1]
|
||||||
}
|
}
|
||||||
font.Run(fontName)
|
env := &environment.ShellEnvironment{}
|
||||||
|
env.Init()
|
||||||
|
needsAdmin := env.GOOS() == environment.WINDOWS && !env.Root()
|
||||||
|
font.Run(fontName, needsAdmin)
|
||||||
return
|
return
|
||||||
case "configure":
|
case "configure":
|
||||||
fmt.Println("not implemented")
|
fmt.Println("not implemented")
|
||||||
|
|
|
@ -64,16 +64,18 @@ const (
|
||||||
downloadFont
|
downloadFont
|
||||||
unzipFont
|
unzipFont
|
||||||
installFont
|
installFont
|
||||||
|
admin
|
||||||
quit
|
quit
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
|
||||||
type main struct {
|
type main struct {
|
||||||
spinner spinner.Model
|
spinner spinner.Model
|
||||||
list *list.Model
|
list *list.Model
|
||||||
fontname string
|
needsAdmin bool
|
||||||
state state
|
fontname string
|
||||||
err error
|
state state
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *main) buildFontList(nerdFonts []*Asset) {
|
func (m *main) buildFontList(nerdFonts []*Asset) {
|
||||||
|
@ -123,6 +125,10 @@ func installFontZIP(zipFile []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *main) Init() tea.Cmd {
|
func (m *main) Init() tea.Cmd {
|
||||||
|
if m.needsAdmin {
|
||||||
|
m.state = admin
|
||||||
|
return tea.Quit
|
||||||
|
}
|
||||||
if len(m.fontname) != 0 {
|
if len(m.fontname) != 0 {
|
||||||
m.state = downloadFont
|
m.state = downloadFont
|
||||||
if !strings.HasPrefix(m.fontname, "https") {
|
if !strings.HasPrefix(m.fontname, "https") {
|
||||||
|
@ -222,6 +228,8 @@ func (m *main) View() string {
|
||||||
return "\n" + m.list.View()
|
return "\n" + m.list.View()
|
||||||
case downloadFont:
|
case downloadFont:
|
||||||
return textStyle.Render(fmt.Sprintf("%s Downloading %s", m.spinner.View(), m.fontname))
|
return textStyle.Render(fmt.Sprintf("%s Downloading %s", m.spinner.View(), m.fontname))
|
||||||
|
case admin:
|
||||||
|
return textStyle.Render("You need to be admin to install a font on Windows")
|
||||||
case unzipFont:
|
case unzipFont:
|
||||||
return textStyle.Render(fmt.Sprintf("%s Extracting %s", m.spinner.View(), m.fontname))
|
return textStyle.Render(fmt.Sprintf("%s Extracting %s", m.spinner.View(), m.fontname))
|
||||||
case installFont:
|
case installFont:
|
||||||
|
@ -234,9 +242,10 @@ func (m *main) View() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(font string) {
|
func Run(font string, needsAdmin bool) {
|
||||||
main := &main{
|
main := &main{
|
||||||
fontname: font,
|
fontname: font,
|
||||||
|
needsAdmin: needsAdmin,
|
||||||
}
|
}
|
||||||
program = tea.NewProgram(main)
|
program = tea.NewProgram(main)
|
||||||
if err := program.Start(); err != nil {
|
if err := program.Start(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue