Skip to content

Commit

Permalink
Moved New* after struct
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi committed Dec 31, 2019
1 parent a75163a commit ae0d036
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
12 changes: 6 additions & 6 deletions pkg/display/dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ type Dec struct {
zeroes int
}

func (d *Dec) SetFileSize(s int64) {
d.fs = uint64(s)
d.zeroes = len(string(d.fs))
d.offFormat = fmt.Sprintf(`%%0%vd`, d.zeroes)
}

func NewDec() *Dec {
return &Dec{
fs: 0,
sb: strings.Builder{},
}
}

func (d *Dec) SetFileSize(s int64) {
d.fs = uint64(s)
d.zeroes = len(string(d.fs))
d.offFormat = fmt.Sprintf(`%%0%vd`, d.zeroes)
}

func (d *Dec) Format(b byte, color clr.Color) string {
d.sb.Reset()
d.sb.WriteString(clr.Sprintf(`%03d `, clr.Colorize(b, color)))
Expand Down
13 changes: 7 additions & 6 deletions pkg/display/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ type Hex struct {
sb strings.Builder
}

func (d *Hex) SetFileSize(s int64) {
d.fs = uint64(s)
d.bw = nearest(uint8(bits.Len64(d.fs)))
d.offFormat = fmt.Sprintf(`%%0%vx`, d.bw/8)
}

func NewHex() *Hex {
return &Hex{
fs: 0,
sb: strings.Builder{},
}
}

func (d *Hex) SetFileSize(s int64) {
d.fs = uint64(s)
d.bw = nearest(uint8(bits.Len64(d.fs)))
d.offFormat = fmt.Sprintf(`%%0%vx`, d.bw/8)
}

func (d *Hex) Format(b byte, color clr.Color) string {
d.sb.Reset()
d.sb.WriteString(clr.Sprintf(`%02x `, clr.Colorize(b, color)))
Expand Down
13 changes: 7 additions & 6 deletions pkg/display/oct.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ type Oct struct {
zeroes int
}

func (d *Oct) SetFileSize(s int64) {
d.fs = uint64(s)
d.zeroes = len(fmt.Sprintf(`%o`, d.fs))
d.offFormat = fmt.Sprintf(`%%0%vo`, d.zeroes)
}

func NewOct() *Oct {
return &Oct{
fs: 0,
sb: strings.Builder{},
}
}

func (d *Oct) SetFileSize(s int64) {
d.fs = uint64(s)
d.zeroes = len(fmt.Sprintf(`%o`, d.fs))
d.offFormat = fmt.Sprintf(`%%0%vo`, d.zeroes)
}

func (d *Oct) Format(b byte, color clr.Color) string {
d.sb.Reset()
d.sb.WriteString(clr.Sprintf(`%03o `, clr.Colorize(b, color)))
Expand Down
8 changes: 4 additions & 4 deletions pkg/display/percent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ type Percent struct {
sb strings.Builder
}

func (d *Percent) SetFileSize(s int64) {
d.fs = uint64(s)
}

func NewPercent() *Percent {
return &Percent{
fs: 0,
sb: strings.Builder{},
}
}

func (d *Percent) SetFileSize(s int64) {
d.fs = uint64(s)
}

// FormatOffset displays offset as percentage 0% - 100%
func (d *Percent) FormatOffset(r iface.ReadSeekerCloser) string {
if d.fs == 0 {
Expand Down

0 comments on commit ae0d036

Please sign in to comment.