~yerinalexey/rex

25eea29ab51a0a4d601dd48b6b3e56f66eefc90c — Alexey Yerin 3 months ago 61aeb89
Strip \r from lines

This fixes issues with files using CRLF as line ending.
2 files changed, 6 insertions(+), 3 deletions(-)

M README.md
M main.go
M README.md => README.md +2 -2
@@ 36,8 36,8 @@ e.g. use `make install DESTDIR="$pkgdir" PREFIX=/usr` on Arch and Alpine.
$ rex [flags] [file]
```

Rex reads `file` where each line (separated by line feed, `\n`) is a test match.
If missing, the text is read from standard input.
Rex reads `file` where each line is a test match. If missing, the text is read
from standard input.

The interface consists of an input field with a regular expression to use, and
the file colored depending on what lines match that regular expression.

M main.go => main.go +4 -1
@@ 75,8 75,11 @@ func regexWorker(in chan string, tests string, out *tview.TextView) {

			out.Clear()

			// TODO: crlf?
			for _, line := range strings.Split(tests, "\n") {
				// Here we strip \r that might come from files with CRLF,
				// which causes issues with matching $
				line = strings.TrimSuffix(line, "\r")
			
				matches := rg.MatchString(line)

				color := "red"