Skip to content

Commit

Permalink
Move textstyles into the (mostly) not-public part
Browse files Browse the repository at this point in the history
I don't foresee this ever being published for anybody else to use.
  • Loading branch information
walles committed Jan 5, 2024
1 parent dc0243f commit 55e2daf
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 37 deletions.
2 changes: 1 addition & 1 deletion m/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package m
import (
"regexp"

"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
)

Expand Down
2 changes: 1 addition & 1 deletion m/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/alecthomas/chroma/v2"
log "github.com/sirupsen/logrus"
"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
)

Expand Down
2 changes: 1 addition & 1 deletion m/pager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/google/go-cmp/cmp"
"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
"gotest.tools/v3/assert"
)
Expand Down
27 changes: 9 additions & 18 deletions m/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"testing"
Expand All @@ -17,6 +16,8 @@ import (

//revive:disable:empty-block

const samplesDir = "../sample-files"

func testGetLineCount(t *testing.T, reader *Reader) {
if strings.Contains(*reader.name, "compressed") {
// We are no good at counting lines of compressed files, never mind
Expand Down Expand Up @@ -114,25 +115,15 @@ func testGetLines(t *testing.T, reader *Reader) {
}
}

func getSamplesDir() string {
// From: https://coderwall.com/p/_fmbug/go-get-path-to-current-file
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Getting current filename failed")
}

return path.Join(path.Dir(filename), "../sample-files")
}

func getTestFiles() []string {
files, err := os.ReadDir(getSamplesDir())
files, err := os.ReadDir(samplesDir)
if err != nil {
panic(err)
}

var filenames []string
for _, file := range files {
filenames = append(filenames, "../sample-files/"+file.Name())
filenames = append(filenames, path.Join(samplesDir, file.Name()))
}

return filenames
Expand Down Expand Up @@ -281,7 +272,7 @@ func TestStatusText(t *testing.T) {
testStatusText(t, 1, 1, 1, "1 line 100%")

// Test with filename
testMe, err := NewReaderFromFilename(getSamplesDir()+"/empty", *styles.Get("native"), formatters.TTY16m, nil)
testMe, err := NewReaderFromFilename(samplesDir+"/empty", *styles.Get("native"), formatters.TTY16m, nil)
if err != nil {
panic(err)
}
Expand All @@ -295,7 +286,7 @@ func TestStatusText(t *testing.T) {
}

func testCompressedFile(t *testing.T, filename string) {
filenameWithPath := getSamplesDir() + "/" + filename
filenameWithPath := path.Join(samplesDir, filename)
reader, e := NewReaderFromFilename(filenameWithPath, *styles.Get("native"), formatters.TTY16m, nil)
if e != nil {
t.Errorf("Error opening file <%s>: %s", filenameWithPath, e.Error())
Expand Down Expand Up @@ -365,7 +356,7 @@ func TestFilterNotAFile(t *testing.T) {
//
// Run with: go test -run='^$' -bench=. . ./...
func BenchmarkReaderDone(b *testing.B) {
filename := getSamplesDir() + "/../m/pager.go" // This is our longest .go file
filename := "pager.go" // This is our longest .go file
b.ResetTimer()
for n := 0; n < b.N; n++ {
// This is our longest .go file
Expand All @@ -390,7 +381,7 @@ func BenchmarkReadLargeFile(b *testing.B) {
const largeSizeBytes = 35_000_000

// First, create it from something...
inputFilename := getSamplesDir() + "/../m/pager.go"
inputFilename := "pager.go"
contents, err := os.ReadFile(inputFilename)
if err != nil {
panic(err)
Expand Down Expand Up @@ -436,7 +427,7 @@ func BenchmarkReadLargeFile(b *testing.B) {
// Count lines in pager.go
func BenchmarkCountLines(b *testing.B) {
// First, get some sample lines...
inputFilename := getSamplesDir() + "/../m/pager.go"
inputFilename := "pager.go"
contents, err := os.ReadFile(inputFilename)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion m/screenLines.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package m
import (
"fmt"

"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
)

Expand Down
2 changes: 1 addition & 1 deletion m/styling.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/alecthomas/chroma/v2"
log "github.com/sirupsen/logrus"
"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path"
"runtime"
"strings"
"testing"
"unicode/utf8"
Expand All @@ -17,6 +16,8 @@ import (
"gotest.tools/v3/assert"
)

const samplesDir = "../../sample-files"

// Convert a cells array to a plain string
func cellsToPlainString(cells []twin.Cell) string {
returnMe := ""
Expand All @@ -27,25 +28,15 @@ func cellsToPlainString(cells []twin.Cell) string {
return returnMe
}

func getSamplesDir() string {
// From: https://coderwall.com/p/_fmbug/go-get-path-to-current-file
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Getting current filename failed")
}

return path.Join(path.Dir(filename), "../sample-files")
}

func getTestFiles() []string {
files, err := os.ReadDir(getSamplesDir())
files, err := os.ReadDir(samplesDir)
if err != nil {
panic(err)
}

var filenames []string
for _, file := range files {
filenames = append(filenames, "../sample-files/"+file.Name())
filenames = append(filenames, path.Join(samplesDir, file.Name()))
}

return filenames
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion moar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/term"

"github.com/walles/moar/m"
"github.com/walles/moar/textstyles"
"github.com/walles/moar/m/textstyles"
"github.com/walles/moar/twin"
)

Expand Down

0 comments on commit 55e2daf

Please sign in to comment.