From 87ef19efcb9635a6aa2762e17cb667403ca5d36e Mon Sep 17 00:00:00 2001 From: Mateusz Drewniak Date: Tue, 25 Jul 2023 20:57:05 +0200 Subject: [PATCH] Reset formatting after rendering a styled token --- CHANGELOG.md | 8 ++++++++ buffer_test.go | 1 + renderer.go | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d2b07d..76295b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/buffer_test.go b/buffer_test.go index 0db735a0..a8fea1c0 100644 --- a/buffer_test.go +++ b/buffer_test.go @@ -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) diff --git a/renderer.go b/renderer.go index ff04573e..017874ed 100644 --- a/renderer.go +++ b/renderer.go @@ -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' { @@ -429,6 +430,7 @@ tokenLoop: if len(lineBuffer) > 0 { r.out.SetDisplayAttributes(color, backgroundColor, displayAttributes...) r.write(lineBuffer) + r.resetFormatting() } if !interToken { @@ -447,6 +449,10 @@ tokenLoop: } } + r.resetFormatting() +} + +func (r *Renderer) resetFormatting() { r.out.SetDisplayAttributes(r.inputTextColor, r.inputBGColor, DisplayReset) }