summaryrefslogtreecommitdiffstats
path: root/src/ansi.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-11-14 02:13:16 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-11-14 02:15:23 +0900
commitdc557c0d4ca3b4770757078308f966e8a90eb3c3 (patch)
tree1bd3aca717c35d8210b79939697ed4ee4bdad0b7 /src/ansi.go
parenta2beb159f1757961f1314b2739b5707ea2af2ea0 (diff)
Update ANSI processor to handle more VT-100 escape sequences
The updated regular expression should include not all but most of the frequently used ANSI sequences. Close #735.
Diffstat (limited to 'src/ansi.go')
-rw-r--r--src/ansi.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ansi.go b/src/ansi.go
index b7d3a9e3..427f7f4c 100644
--- a/src/ansi.go
+++ b/src/ansi.go
@@ -35,7 +35,16 @@ func (s *ansiState) equals(t *ansiState) bool {
var ansiRegex *regexp.Regexp
func init() {
- ansiRegex = regexp.MustCompile("\x1b\\[[0-9;]*.|[\x0e\x0f]")
+ /*
+ References:
+ - https://github.com/gnachman/iTerm2
+ - http://ascii-table.com/ansi-escape-sequences.php
+ - http://ascii-table.com/ansi-escape-sequences-vt-100.php
+ - http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html
+ */
+ // The following regular expression will include not all but most of the
+ // frequently used ANSI sequences
+ ansiRegex = regexp.MustCompile("\x1b[\\[()][0-9;]*[a-zA-Z@]|\x1b.|[\x08\x0e\x0f]")
}
func extractColor(str string, state *ansiState, proc func(string, *ansiState) bool) (string, *[]ansiOffset, *ansiState) {
@@ -100,7 +109,7 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
} else {
state = &ansiState{prevState.fg, prevState.bg, prevState.attr}
}
- if ansiCode[0] != '\x1b' || ansiCode[len(ansiCode)-1] != 'm' {
+ if ansiCode[0] != '\x1b' || ansiCode[1] != '[' || ansiCode[len(ansiCode)-1] != 'm' {
return state
}