-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cleaned up model. * Manage results with a stack. * Fixed segfault in tests.
- Loading branch information
1 parent
26a4a32
commit 21c1180
Showing
7 changed files
with
150 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package stack | ||
|
||
import "github.com/janderland/fdbq/internal/app/fullscreen/results" | ||
|
||
type ResultsStack struct { | ||
stack []results.Model | ||
|
||
height int | ||
wrapWidth int | ||
} | ||
|
||
func (x *ResultsStack) Push(model results.Model) { | ||
model.Height(x.height) | ||
model.WrapWidth(x.wrapWidth) | ||
x.stack = append(x.stack, model) | ||
} | ||
|
||
func (x *ResultsStack) Pop() { | ||
if len(x.stack) != 0 { | ||
x.stack = x.stack[:len(x.stack)-1] | ||
} | ||
} | ||
|
||
func (x *ResultsStack) Top() *results.Model { | ||
if len(x.stack) == 0 { | ||
return nil | ||
} | ||
return &x.stack[len(x.stack)-1] | ||
} | ||
|
||
func (x *ResultsStack) Height(height int) { | ||
x.height = height | ||
for i := range x.stack { | ||
x.stack[i].Height(height) | ||
} | ||
} | ||
|
||
func (x *ResultsStack) WrapWidth(width int) { | ||
x.wrapWidth = width | ||
for i := range x.stack { | ||
x.stack[i].WrapWidth(width) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package stack | ||
|
||
import ( | ||
"github.com/janderland/fdbq/internal/app/fullscreen/results" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestResultsStack(t *testing.T) { | ||
var ( | ||
x ResultsStack | ||
r1 = results.New() | ||
r2 = results.New() | ||
) | ||
|
||
require.Nil(t, x.Top()) | ||
|
||
x.Push(r1) | ||
require.Equal(t, &r1, x.Top()) | ||
|
||
x.Push(r2) | ||
require.Equal(t, &r2, x.Top()) | ||
|
||
x.Pop() | ||
require.Equal(t, &r1, x.Top()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.