Skip to content

Commit

Permalink
Reset formatting after rendering a styled token
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed Jul 25, 2023
1 parent ace1970 commit 87ef19e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.3] - 25.07.2023

[Diff](https://github.com/elk-language/go-prompt/compare/v1.0.2...elk-language:go-prompt:v1.0.3)

### Fixed
- Reset formatting after rendering a styled token
- Fix unit tests

## [1.0.2] - 25.07.2023

[Diff](https://github.com/elk-language/go-prompt/compare/v1.0.1...elk-language:go-prompt:v1.0.2)
Expand Down
1 change: 1 addition & 0 deletions buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func TestBuffer_CursorDown(t *testing.T) {
b := NewBuffer()
b.InsertTextMoveCursor("line1\nline2", DefColCount, DefRowCount, false)
b.cursorPosition = 3
b.preferredColumn = -1

// Normally going down
b.CursorDown(1, DefColCount, DefRowCount)
Expand Down
6 changes: 6 additions & 0 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ tokenLoop:
lineBuffer = append(lineBuffer, '\n')
r.out.SetDisplayAttributes(color, backgroundColor, displayAttributes...)
r.write(lineBuffer)
r.resetFormatting()
r.renderPrefix(multilinePrefix)
lineBuffer = lineBuffer[:0]
if char != '\n' {
Expand All @@ -429,6 +430,7 @@ tokenLoop:
if len(lineBuffer) > 0 {
r.out.SetDisplayAttributes(color, backgroundColor, displayAttributes...)
r.write(lineBuffer)
r.resetFormatting()
}

if !interToken {
Expand All @@ -447,6 +449,10 @@ tokenLoop:
}
}

r.resetFormatting()
}

func (r *Renderer) resetFormatting() {
r.out.SetDisplayAttributes(r.inputTextColor, r.inputBGColor, DisplayReset)
}

Expand Down

0 comments on commit 87ef19e

Please sign in to comment.