Skip to content

338: fix: move highlighting after formatting#339

Merged
superbrothers merged 9 commits into
stern:masterfrom
TeaDove:master
May 27, 2025
Merged

338: fix: move highlighting after formatting#339
superbrothers merged 9 commits into
stern:masterfrom
TeaDove:master

Conversation

@TeaDove

@TeaDove TeaDove commented Mar 13, 2025

Copy link
Copy Markdown
Contributor

Closes issue: 338

Highlighting was moved after templating

@TeaDove

TeaDove commented Mar 13, 2025

Copy link
Copy Markdown
Contributor Author

more details here in original issue: #338

@superbrothers

Copy link
Copy Markdown
Member

I will check the PR this weekend.

Comment thread stern/tail.go Outdated
Comment on lines 221 to 225
if withHighlight {
fmt.Fprint(t.out, t.Options.HighlightMatchedString(buf.String()))
return
}
fmt.Fprint(t.out, buf.String())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if withHighlight {
fmt.Fprint(t.out, t.Options.HighlightMatchedString(buf.String()))
return
}
fmt.Fprint(t.out, buf.String())
fmt.Fprint(t.out, t.Options.HighlightMatchedString(buf.String()))

Some error messages may be highlighted, but I think the above change is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's rare case, imho, but if it required, I can add feature to exclude highlight from errors

@superbrothers superbrothers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If possible, I would like you to add tests.

@TeaDove

TeaDove commented Apr 19, 2025

Copy link
Copy Markdown
Contributor Author

If possible, I would like you to add tests.

Sorry for late update, had no time:(

I've added tests!

Comment thread stern/file_tail.go Outdated

// Print prints a color coded log message
func (t *FileTail) Print(msg string) {
func (t *FileTail) Print(msg string, withHighlight bool) {

@superbrothers superbrothers May 11, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late review.

Instead of adding the withHighlight argument, I would like to add a new PrintWithoutHighlight function that print message without highlight.

func (t *Tail) sprint(msg string) string {
	...
}

// Print prints a color coded log message with the pod and container names
func (t *Tail) Print(msg string) {
	fmt.Fprint(t.out, t.Options.HighlightMatchedString(t.sprint(msg)))
}

// PrintWithoutHighlight prints a log message without applying any highlight.
func (t *Tail) PrintWithoutHighlight(msg string) {
	fmt.Fprint(t.out, t.sprint(msg))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@TeaDove TeaDove requested a review from superbrothers May 23, 2025 21:05
@superbrothers superbrothers merged commit 6d915a8 into stern:master May 27, 2025
4 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 9, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [stern/stern](https://github.com/stern/stern) | minor | `v1.32.0` -> `v1.33.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>stern/stern (stern/stern)</summary>

### [`v1.33.0`](https://github.com/stern/stern/blob/HEAD/CHANGELOG.md#v1330)

[Compare Source](stern/stern@v1.32.0...v1.33.0)

#### ⚡ Notable Changes

##### New template variables `Labels` and `Annotations`

You can now use `Labels` and `Annotations` in your templates.

```
stern -n kube-system -l component --template '{{printf "%-25s %s" .Labels.component .Message}}{{"\n"}}'
```

#### Changes

- Update dependencies for Kubernetes 1.34 ([#&#8203;349](stern/stern#349)) [`d6a0679`](stern/stern@d6a0679) (Takashi Kusumi)
- Fix asdf installation typo ([#&#8203;348](stern/stern#348)) [`5946e7f`](stern/stern@5946e7f) (Guruprasad Bhat)
- 338: fix: move highlighting after formatting ([#&#8203;339](stern/stern#339)) [`6d915a8`](stern/stern@6d915a8) (Peter)
- Add support for labels & annotations in templates ([#&#8203;344](stern/stern#344)) [`3cd85b4`](stern/stern@3cd85b4) (Nicholas Hurden)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45Ny45IiwidXBkYXRlZEluVmVyIjoiNDEuOTcuOSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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.

2 participants