fix(font): provide feedback when installing

relates to #2338
This commit is contained in:
Jan De Dobbeleer 2022-06-10 10:31:44 +02:00 committed by Jan De Dobbeleer
parent 265790659c
commit 0dbe5f2aa4
3 changed files with 19 additions and 22 deletions

View file

@ -3,7 +3,6 @@ package cli
import (
"fmt"
"oh-my-posh/font"
"os"
"github.com/spf13/cobra"
)
@ -17,7 +16,7 @@ var (
This command is used to install fonts and configure the font in your terminal.
- install: oh-my-posh font install https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/3270.zip`,
- install: oh-my-posh font install 3270`,
ValidArgs: []string{
"install",
"configure",
@ -29,15 +28,11 @@ This command is used to install fonts and configure the font in your terminal.
}
switch args[0] {
case "install":
if len(args) == 1 {
font.Run()
return
}
err := font.Install(args[1])
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
var fontName string
if len(args) > 1 {
fontName = args[1]
}
font.Run(fontName)
return
case "configure":
fmt.Println("not implemented")

View file

@ -122,6 +122,15 @@ func installFontZIP(zipFile []byte) {
}
func (m *main) Init() tea.Cmd {
if len(m.fontname) != 0 {
m.state = downloadFont
url := fmt.Sprintf("https://github.com/ryanoasis/nerd-fonts/releases/latest/download/%s.zip", m.fontname)
defer func() {
go downloadFontZip(url)
}()
m.spinner.Spinner = spinner.Globe
return m.spinner.Tick
}
defer func() {
go getFontsList()
}()
@ -219,8 +228,11 @@ func (m *main) View() string {
return ""
}
func Run() {
program = tea.NewProgram(&main{})
func Run(font string) {
main := &main{
fontname: font,
}
program = tea.NewProgram(main)
if err := program.Start(); err != nil {
print("Error running program: %v", err)
os.Exit(1)

View file

@ -5,22 +5,12 @@ package font
import (
"archive/zip"
"bytes"
"fmt"
"io"
"path"
"runtime"
"strings"
)
func Install(font string) error {
location := fmt.Sprintf("https://github.com/ryanoasis/nerd-fonts/releases/latest/download/%s.zip", font)
zipFile, err := Download(location)
if err != nil {
return err
}
return InstallZIP(zipFile)
}
func InstallZIP(data []byte) (err error) {
bytesReader := bytes.NewReader(data)