1
1
mirror of https://github.com/walles/moar.git synced 2024-11-26 13:46:16 +03:00
Commit Graph

10 Commits

Author SHA1 Message Date
Johan Walles
5e847f4cd7 Improve large file reading performance by 10%
By reading the file in two passes.

The first pass just counts the lines in the file.

The second pass starts by preallocating the correct number of lines, and
then reads the file.

The whole time saving comes from not having to dynamically resize the
lines slice while reading the file.
2021-05-03 20:33:25 +02:00
Johan Walles
a9ee2fae9d Support SGR codes 90-97, bright colors
We just treat them as their plain counterparts.

After testing vs less and cat on iTerm2 3.3.9 / macOS Catalina 10.15.4
that's how they seem to handle this. Counter examples welcome.

Fixes #24
2020-04-22 21:39:58 +02:00
Johan Walles
b25cfc692e Make start of line identifiable
Change-Id: I1fa4b4fa5b25ec58b418a53dbb4d38b6f473d172
2019-11-19 16:21:58 +01:00
Johan Walles
aaa25b74f3 Add sample file with a long line
This file breaks the test suite.

Change-Id: I510e1ddf98dadb02d1848702e9e83aaacf0f6e78
2019-11-19 15:33:50 +01:00
Johan Walles
b781d09a72 Add another test case
diff --git m/reader_test.go m/reader_test.go
index 176192b..bed1e33 100644
--- m/reader_test.go
+++ m/reader_test.go
@@ -30,6 +30,12 @@ func _TestGetLineCount(t *testing.T, reader *Reader) {
 	if err != nil {
 		t.Error("Error counting lines of", *reader.name, err)
 	}
+
+	if strings.HasSuffix(*reader.name, "/line-without-newline.txt") {
+		// "wc -l" thinks this file contains zero lines
+		fileLineCount = 1
+	}
+
 	if reader.GetLineCount() != fileLineCount {
 		t.Errorf("Got %d lines but expected %d: <%s>",
 			reader.GetLineCount(), fileLineCount, *reader.name)
diff --git sample-files/line-without-newline.txt sample-files/line-without-newline.txt
new file mode 100644
index 0000000..2260c57
--- /dev/null
+++ sample-files/line-without-newline.txt
@@ -0,0 +1 @@
+This file contains no newlines
\ No newline at end of file

Change-Id: Ic2801ce3477a7afd4537d340385c884c5f2b7438
2019-11-19 14:47:44 +01:00
Johan Walles
7405293e25 Add sample file for color handling
From #14
2019-10-28 21:54:57 +01:00
Johan Walles
ebba21a409 Dodge corner case issue
If call "highlight" on an empty file the output will have a line.

We don't really care about that.

This change renames empty.txt (which highlight wants to highlight) into
just "empty", which highlight will not try to highligt, so no line is
added and the test passes.
2019-07-15 18:49:25 +02:00
Johan Walles
e640c7d856 Add (failing) compressed-files tests 2019-06-23 21:30:11 +02:00
Johan Walles
da30eaf956 Handle displaying empty files
And introduce a unit test!
2019-06-13 20:04:51 +02:00
Johan Walles
f3097e7450 Reboot in Go 2019-06-08 22:12:52 +02:00