Skip to content

Conversation

@winterka
Copy link
Contributor

Resolving this one: #152

Tried to follow your code-style, architecture and approaches. There might and I guess there are some naming issues, feel free to point them out and I'd fix them if needed.

Олег Талантов added 3 commits December 17, 2025 09:21
@winterka winterka changed the title Feat/regex search support feat/regex-search-support Dec 17, 2025
@winterka
Copy link
Contributor Author

fixed PR title

@petric3
Copy link

petric3 commented Dec 17, 2025

Thank you for the effort, I tried something, but am not sure if this is correct (am just mechanical engineer, user, not skilled in coding).

Seems correct version is installed as there's RegExpoption:
2025-12-17_19-07

Tried some minimal working example (mwe.log):
2025-12-17_19-08

Result:
2025-12-17_19-09

@winterka
Copy link
Contributor Author

would look into it, @petric3 could you please provide some kind of sanitized (without any sensitive data) log file (.json i guess) so i could debug it ?

@petric3
Copy link

petric3 commented Dec 17, 2025

I did attach the minimal working file, here it goes in raw version:

{"level":"info","time":"2025-12-16T13:20:00-05:00","message":"2025-12-16 13:20:00.049   Day1|  Ana went home!"}
{"level":"info","time":"2025-12-16T13:20:00-05:00","message":"2025-12-16 13:21:00.049  Day2| Tom was daydreaming"}
{"level":"info","time":"2025-12-16T13:20:00-05:00","message":"2025-12-16 13:22:00.049  Day3| Can't wait to be weekend!"}

Is this good enough?
Thank you 🙏

@winterka
Copy link
Contributor Author

winterka commented Dec 18, 2025

@petric3 Hello, I used your logs provided above and it seems to be working

изображение

UPD: Nevermind, could reproduce it, it seems to be case-related issue

@winterka
Copy link
Contributor Author

Updated it, now regexp seems to filter correctly

изображение

@petric3
Copy link

petric3 commented Dec 18, 2025

@winterka hey, I saw it and then reinstalled it and now it works also for me, great 👍 I've install a non-main version for the first time :) I guess did something wrong.

Great, hopefully it can be merged into main version soon. I'm gonna close the issue once merged. Thank you once more 🙏

Copy link
Owner

@hedhyw hedhyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: thank you for your contribution!

thought: regexes are powerful, but they seem too powerful and not very convenient for a TUI (easy to make a mistake). What about globs? https://github.com/gobwas/glob, which support simple abc*xyz or more advanced AND patterns {abc,xyz,123}. It's just a thing to discuss, I'm not saying it's the right way :)

note: the PR title should follow conventional commits:
https://www.conventionalcommits.org/en/v1.0.0/
it should be: feat: regex search support

}, nil
}

// FilterRegEx filters entries by regex ignoring case
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// FilterRegEx filters entries by regex ignoring case
// FilterRegEx filters entries by regex ignoring case.

It will fix a linter issue, you can try make lint

return s.BaseStyle.Render(s.table.View()) + "\n" + footer
}

func (s StateRegexFilteredModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can you please add comments to all exported methods?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: it's more flexible to have a dedicated state for regexp filtering - StateRegexFilteredModel (as you implemented). However it introduces a lot of boilerplate and still overlaps with StateFilteredModel. What about extending the latter? newStateFiltered -> newStateFilteredByText(previousState, filterText) and newStateFilteredByRegexp(previousState, filterRegexp).

return s, tea.Quit
case key.Matches(msg, s.keys.Filter):
return s.handleFilterKeyClickedMsg()
case key.Matches(msg, s.keys.FilterRegex):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: let's add the tests.

return entries, nil
}

re, err := regexp.Compile(strings.ToLower(regex))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: there’s a (?i) flag for case-insensitive matching, you just need to add it to the start of the regex if it isn't already there.

(?i)[a-z0-9]+ will match both AAAAA and aaaaaa

return LazyLogEntries{}, err
}

if re.Match([]byte(bytes.ToLower(line))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: we don't need to call ToLower if you include the (?i) flag

return entries, nil
}

re, err := regexp.Compile(strings.ToLower(regex))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: how will errors be reported? It would be annoying to loose everything after a small mistake in a regexp

@petric3
Copy link

petric3 commented Dec 19, 2025

praise: thank you for your contribution!

thought: regexes are powerful, but they seem too powerful and not very convenient for a TUI (easy to make a mistake). What about globs? https://github.com/gobwas/glob, which support simple abc*xyz or more advanced AND patterns {abc,xyz,123}. It's just a thing to discuss, I'm not saying it's the right way :)

note: the PR title should follow conventional commits: https://www.conventionalcommits.org/en/v1.0.0/ it should be: feat: regex search support

It's hard for me to comment on this one, really am just a simple user from this side. From my perspective, I use pretty big log files, so I'd simply go for what's faster solution. Regexp is pretty common nowadays (and probably optimized I guess), so got used to it and works for me fine. Also AND/OR solution sounds okey too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants