summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Grebenshchikov <sgreben@gmail.com>2018-03-31 19:03:23 +0200
committerSergey Grebenshchikov <sgreben@gmail.com>2018-03-31 19:03:23 +0200
commitc172ba91228a8d4f5275f3e5a24e3462b906b2bc (patch)
treea6641b471c0a77b8c979522a6f1aa6214a5590fc
parent0aca02dc1e7ee25371e0d9f1d3d447973bd21b8b (diff)
Add full-escape canvas type1.1.10
-rw-r--r--Makefile2
-rw-r--r--README.md14
-rw-r--r--README.template.md2
-rw-r--r--cmd/jp/main.go27
-rw-r--r--pkg/draw/full.go4
-rw-r--r--pkg/draw/full_escape.go9
6 files changed, 39 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index e32eb2e..afc6fc5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = 1.1.9
+VERSION = 1.1.10
APP := jp
PACKAGES := $(shell go list -f {{.Dir}} ./...)
diff --git a/README.md b/README.md
index b816c76..ca2959a 100644
--- a/README.md
+++ b/README.md
@@ -39,16 +39,16 @@ Or [download the binary](https://github.com/sgreben/jp/releases/latest) from the
```bash
# Linux
-curl -LO https://github.com/sgreben/jp/releases/download/1.1.9/jp_1.1.9_linux_x86_64.zip
-unzip jp_1.1.9_linux_x86_64.zip
+curl -LO https://github.com/sgreben/jp/releases/download/1.1.10/jp_1.1.10_linux_x86_64.zip
+unzip jp_1.1.10_linux_x86_64.zip
# OS X
-curl -LO https://github.com/sgreben/jp/releases/download/1.1.9/jp_1.1.9_osx_x86_64.zip
-unzip jp_1.1.9_osx_x86_64.zip
+curl -LO https://github.com/sgreben/jp/releases/download/1.1.10/jp_1.1.10_osx_x86_64.zip
+unzip jp_1.1.10_osx_x86_64.zip
# Windows
-curl -LO https://github.com/sgreben/jp/releases/download/1.1.9/jp_1.1.9_windows_x86_64.zip
-unzip jp_1.1.9_windows_x86_64.zip
+curl -LO https://github.com/sgreben/jp/releases/download/1.1.10/jp_1.1.10_windows_x86_64.zip
+unzip jp_1.1.10_windows_x86_64.zip
```
## Use it
@@ -74,7 +74,7 @@ Usage of jp:
-width int
Plot width (default 0 (auto))
-canvas value
- Canvas type. One of [full quarter braille auto] (default auto)
+ Canvas type. One of [full full-escape quarter braille auto] (default auto)
```
## Examples
diff --git a/README.template.md b/README.template.md
index 5496c52..1d3552b 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 quarter braille auto] (default auto)
+ Canvas type. One of [full full-escape quarter braille auto] (default auto)
```
## Examples
diff --git a/cmd/jp/main.go b/cmd/jp/main.go
index 6cc9898..6769e1c 100644
--- a/cmd/jp/main.go
+++ b/cmd/jp/main.go
@@ -35,10 +35,11 @@ const (
)
const (
- canvasTypeFull = "full"
- canvasTypeQuarter = "quarter"
- canvasTypeBraille = "braille"
- canvasTypeAuto = "auto"
+ canvasTypeFull = "full"
+ canvasTypeFullEscape = "full-escape"
+ canvasTypeQuarter = "quarter"
+ canvasTypeBraille = "braille"
+ canvasTypeAuto = "auto"
)
const (
@@ -61,6 +62,7 @@ var config = configuration{
Value: canvasTypeAuto,
Choices: []string{
canvasTypeFull,
+ canvasTypeFullEscape,
canvasTypeQuarter,
canvasTypeBraille,
canvasTypeAuto,
@@ -173,19 +175,26 @@ func main() {
p = &draw.Quarter{Buffer: buffer}
case canvasTypeFull:
p = &draw.Full{Buffer: buffer}
+ case canvasTypeFullEscape:
+ p = &draw.Full{Buffer: buffer}
}
p.Clear()
c := draw.Canvas{Pixels: p}
+ var out string
switch config.PlotType.Value {
case plotTypeLine:
- fmt.Println(linePlot(x, y, c))
+ out = linePlot(x, y, c)
case plotTypeScatter:
- fmt.Println(scatterPlot(x, y, c))
+ out = scatterPlot(x, y, c)
case plotTypeBar:
- fmt.Println(barPlot(x, y, c))
+ out = barPlot(x, y, c)
case plotTypeHist:
- fmt.Println(histogram(x, c, config.HistBins))
+ out = histogram(x, c, config.HistBins)
case plotTypeHist2D:
- fmt.Println(hist2D(x, y, c, config.HistBins))
+ out = hist2D(x, y, c, config.HistBins)
+ }
+ if config.CanvasType.Value == canvasTypeFullEscape {
+ out = draw.FullEscape(out)
}
+ fmt.Println(out)
}
diff --git a/pkg/draw/full.go b/pkg/draw/full.go
index 6f234b0..dccdd9f 100644
--- a/pkg/draw/full.go
+++ b/pkg/draw/full.go
@@ -2,10 +2,12 @@ package draw
var _ Pixels = &Full{}
+const fullBlock = '█'
+
type Full struct{ *Buffer }
func (b *Full) Size() Box { return b.Box }
-func (b *Full) Set(y, x int) { b.Buffer.Set(y, x, '█') }
+func (b *Full) Set(y, x int) { b.Buffer.Set(y, x, fullBlock) }
func (b *Full) Clear() { b.Fill(' ') }
diff --git a/pkg/draw/full_escape.go b/pkg/draw/full_escape.go
new file mode 100644
index 0000000..e6a68de
--- /dev/null
+++ b/pkg/draw/full_escape.go
@@ -0,0 +1,9 @@
+package draw
+
+import "strings"
+
+const invertedSpace = "\033[7m \033[27m"
+
+func FullEscape(full string) string {
+ return strings.Replace(full, string(fullBlock), invertedSpace, -1)
+}