From 9d138173be9845fc7f2cbeab58b41f27a1f8043f Mon Sep 17 00:00:00 2001
From: Junegunn Choi <junegunn.c@gmail.com>
Date: Mon, 23 Mar 2015 01:24:31 +0900
Subject: [PATCH] Fix #155 - Empty ANSI color code to reset color state

---
 src/ansi.go      | 3 +++
 src/ansi_test.go | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/src/ansi.go b/src/ansi.go
index 42c69166..f4c8f5a0 100644
--- a/src/ansi.go
+++ b/src/ansi.go
@@ -99,6 +99,9 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
 	}
 
 	ansiCode = ansiCode[2 : len(ansiCode)-1]
+	if len(ansiCode) == 0 {
+		init()
+	}
 	for _, code := range strings.Split(ansiCode, ";") {
 		if num, err := strconv.Atoi(code); err == nil {
 			switch state256 {
diff --git a/src/ansi_test.go b/src/ansi_test.go
index d5e0e432..be982eb4 100644
--- a/src/ansi_test.go
+++ b/src/ansi_test.go
@@ -45,6 +45,14 @@ func TestExtractColor(t *testing.T) {
 		assert(offsets[0], 0, 11, -1, -1, true)
 	})
 
+	src = "\x1b[1mhello \x1b[mworld"
+	check(func(offsets []ansiOffset) {
+		if len(offsets) != 1 {
+			t.Fail()
+		}
+		assert(offsets[0], 0, 6, -1, -1, true)
+	})
+
 	src = "hello \x1b[34;45;1mworld"
 	check(func(offsets []ansiOffset) {
 		if len(offsets) != 1 {
-- 
GitLab