From e57f37292628008a6cd5b7d64878146bff99419e Mon Sep 17 00:00:00 2001 From: Sergey Grebenshchikov Date: Sat, 31 Mar 2018 19:52:46 +0200 Subject: Add full-bw and full-wb canvas types --- Makefile | 2 +- README.md | 2 +- README.template.md | 3 ++- cmd/jp/main.go | 23 ++++++++++++++++------- docs/hist2d_full_escape.png | Bin 0 -> 113364 bytes pkg/draw/full_escape.go | 41 +++++++++++++++++++++++++++++++++++++++-- 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 docs/hist2d_full_escape.png diff --git a/Makefile b/Makefile index afc6fc5..d3acee4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 1.1.10 +VERSION = 1.1.11 APP := jp PACKAGES := $(shell go list -f {{.Dir}} ./...) diff --git a/README.md b/README.md index 692a1da..61a881e 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Usage of jp: -width int Plot width (default 0 (auto)) -canvas value - Canvas type. One of [full full-escape quarter braille auto] (default auto) + Canvas type. One of [full full-escape full-bw full-wb quarter braille auto] (default auto) ``` ## Examples diff --git a/README.template.md b/README.template.md index ad8b0cb..6874cff 100644 --- a/README.template.md +++ b/README.template.md @@ -74,7 +74,7 @@ Usage of jp: -width int Plot width (default 0 (auto)) -canvas value - Canvas type. One of [full full-escape quarter braille auto] (default auto) + Canvas type. One of [full full-escape full-bw full-wb quarter braille auto] (default auto) ``` ## Examples @@ -415,6 +415,7 @@ In case you're on mobile, here's some PNGs of what `jp` output looks like: ![Line chart](docs/line_chart.png) +![Heatmap](docs/hist2d_full_escape.png) ## Licensing diff --git a/cmd/jp/main.go b/cmd/jp/main.go index 6769e1c..cc1d9b8 100644 --- a/cmd/jp/main.go +++ b/cmd/jp/main.go @@ -35,11 +35,13 @@ const ( ) const ( - canvasTypeFull = "full" - canvasTypeFullEscape = "full-escape" - canvasTypeQuarter = "quarter" - canvasTypeBraille = "braille" - canvasTypeAuto = "auto" + canvasTypeFull = "full" + canvasTypeFullEscape = "full-escape" + canvasTypeFullEscapeBW = "full-bw" + canvasTypeFullEscapeWB = "full-wb" + canvasTypeQuarter = "quarter" + canvasTypeBraille = "braille" + canvasTypeAuto = "auto" ) const ( @@ -63,6 +65,8 @@ var config = configuration{ Choices: []string{ canvasTypeFull, canvasTypeFullEscape, + canvasTypeFullEscapeBW, + canvasTypeFullEscapeWB, canvasTypeQuarter, canvasTypeBraille, canvasTypeAuto, @@ -175,7 +179,7 @@ func main() { p = &draw.Quarter{Buffer: buffer} case canvasTypeFull: p = &draw.Full{Buffer: buffer} - case canvasTypeFullEscape: + case canvasTypeFullEscape, canvasTypeFullEscapeWB, canvasTypeFullEscapeBW: p = &draw.Full{Buffer: buffer} } p.Clear() @@ -193,8 +197,13 @@ func main() { case plotTypeHist2D: out = hist2D(x, y, c, config.HistBins) } - if config.CanvasType.Value == canvasTypeFullEscape { + switch config.CanvasType.Value { + case canvasTypeFullEscape: out = draw.FullEscape(out) + case canvasTypeFullEscapeBW: + out = draw.FullEscapeBW(out) + case canvasTypeFullEscapeWB: + out = draw.FullEscapeWB(out) } fmt.Println(out) } diff --git a/docs/hist2d_full_escape.png b/docs/hist2d_full_escape.png new file mode 100644 index 0000000..c383126 Binary files /dev/null and b/docs/hist2d_full_escape.png differ diff --git a/pkg/draw/full_escape.go b/pkg/draw/full_escape.go index e6a68de..ab0af25 100644 --- a/pkg/draw/full_escape.go +++ b/pkg/draw/full_escape.go @@ -2,8 +2,45 @@ package draw import "strings" -const invertedSpace = "\033[7m \033[27m" +var invertEscape = replacer(map[rune]string{ + '█': "\033[7m \033[27m", +}) + +var colorEscapeBW = replacer(map[rune]string{ + '█': "\033[48;5;231m \033[49m", + '▓': "\033[48;5;252m \033[49m", + '▒': "\033[48;5;248m \033[49m", + '░': "\033[48;5;240m \033[49m", + '·': "\033[48;5;236m \033[49m", + ' ': "\033[48;5;232m ", +}) + +var colorEscapeWB = replacer(map[rune]string{ + '█': "\033[48;5;232m \033[49m", + '▓': "\033[48;5;236m \033[49m", + '▒': "\033[48;5;240m \033[49m", + '░': "\033[48;5;248m \033[49m", + '·': "\033[48;5;252m \033[49m", + ' ': "\033[48;5;231m ", +}) + +func replacer(m map[rune]string) *strings.Replacer { + r := make([]string, 0, len(m)*2) + for old, new := range m { + r = append(r, string(old)) + r = append(r, new) + } + return strings.NewReplacer(r...) +} func FullEscape(full string) string { - return strings.Replace(full, string(fullBlock), invertedSpace, -1) + return invertEscape.Replace(full) +} + +func FullEscapeBW(full string) string { + return colorEscapeBW.Replace(full) +} + +func FullEscapeWB(full string) string { + return colorEscapeWB.Replace(full) } -- cgit v1.2.3