-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Kiura/mac-os-newline-bugfix
Mac os newline bugfix
- Loading branch information
Showing
4 changed files
with
99 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package themes | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var defaultSymbolsFinished = []rune("█◎▭☢≈⋮─━═=╸") | ||
var defaultTheme = []rune("█ ||") | ||
|
||
// New returns a new theme | ||
func New(symbols ...string) []string { | ||
symbols = append(symbols, make([]string, 4-len(symbols))...) | ||
for i, _ := range symbols { | ||
if len(symbols[i]) == 0 { | ||
symbols[i] = string(defaultTheme[i]) | ||
} | ||
} | ||
return []string{ | ||
symbols[0], | ||
symbols[1], | ||
symbols[2], | ||
symbols[3], | ||
} | ||
} | ||
|
||
// NewDefault returns nth theme from default themes | ||
func NewDefault(n uint8) ([]string, error) { | ||
if n > uint8(len(defaultSymbolsFinished)) { | ||
return nil, errors.New("n must be less than defined themes") | ||
} | ||
return New(string(defaultSymbolsFinished[n])), nil | ||
} | ||
|
||
func NewFromRunes(symbols []rune) ([]string, error) { | ||
if len(symbols) != 4 { | ||
return []string{}, errors.New("symbols lenght must be exactly 4") | ||
} | ||
return []string{ | ||
string(symbols[0]), | ||
string(symbols[1]), | ||
string(symbols[2]), | ||
string(symbols[3]), | ||
}, nil | ||
} |
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,9 @@ | ||
package themes | ||
|
||
import "testing" | ||
|
||
func TestNewDefault(t *testing.T) { | ||
if _, err := NewDefault(uint8(len(defaultSymbolsFinished) + 1)); err == nil { | ||
t.Error("should have an error if n > default themes") | ||
} | ||
} |