Skip to content

Commit

Permalink
Merge pull request #99 from metafates/dev
Browse files Browse the repository at this point in the history
3.11.1
  • Loading branch information
metafates authored Oct 3, 2022
2 parents 3b8d0d1 + 3264e69 commit 7ce7dc7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 65 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to
[Semantic Versioning](https://semver.org).

## 3.11.1

- Fixed critical bug when mangal would crash when using mini mode
- Slightly change `version` command output
- Use better text wrapping

## 3.11.0

- Add an option to search mangas with inline mode. `mangal inline -q "..." -j` will output search results without chapters. #97
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MAKEFLAGS += --silent

ldflags := -X 'github.com/metafates/mangal/constant.BuiltAt=$(shell date -u)'
ldflags += -X 'github.com/metafates/mangal/constant.BuiltBy=$(shell whoami)@$(shell hostname)'
ldflags += -X 'github.com/metafates/mangal/constant.BuiltBy=$(shell whoami)'
ldflags += -X 'github.com/metafates/mangal/constant.Revision=$(shell git rev-parse --short HEAD)'
ldflags += -s
ldflags += -w
Expand Down
59 changes: 39 additions & 20 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cmd

import (
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/style"
"github.com/metafates/mangal/updater"
"github.com/spf13/cobra"
"os"
"runtime"
"text/template"

"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/updater"
"github.com/spf13/cobra"
)

func init() {
Expand Down Expand Up @@ -36,22 +38,39 @@ var versionCmd = &cobra.Command{
installedWith = "Unknown"
}

cmd.Printf(`%s
Version: %s
OS: %s
Arch: %s
Built: %s by %s
Revision: %s
Installed With: %s
`,
constant.AsciiArtLogo,
constant.Version,
runtime.GOOS,
runtime.GOARCH,
constant.BuiltAt, style.Faint(constant.BuiltBy),
constant.Revision,
installedWith,
)
versionInfo := struct {
Version string
InstalledWith string
OS string
Arch string
BuiltAt string
BuiltBy string
Ascii string
Revision string
}{
Ascii: constant.AsciiArtLogo,
Version: constant.Version,
InstalledWith: installedWith,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
BuiltAt: constant.BuiltAt,
BuiltBy: constant.BuiltBy,
Revision: constant.Revision,
}

t, err := template.New("version").Funcs(map[string]any{
"faint": style.Faint,
"bold": style.Bold,
"magenta": style.Magenta,
}).Parse(`{{ .Ascii }}
Version: {{ magenta .Version }}
Installed with: {{ .InstalledWith }}
OS/Arch: {{ .OS }}/{{ .Arch }}
Revision: {{ .Revision }}
Built: {{ .BuiltAt }} by {{ faint .BuiltBy }}
`)
handleErr(err)
handleErr(t.Execute(cmd.OutOrStdout(), versionInfo))
},
}
2 changes: 1 addition & 1 deletion constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package constant

const (
Mangal = "mangal"
Version = "3.11.0"
Version = "3.11.1"
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
)

Expand Down
5 changes: 1 addition & 4 deletions mini/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func (m *mini) handleSourceSelectState() error {
return err
}
} else {
defaultProviders := provider.DefaultProviders()
customProviders := provider.CustomProviders()

var providers = make([]*provider.Provider, len(defaultProviders)+len(customProviders))
var providers []*provider.Provider
providers = append(providers, provider.DefaultProviders()...)
providers = append(providers, provider.CustomProviders()...)

Expand Down
5 changes: 3 additions & 2 deletions tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/style"
"github.com/metafates/mangal/util"
"github.com/muesli/reflow/wrap"
"github.com/spf13/viper"
"math/rand"
"strconv"
Expand Down Expand Up @@ -177,7 +178,7 @@ func (b *statefulBubble) viewDownloadDone() string {
}

func (b *statefulBubble) viewError() string {
errorMsg := util.Wrap(style.Combined(style.Italic, style.Red)(b.lastError.Error()), b.width)
errorMsg := wrap.String(style.Combined(style.Italic, style.Red)(b.lastError.Error()), b.width)
return b.renderLines(
true,
append([]string{
Expand All @@ -186,7 +187,7 @@ func (b *statefulBubble) viewError() string {
icon.Get(icon.Fail) + " Uggh, something went wrong. Maybe try again?",
"",
},
strings.Split(util.Wrap(style.Italic(b.errorPlot), b.width)+"\n\n"+errorMsg, "\n")...,
strings.Split(wrap.String(style.Italic(b.errorPlot), b.width)+"\n\n"+errorMsg, "\n")...,
),
)
}
Expand Down
16 changes: 0 additions & 16 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ func FileStem(path string) string {
return strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
}

// Wrap wraps a string with the given width.
// Will break lines at word boundaries.
func Wrap(s string, width int) string {
var lines []string
for len(s) > width {
i := strings.LastIndex(s[:width], " ")
if i == -1 {
i = width
}
lines = append(lines, s[:i])
s = s[i:]
}
lines = append(lines, s)
return strings.Join(lines, "\n")
}

// ClearScreen clears the terminal screen.
func ClearScreen() {
run := func(name string, args ...string) error {
Expand Down
21 changes: 0 additions & 21 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,6 @@ func TestPadZero(t *testing.T) {
})
}

func TestWrap(t *testing.T) {
s := "1234567890"
Convey("Given a string "+s, t, func() {
Convey("When wrapping with a width of 3", func() {
expected := "123\n456\n789\n0"
result := Wrap(s, 3)
Convey("Then the result should be "+expected, func() {
So(result, ShouldEqual, expected)
})
})

Convey("When wrapping with a width of 2", func() {
result := Wrap(s, 2)
expected := "12\n34\n56\n78\n90"
Convey("Then the result should be "+expected, func() {
So(result, ShouldEqual, expected)
})
})
})
}

func TestFileStem(t *testing.T) {
Convey("When the file name is 'foo.bar'", t, func() {
result := FileStem("foo.bar")
Expand Down

0 comments on commit 7ce7dc7

Please sign in to comment.