|
|
@ -3,10 +3,10 @@ |
|
|
|
package mop |
|
|
|
package mop |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"regexp" |
|
|
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/michaeldv/just" |
|
|
|
"github.com/michaeldv/just" |
|
|
|
"github.com/nsf/termbox-go" |
|
|
|
"github.com/nsf/termbox-go" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
|
|
|
|
"strings" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Can combine attributes and a single color using bitwise OR.
|
|
|
|
// Can combine attributes and a single color using bitwise OR.
|
|
|
@ -15,7 +15,7 @@ import ( |
|
|
|
// AttrUnderline
|
|
|
|
// AttrUnderline
|
|
|
|
// AttrReverse
|
|
|
|
// AttrReverse
|
|
|
|
//
|
|
|
|
//
|
|
|
|
var colors = map[string]termbox.Attribute{ |
|
|
|
var tags = map[string]termbox.Attribute{ |
|
|
|
"black": termbox.ColorBlack, |
|
|
|
"black": termbox.ColorBlack, |
|
|
|
"red": termbox.ColorRed, |
|
|
|
"red": termbox.ColorRed, |
|
|
|
"green": termbox.ColorGreen, |
|
|
|
"green": termbox.ColorGreen, |
|
|
@ -24,6 +24,7 @@ var colors = map[string]termbox.Attribute{ |
|
|
|
"magenta": termbox.ColorMagenta, |
|
|
|
"magenta": termbox.ColorMagenta, |
|
|
|
"cyan": termbox.ColorCyan, |
|
|
|
"cyan": termbox.ColorCyan, |
|
|
|
"white": termbox.ColorWhite, |
|
|
|
"white": termbox.ColorWhite, |
|
|
|
|
|
|
|
"right": termbox.ColorDefault, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@ -37,17 +38,17 @@ func Draw(stocks string) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Return regular expression that matches all possible color tags, i.e.
|
|
|
|
// Return regular expression that matches all possible tags, i.e.
|
|
|
|
// </?black>|</?red>| ... |</?white>
|
|
|
|
// </?black>|</?red>| ... |</?white>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func tagsRegexp() *regexp.Regexp { |
|
|
|
func tagsRegexp() *regexp.Regexp { |
|
|
|
tags := []string{} |
|
|
|
arr := []string{} |
|
|
|
|
|
|
|
|
|
|
|
for color, _ := range colors { |
|
|
|
for tag, _ := range tags { |
|
|
|
tags = append(tags, "</?"+color+">") |
|
|
|
arr = append(arr, "</?"+tag+">") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return regexp.MustCompile(strings.Join(tags, "|")) |
|
|
|
return regexp.MustCompile(strings.Join(arr, "|")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -72,23 +73,34 @@ func tagName(str string) string { |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func drawLine(x int, y int, str string) { |
|
|
|
func drawLine(x int, y int, str string) { |
|
|
|
column := 0 |
|
|
|
column, right := 0, false |
|
|
|
foreground, background := termbox.ColorDefault, termbox.ColorDefault |
|
|
|
foreground, background := termbox.ColorDefault, termbox.ColorDefault |
|
|
|
|
|
|
|
|
|
|
|
for _, token := range just.Split(tagsRegexp(), str) { |
|
|
|
for _, token := range just.Split(tagsRegexp(), str) { |
|
|
|
if tag, open := isTag(token); tag { |
|
|
|
if tag, open := isTag(token); tag { |
|
|
|
if color, ok := colors[tagName(token)]; ok { |
|
|
|
key := tagName(token) |
|
|
|
|
|
|
|
if value, ok := tags[key]; ok { |
|
|
|
token = "" |
|
|
|
token = "" |
|
|
|
|
|
|
|
switch key { |
|
|
|
|
|
|
|
case "right": |
|
|
|
|
|
|
|
right = open |
|
|
|
|
|
|
|
default: |
|
|
|
if open { |
|
|
|
if open { |
|
|
|
foreground = color |
|
|
|
foreground = value |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
foreground = termbox.ColorDefault |
|
|
|
foreground = termbox.ColorDefault |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, char := range token { |
|
|
|
for i, char := range token { |
|
|
|
|
|
|
|
if !right { |
|
|
|
termbox.SetCell(x+column, y, char, foreground, background) |
|
|
|
termbox.SetCell(x+column, y, char, foreground, background) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
width, _ := termbox.Size() |
|
|
|
|
|
|
|
termbox.SetCell(width-len(token)+i, y, char, foreground, background) |
|
|
|
|
|
|
|
} |
|
|
|
column += 1 |
|
|
|
column += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|