-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
table: style option to color borders/separators (#259)
- Loading branch information
Showing
5 changed files
with
137 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package text | ||
|
||
import "strings" | ||
|
||
// Constants | ||
const ( | ||
CSIStartRune = rune(91) // [ | ||
CSIStopRune = 'm' | ||
EscapeReset = EscapeStart + "0" + EscapeStop | ||
EscapeStart = "\x1b[" | ||
EscapeStartRune = rune(27) // \x1b | ||
EscapeStop = "m" | ||
EscapeStopRune = 'm' | ||
OSIStartRune = rune(93) // ] | ||
OSIStopRune = '\\' | ||
) | ||
|
||
type escKind int | ||
|
||
const ( | ||
escKindUnknown escKind = iota | ||
escKindCSI | ||
escKindOSI | ||
) | ||
|
||
type escSeq struct { | ||
isIn bool | ||
content strings.Builder | ||
kind escKind | ||
} | ||
|
||
func (e *escSeq) InspectRune(r rune) { | ||
if !e.isIn && r == EscapeStartRune { | ||
e.isIn = true | ||
e.kind = escKindUnknown | ||
e.content.Reset() | ||
e.content.WriteRune(r) | ||
} else if e.isIn { | ||
switch { | ||
case e.kind == escKindUnknown && r == CSIStartRune: | ||
e.kind = escKindCSI | ||
case e.kind == escKindUnknown && r == OSIStartRune: | ||
e.kind = escKindOSI | ||
case e.kind == escKindCSI && r == CSIStopRune || e.kind == escKindOSI && r == OSIStopRune: | ||
e.isIn = false | ||
e.kind = escKindUnknown | ||
} | ||
e.content.WriteRune(r) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters