Skip to content

Commit

Permalink
feat: Remove truncation from oneline list
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiAwar committed May 1, 2024
1 parent 1477329 commit 60994f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func list(cmd *cobra.Command, args []string) error {
for _, snippet := range snippets.Snippets {
if config.Flag.OneLine {
description := runewidth.FillRight(runewidth.Truncate(snippet.Description, col, "..."), col)
command := runewidth.Truncate(snippet.Command, 100-4-col, "...")
command := snippet.Command
// make sure multiline command printed as oneline
command = strings.Replace(command, "\n", "\\n", -1)
fmt.Fprintf(color.Output, "%s : %s\n",
Expand Down
10 changes: 5 additions & 5 deletions snippet/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"sort"

"github.com/pelletier/go-toml"
"github.com/knqyf263/pet/config"
"github.com/pelletier/go-toml"
)

type Snippets struct {
Expand All @@ -29,7 +29,7 @@ func (snippets *Snippets) Load() error {
}
f, err := os.ReadFile(snippetFile)
if err != nil {
return fmt.Errorf("Failed to load snippet file. %v", err)
return fmt.Errorf("failed to load snippet file. %v", err)
}
toml.Unmarshal(f, snippets)
snippets.Order()
Expand All @@ -40,10 +40,10 @@ func (snippets *Snippets) Load() error {
func (snippets *Snippets) Save() error {
snippetFile := config.Conf.General.SnippetFile
f, err := os.Create(snippetFile)
defer f.Close()
if err != nil {
return fmt.Errorf("Failed to save snippet file. err: %s", err)
return fmt.Errorf("failed to save snippet file. err: %s", err)
}
defer f.Close()
return toml.NewEncoder(f).Encode(snippets)
}

Expand All @@ -52,7 +52,7 @@ func (snippets *Snippets) ToString() (string, error) {
var buffer bytes.Buffer
err := toml.NewEncoder(&buffer).Encode(snippets)
if err != nil {
return "", fmt.Errorf("Failed to convert struct to TOML string: %v", err)
return "", fmt.Errorf("failed to convert struct to TOML string: %v", err)
}
return buffer.String(), nil
}
Expand Down

0 comments on commit 60994f0

Please sign in to comment.