mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 13:04:04 -08:00
parent
b22dd21fa5
commit
9b17c483a8
111
src/cli/font.go
111
src/cli/font.go
|
@ -3,12 +3,16 @@ package cli
|
|||
import (
|
||||
"fmt"
|
||||
"oh-my-posh/font"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// fontCmd can work with fonts
|
||||
var fontCmd = &cobra.Command{
|
||||
var (
|
||||
fontName string
|
||||
|
||||
// fontCmd can work with fonts
|
||||
fontCmd = &cobra.Command{
|
||||
Use: "font [install|configure]",
|
||||
Short: "Manage fonts",
|
||||
Long: `Manage fonts.
|
||||
|
@ -27,105 +31,26 @@ This command is used to install fonts and configure the font in your terminal.
|
|||
}
|
||||
switch args[0] {
|
||||
case "install":
|
||||
if len(fontName) == 0 {
|
||||
font.Run()
|
||||
return
|
||||
}
|
||||
err := font.Install(fontName)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
case "configure":
|
||||
fmt.Println("not implemented")
|
||||
default:
|
||||
_ = cmd.Help()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func init() { // nolint:gochecknoinits
|
||||
fontCmd.Flags().StringVarP(&fontName, "font", "f", "", "the font name to install")
|
||||
rootCmd.AddCommand(fontCmd)
|
||||
}
|
||||
|
||||
// type fontsModel struct {
|
||||
// fonts []*font.Asset // the list of choices
|
||||
// cursor int // which item our cursor is pointing at
|
||||
// selected map[int]*font.Asset // which items are selected
|
||||
// }
|
||||
|
||||
// func initFontsModel() (*fontsModel, error) {
|
||||
// nerdFonts, err := font.Nerds()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &fontsModel{
|
||||
// fonts: nerdFonts,
|
||||
// selected: make(map[int]*font.Asset),
|
||||
// }, nil
|
||||
// }
|
||||
|
||||
// func (f fontsModel) Init() tea.Cmd {
|
||||
// // Just return `nil`, which means "no I/O right now, please."
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (f fontsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// switch msg := msg.(type) {
|
||||
// // Is it a key press?
|
||||
// case tea.KeyMsg:
|
||||
// // Cool, what was the actual key pressed?
|
||||
// switch msg.String() {
|
||||
// // These keys should exit the program.
|
||||
// case "ctrl+c", "q":
|
||||
// return f, tea.Quit
|
||||
|
||||
// // The "up" and "k" keys move the cursor up
|
||||
// case "up", "k":
|
||||
// if f.cursor > 0 {
|
||||
// f.cursor--
|
||||
// }
|
||||
|
||||
// // The "down" and "j" keys move the cursor down
|
||||
// case "down", "j":
|
||||
// if f.cursor < len(f.fonts)-1 {
|
||||
// f.cursor++
|
||||
// }
|
||||
|
||||
// // The "enter" key and the spacebar (a literal space) toggle
|
||||
// // the selected state for the item that the cursor is pointing at.
|
||||
// case "enter", " ":
|
||||
// _, ok := f.selected[f.cursor]
|
||||
// if ok {
|
||||
// delete(f.selected, f.cursor)
|
||||
// } else {
|
||||
// f.selected[f.cursor] = f.fonts[f.cursor]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Return the updated model to the Bubble Tea runtime for processing.
|
||||
// // Note that we're not returning a command.
|
||||
// return f, nil
|
||||
// }
|
||||
|
||||
// func (f fontsModel) View() string {
|
||||
// // The header
|
||||
// s := "Which font do you want to install?\n\n"
|
||||
|
||||
// // Iterate over our choices
|
||||
// for i, choice := range f.fonts {
|
||||
// // Is the cursor pointing at this choice?
|
||||
// cursor := " " // no cursor
|
||||
// if f.cursor == i {
|
||||
// cursor = ">" // cursor!
|
||||
// }
|
||||
|
||||
// // Is this choice selected?
|
||||
// checked := " " // not selected
|
||||
// if _, ok := f.selected[i]; ok {
|
||||
// checked = "x" // selected!
|
||||
// }
|
||||
|
||||
// // Render the row
|
||||
// s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice.Name)
|
||||
// }
|
||||
|
||||
// // The footer
|
||||
// s += "\nPress q to quit.\n"
|
||||
|
||||
// // Send the UI for rendering
|
||||
// return s
|
||||
// }
|
||||
|
|
|
@ -35,7 +35,6 @@ func isZipFile(data []byte) bool {
|
|||
}
|
||||
|
||||
func getRemoteFile(location string) (data []byte, err error) {
|
||||
print("Downloading %s", location)
|
||||
var client = http.Client{}
|
||||
|
||||
resp, err := client.Get(location)
|
||||
|
|
|
@ -5,12 +5,22 @@ 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