Skip to content

Commit

Permalink
Fix more linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lammel committed Jul 19, 2023
1 parent 3ffca3f commit e8fa94d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
12 changes: 9 additions & 3 deletions area.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ type Area struct {
// NewArea returns a new Area.
func NewArea() Area {
return Area{
writer: os.Stdout,
cursor: cursor,
height: 0,
writer: os.Stdout,
cursor: cursor,
cursorPosY: 0,

Check warning on line 24 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L21-L24

Added lines #L21 - L24 were not covered by tests
}
}

// WithWriter sets the custom writer
// WithWriter sets the custom writer.
func (area Area) WithWriter(writer Writer) Area {
area.writer = writer
area.cursor = area.cursor.WithWriter(writer)

Check warning on line 31 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L31

Added line #L31 was not covered by tests

return area
}

Expand All @@ -36,6 +39,7 @@ func (area *Area) Clear() {
if area.writer == nil {
area.writer = os.Stdout

Check warning on line 40 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

if area.height > 0 {
area.Bottom()
area.ClearLinesUp(area.height)
Expand All @@ -59,6 +63,7 @@ func (area *Area) Up(n int) {
if area.cursorPosY+n > area.height {
n = area.height - area.cursorPosY - 1

Check warning on line 64 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L62-L64

Added lines #L62 - L64 were not covered by tests
}

area.cursor.Up(n)
area.cursorPosY += n

Check warning on line 68 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}
Expand All @@ -70,6 +75,7 @@ func (area *Area) Down(n int) {
if area.height-area.cursorPosY-n < 0 {
n = area.height - area.cursorPosY

Check warning on line 76 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L74-L76

Added lines #L74 - L76 were not covered by tests
}

area.cursor.Down(n)
area.cursorPosY -= n

Check warning on line 80 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L79-L80

Added lines #L79 - L80 were not covered by tests
}
Expand Down
3 changes: 2 additions & 1 deletion cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Cursor struct {
writer Writer
}

// NewCursor creates a new Cursor instance writing to os.Stdout
// NewCursor creates a new Cursor instance writing to os.Stdout.
func NewCursor() *Cursor {
return &Cursor{writer: os.Stdout}

Check warning on line 19 in cursor.go

View check run for this annotation

Codecov / codecov/patch

cursor.go#L19

Added line #L19 was not covered by tests
}
Expand All @@ -25,6 +25,7 @@ func (c *Cursor) WithWriter(w Writer) *Cursor {
if w != nil {
c.writer = w

Check warning on line 26 in cursor.go

View check run for this annotation

Codecov / codecov/patch

cursor.go#L25-L26

Added lines #L25 - L26 were not covered by tests
}

return c

Check warning on line 29 in cursor.go

View check run for this annotation

Codecov / codecov/patch

cursor.go#L29

Added line #L29 was not covered by tests
}

Expand Down
4 changes: 3 additions & 1 deletion cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ func TestHeightChanges(t *testing.T) {
for i := 0; i < 4; i++ {
fmt.Println()
}

Up(3)

if autoheight != 3 {
t.Errorf("height should be 3 but is %d", autoheight)
}

Down(3)

if autoheight != 0 {
t.Errorf("height should be 0 but is %d", autoheight)
}
}

func TestHeightCannotBeNegative(t *testing.T) {
Down(10)

if autoheight < 0 {
t.Errorf("height is negative: %d", autoheight)
}
Expand Down
4 changes: 3 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Writer interface {
}

// SetTarget sets to output target of the default curser to the
// provided cursor.Writer (wrapping io.Writer)
// provided cursor.Writer (wrapping io.Writer).
func SetTarget(w Writer) {
cursor = cursor.WithWriter(w)

Check warning on line 24 in utils.go

View check run for this annotation

Codecov / codecov/patch

utils.go#L24

Added line #L24 was not covered by tests
}
Expand All @@ -33,6 +33,7 @@ func Up(n int) {
// Down moves the cursor n lines down relative to the current position.
func Down(n int) {
cursor.Down(n)

if autoheight > 0 {
autoheight -= n
}
Expand Down Expand Up @@ -84,6 +85,7 @@ func Bottom() {
if autoheight > 0 {
Down(autoheight)

Check warning on line 86 in utils.go

View check run for this annotation

Codecov / codecov/patch

utils.go#L85-L86

Added lines #L85 - L86 were not covered by tests
StartOfLine()

autoheight = 0

Check warning on line 89 in utils.go

View check run for this annotation

Codecov / codecov/patch

utils.go#L89

Added line #L89 was not covered by tests
}
}
Expand Down

0 comments on commit e8fa94d

Please sign in to comment.