Skip to content

Commit 568df3f

Browse files
committed
feat: make print sytle better
1 parent fda638c commit 568df3f

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

ghdl/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ ghdl handles archived or compressed file as well`,
4848
h.Print(fmt.Sprintf("%s. You can install %s with the appropriate commands", err, ghReleaseDl.BinaryName), h.PrintModeInfo)
4949
os.Exit(0)
5050
case ghdl.NoBinError:
51-
h.Print(fmt.Sprintf("%s. Try specify binary name flag", err), h.PrintModeInfo)
51+
h.Print(fmt.Sprintf("%s. Try to specify binary name flag", err), h.PrintModeInfo)
5252
os.Exit(0)
5353
default:
5454
h.Print(fmt.Sprintf("extract failed: %s", err), h.PrintModeErr)
5555
os.Exit(1)
5656
}
5757
}
58-
h.Print(fmt.Sprintf("saved binary executable to %s", ghReleaseDl.BinaryName), h.PrintModeSuccess)
58+
h.Print(fmt.Sprintf("saved executable to %s", ghReleaseDl.BinaryName), h.PrintModeSuccess)
5959
if err := os.Chmod(ghReleaseDl.BinaryName, 0777); err != nil {
6060
h.Print(fmt.Sprintf("chmod failed: %s", err), h.PrintModeErr)
6161
}

helper/pg/pg.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"io"
66
"os"
7-
"strings"
87

98
h "github.com/beetcb/ghdl/helper"
109
"github.com/charmbracelet/bubbles/progress"
@@ -33,11 +32,6 @@ func (pbr *ProgressBytesReader) Read(b []byte) (n int, err error) {
3332
return
3433
}
3534

36-
const (
37-
padding = 4
38-
maxWidth = 80
39-
)
40-
4135
func (m model) Init() tea.Cmd {
4236
return m.init
4337
}
@@ -50,8 +44,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5044
}
5145

5246
func (e model) View() string {
53-
pad := strings.Repeat(" ", padding)
54-
return "\n" + pad + e.progress.ViewAs(e.percent) + fmt.Sprintf(" of %s", e.humanize) + "\n\n"
47+
return "\n " + e.progress.ViewAs(e.percent) + fmt.Sprintf(" of %s", e.humanize) + "\n\n"
5548
}
5649

5750
func Progress(starter func(updater func(float64)), humanize string) {

helper/print.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@ import (
66
"github.com/charmbracelet/lipgloss"
77
)
88

9-
const maxWidth = 80
10-
119
const (
1210
PrintModeInfo = 0
1311
PrintModeSuccess = 1
1412
PrintModeErr = 2
1513
)
1614

17-
func Print(str string, printMode int) {
18-
var PaddingLeft = lipgloss.NewStyle().PaddingLeft(2).MaxWidth(maxWidth)
15+
func Sprint(str string, printMode int) string {
16+
printWidth := 60
17+
var newStyle = lipgloss.NewStyle().Width(printWidth)
18+
prompt := lipgloss.NewStyle().Foreground(lipgloss.Color("13")).Render("→ ")
19+
var sPrint string = prompt
1920
switch printMode {
2021
case PrintModeInfo:
21-
fmt.Println(PaddingLeft.Foreground(lipgloss.Color("11")).Render(str))
22+
sPrint += newStyle.Copy().Foreground(lipgloss.Color("146")).Render(str)
2223
case PrintModeSuccess:
23-
fmt.Println(PaddingLeft.Foreground(lipgloss.Color("14")).Render(str))
24+
sPrint += newStyle.Copy().Foreground(lipgloss.Color("6")).Render(str)
2425
case PrintModeErr:
25-
fmt.Println(PaddingLeft.Foreground(lipgloss.Color("202")).Render(str))
26+
sPrint += newStyle.Copy().Foreground(lipgloss.Color("9")).Render(str)
2627
}
28+
29+
return sPrint
30+
}
31+
32+
func Print(str string, printMode int) {
33+
sPrint := Sprint(str, printMode)
34+
fmt.Println(sPrint)
2735
}

helper/sl/sl.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5151
}
5252

5353
func (m model) View() string {
54-
blue := lipgloss.Color("14")
55-
yellow := lipgloss.Color("11")
56-
paddingS := lipgloss.NewStyle().PaddingLeft(2).MaxWidth(maxWidth)
54+
blue, printWidth := lipgloss.Color("14"), 60
55+
paddingS := lipgloss.NewStyle().PaddingLeft(2).Width(printWidth)
5756
colorS := paddingS.Copy().
5857
Foreground(blue).BorderLeft(true).BorderForeground(blue)
58+
s := "\n" + h.Sprint("there is more than one option after filtering, please select it manually", h.PrintModeInfo) + "\n"
5959
if m.selected == -1 {
60-
s := "\n" + paddingS.Copy().Foreground(yellow).Render("gh-dl can't figure out which release to download\nplease select it manully") + "\n\n"
60+
s += "\n"
6161
for i, choice := range m.choices {
6262
if m.cursor == i {
6363
s += colorS.Render(choice) + "\n"
@@ -68,7 +68,7 @@ func (m model) View() string {
6868
// Send the UI for rendering
6969
return s + "\n"
7070
} else {
71-
s := "\n" + paddingS.Copy().Foreground(yellow).Render(fmt.Sprintf("start downloading %s", lipgloss.NewStyle().Foreground(blue).Render(m.choices[m.selected]))) + "\n"
71+
s += h.Sprint(fmt.Sprintf("start downloading %s", lipgloss.NewStyle().Foreground(blue).Render(m.choices[m.selected])), h.PrintModeInfo) + "\n"
7272
return s
7373
}
7474
}

0 commit comments

Comments
 (0)