From 0dbe5f2aa4c24bb037af956a07330f6c8d77cd8f Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 10 Jun 2022 10:31:44 +0200 Subject: [PATCH] fix(font): provide feedback when installing relates to #2338 --- src/cli/font.go | 15 +++++---------- src/font/cli.go | 16 ++++++++++++++-- src/font/install.go | 10 ---------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/cli/font.go b/src/cli/font.go index e9e423db..240ebb8d 100644 --- a/src/cli/font.go +++ b/src/cli/font.go @@ -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") diff --git a/src/font/cli.go b/src/font/cli.go index 36c3fb8e..036145c5 100644 --- a/src/font/cli.go +++ b/src/font/cli.go @@ -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) diff --git a/src/font/install.go b/src/font/install.go index efe858d4..f6f14e3e 100644 --- a/src/font/install.go +++ b/src/font/install.go @@ -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)