Skip to content

Commit

Permalink
Add full-escape canvas type
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Mar 31, 2018
1 parent 0aca02d commit c172ba9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 1.1.9
VERSION = 1.1.10

APP := jp
PACKAGES := $(shell go list -f {{.Dir}} ./...)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions cmd/jp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -61,6 +62,7 @@ var config = configuration{
Value: canvasTypeAuto,
Choices: []string{
canvasTypeFull,
canvasTypeFullEscape,
canvasTypeQuarter,
canvasTypeBraille,
canvasTypeAuto,
Expand Down Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion pkg/draw/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ') }
9 changes: 9 additions & 0 deletions pkg/draw/full_escape.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c172ba9

Please sign in to comment.