mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
parent
265790659c
commit
0dbe5f2aa4
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue