Skip to content

Commit

Permalink
help and layout improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 12, 2023
1 parent 72e36ee commit 70f8957
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
6 changes: 3 additions & 3 deletions cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
)

func ListExample() *cobra.Command {
s := fmt.Sprintf("List builtin tester text files available for use with the %s and %s commands",
s := fmt.Sprintf("List the included sample text files available for use with the %s and %s commands",
term.Example("info"), term.Example("view"))
l := fmt.Sprintf("List builtin tester text art and documents available for use with the %s and %s commands.",
l := fmt.Sprintf("List the included sample text art and documents available for use with the %s and %s commands.",
term.Example("info"), term.Example("view"))
expl := strings.Builder{}
example.ListExamples.String(&expl)
return &cobra.Command{
Use: "example",
Aliases: []string{"e", "sample"},
Aliases: []string{"e", "sample", "s"},
GroupID: IDsample,
Short: s,
Long: l,
Expand Down
20 changes: 12 additions & 8 deletions cmd/pkg/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ func (e Example) result() string {
}

func cmd() string {
const todo = " # print text files partial info TODO"
s := &strings.Builder{}
fmt.Fprintf(s, " %s info %s\n", meta.Bin, Filenames)
fmt.Fprintf(s, " %s view %s\n", meta.Bin, Filenames)
fmt.Fprintf(s, " %s %s %s", meta.Bin, Filenames, todo)
fmt.Fprintf(s, " %s example\n\n", meta.Bin)
fmt.Fprintf(s, " %s list\n", meta.Bin)
fmt.Fprintf(s, " %s tables\n", meta.Bin)
fmt.Fprintf(s, " %s table [codepage names or aliases]", meta.Bin)
return s.String()
}

Expand All @@ -107,19 +109,21 @@ func list() string {

func listExamples() string {
s := &strings.Builder{}
fmt.Fprintf(s, " %s examples # list the builtin examples\n", meta.Bin)
fmt.Fprintf(s, " %s info ascii # information on the buildin ascii example\n", meta.Bin)
fmt.Fprintf(s, " %s view ascii # view the ascii example\n", meta.Bin)
fmt.Fprintf(s, " %s info ansi.rgb # information on the 24-bit color ansi example\n", meta.Bin)
fmt.Fprintf(s, " %s view ansi.rgb # view the 24-bit color ansi example", meta.Bin)
fmt.Fprintf(s, " %s examples\t\t# list the builtin examples\n", meta.Bin)
fmt.Fprintf(s, " %s info ascii\t\t# information on the buildin ascii sample\n", meta.Bin)
fmt.Fprintf(s, " %s info ascii -f json\t# information in json format on the ascii sample\n", meta.Bin)
fmt.Fprintf(s, " %s view ascii\t\t# view the ascii example\n", meta.Bin)
fmt.Fprintf(s, " %s info ansi.rgb\t# information on the 24-bit color ansi example\n", meta.Bin)
fmt.Fprintf(s, " %s view ansi.rgb\t# view the 24-bit color ansi example", meta.Bin)
return s.String()
}

func listTable() string {
s := &strings.Builder{}
fmt.Fprintf(s, " %s table cp437\n", meta.Bin)
fmt.Fprintf(s, " %s table cp437 latin1 windows-1252\n", meta.Bin)
fmt.Fprintf(s, " %s table iso-8859-15", meta.Bin)
fmt.Fprintf(s, " %s table iso-8859-15\n", meta.Bin)
fmt.Fprintf(s, " %s list\t# list the supported codepage tables\n", meta.Bin)
return s.String()
}

Expand Down
16 changes: 11 additions & 5 deletions cmd/pkg/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Examples(wr io.Writer) error {
if wr == nil {
wr = io.Discard
}
const width = 80
m := sample.Map()
keys := make([]string, 0, len(m))
for k := range m {
Expand All @@ -38,15 +39,20 @@ func Examples(wr io.Writer) error {
const padding = 2
w := tabwriter.NewWriter(wr, 0, 0, padding, ' ', 0)
bin := fmt.Sprintf(" %s ", meta.Bin)
if _, err := term.Head(w, 0,
fmt.Sprintf("Packaged example text and ANSI files to test and play with %s\n", meta.Name)); err != nil {
header := "Packaged example text and ANSI files to test and play with " + meta.Name
if _, err := term.Head(w, width, header); err != nil {
return err
}
for _, k := range keys {
fmt.Fprintf(w, "%s\t%s\t\n", k, m[k].Description)
}
fmt.Fprintf(w, "\nAny of these packaged examples will work with the %s and %s commands.\n",
term.Example("info"), term.Example("view"))
fmt.Fprintln(w)
for _, k := range keys {
fmt.Fprintf(w, " %s\t%s\t\n", k, m[k].Description)
}
fmt.Fprintln(w)
if _, err := term.Head(w, width, "Usage sample commands"); err != nil {
return err
}
fmt.Fprintf(w, "\nPrint the Windows-1252 English test to the terminal.\n%s\n",
term.Example(bin+"view 1252"))
fmt.Fprintf(w, "\nConvert the Windows-1252 English test to UTF-8 encoding and save it to a file.\n%s\n",
Expand Down
25 changes: 13 additions & 12 deletions pkg/info/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,35 +149,35 @@ func (d *Detail) Marshal(w io.Writer, f Format) error {
if w == nil {
w = io.Discard
}
var err error
var b []byte
switch f {
case ColorText:
return d.marshal(w, true)
case PlainText:
return d.marshal(w, false)
case JSON:
b, err = json.MarshalIndent(d, "", " ")
b, err := json.MarshalIndent(d, "", " ")
if err != nil {
return fmt.Errorf("detail json indent marshal: %w", err)
}
_, err = w.Write(b)
return err
case JSONMin:
b, err = json.Marshal(d)
b, err := json.Marshal(d)
if err != nil {
return fmt.Errorf("detail json marshal: %w", err)
}
_, err = w.Write(b)
return err
case XML:
b, err = xml.MarshalIndent(d, "", "\t")
b, err := xml.MarshalIndent(d, "", "\t")
if err != nil {
return fmt.Errorf("detail xml marshal: %w", err)
}
_, err = w.Write(b)
return err
default:
return fmt.Errorf("detail marshal %q: %w", f, ErrFmt)
}
if _, err := w.Write(b); err != nil {
return fmt.Errorf("detail marshal write: %w", err)
}
return nil
}

// MimeUnknown detects non-Standard legacy data.
Expand Down Expand Up @@ -341,13 +341,14 @@ func (d *Detail) marshal(w io.Writer, color bool) error {
return fmt.Sprintf("%s\t", s)
}
gookit.Enable = color
if _, err := term.Head(w, width, "File information"); err != nil {
return err
}
fmt.Fprintln(w)
data := d.marshalled()
l := len(fmt.Sprintf(" filename%s%s", strings.Repeat(" ", padding), data[0].v))
const tabWidth = 8
tw := tabwriter.NewWriter(w, 0, tabWidth, 0, '\t', 0)
if _, err := term.Head(tw, width, "File information"); err != nil {
return err
}
for _, x := range data {
if !d.validate(x) {
continue
Expand Down
8 changes: 4 additions & 4 deletions pkg/table/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func List(wr io.Writer) error { //nolint:funlen
term.Example(cmds), term.Comment("latin1"), term.Fuzzy("# alias"))
fmt.Fprintf(w, "\n IBM Code Page 437 (%s) is commonly used on MS-DOS and ANSI art.\n",
term.Comment("cp437"))
fmt.Fprintf(w, " ISO 8859-1 (%s) is found on legacy Unix, Amiga and the early Internet.\n",
fmt.Fprintf(w, " ISO 8859-1 (%s) is found on historic Unix, Amiga and the early Internet.\n",
term.Comment("latin1"))
fmt.Fprintf(w, " Windows 1252 (%s) is found on legacy Windows 9x and earlier systems.\n",
fmt.Fprintf(w, " Windows 1252 (%s) is found on Windows ME/98 and earlier systems.\n",
term.Comment("cp1252"))
fmt.Fprintf(w, " Macintosh (%s) is found on Mac OS 9 and earlier systems.\n",
term.Comment("macintosh"))
fmt.Fprintf(w, "\n%s, PCs and the web today use Unicode UTF-8. As a subset of ISO 8895-1,\n", meta.Name)
fmt.Fprintln(w, "UTF-8 is backwards compatible with it and US-ASCII.")
fmt.Fprintf(w, "\n%s, PCs and the web today use Unicode UTF-8. As a subset,\n", meta.Name)
fmt.Fprintln(w, "UTF-8 is backwards compatible with both ISO 8895-1 and US-ASCII.")
return w.Flush()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
)

const (
width = 67
width = 68
)

// Table prints out all the characters in the named 8-bit character set.
Expand Down

0 comments on commit 70f8957

Please sign in to comment.