mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 20:23:50 -07:00
Refactor ANSI parser
This commit is contained in:
17
src/ansi.go
17
src/ansi.go
@@ -399,10 +399,15 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ansiCode) <= 3 {
|
reset := func() {
|
||||||
state.fg = -1
|
state.fg = -1
|
||||||
state.bg = -1
|
state.bg = -1
|
||||||
state.attr = 0
|
state.attr = 0
|
||||||
|
state.lbg = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ansiCode) <= 3 {
|
||||||
|
reset()
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
ansiCode = ansiCode[2 : len(ansiCode)-1]
|
ansiCode = ansiCode[2 : len(ansiCode)-1]
|
||||||
@@ -456,10 +461,7 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
|||||||
case 29:
|
case 29:
|
||||||
state.attr = state.attr &^ tui.StrikeThrough
|
state.attr = state.attr &^ tui.StrikeThrough
|
||||||
case 0:
|
case 0:
|
||||||
state.fg = -1
|
reset()
|
||||||
state.bg = -1
|
|
||||||
state.attr = 0
|
|
||||||
state.lbg = -1
|
|
||||||
state256 = 0
|
state256 = 0
|
||||||
default:
|
default:
|
||||||
if num >= 30 && num <= 37 {
|
if num >= 30 && num <= 37 {
|
||||||
@@ -499,10 +501,7 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
|||||||
|
|
||||||
// Empty sequence: reset
|
// Empty sequence: reset
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
state.fg = -1
|
reset()
|
||||||
state.bg = -1
|
|
||||||
state.attr = 0
|
|
||||||
state.lbg = -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if state256 > 0 {
|
if state256 > 0 {
|
||||||
|
Reference in New Issue
Block a user