Skip to content

Commit 2cd998b

Browse files
committed
Initial commit.
0 parents  commit 2cd998b

File tree

10 files changed

+601
-0
lines changed

10 files changed

+601
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
debug

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Console Pxls viewer
2+
3+
View a Pxls canvas on the command-line!
4+
5+
## Known bugs
6+
7+
- Windows has fewer, wronger colors
8+
- this is due to the library that's used ([termbox-go](https://github.com/nsf/termbox-go/)) not supporting xterm 256 colors at the time of this writing.
9+
- Mingw on Windows not rendering anything
10+
- no idea why this happens
11+
- Moving horizontally goes twice as fast than moving vertically
12+
13+
## Controls
14+
15+
* Drag your mouse to scroll through the canvas.
16+
* Use the arrow keys to move faster.
17+
* Ctrl+C exists.
18+
19+
## Arguments
20+
21+
`--host`: the hostname of the pxls server. Default is "pxls.space"
22+
23+
`--secure`: whether the connection should be secure (use https: and wss: protocols) or insecure (use http: and ws: protocols). Default is true.
24+
25+
---
26+
27+
## Screenshots
28+
29+
Powershell in Windows:
30+
![Windows, Powershell](images/windows-powershell.gif)
31+
32+
Ubuntu with Xterm color palette (full of visual glitches, but pretty colors)
33+
![Ubuntu, Terminal (Xterm color palette)](images/ubuntu-xterm.gif)

color_unix.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// +build !windows linux,darwin
2+
3+
package main
4+
5+
import (
6+
"github.com/lucasb-eyer/go-colorful"
7+
"github.com/nsf/termbox-go"
8+
)
9+
10+
const termboxXtermOffset = 0x11
11+
12+
// modification of https://github.com/ichinaski/pxl/blob/master/color.go.
13+
14+
// reduceRGB reduces color values to the range [0, 15].
15+
func reduceRGB(color colorful.Color) (uint16, uint16, uint16) {
16+
r, g, b, _ := color.RGBA()
17+
18+
return uint16(r >> 8), uint16(g >> 8), uint16(b >> 8)
19+
}
20+
21+
// termColor converts a 24-bit RGB color into a term256 compatible approximation.
22+
func colorToTermboxAttr(color colorful.Color) termbox.Attribute {
23+
r, g, b := reduceRGB(color)
24+
25+
var (
26+
termR = (((r * 5) + 127) / 255) * 36
27+
termG = (((g * 5) + 127) / 255) * 6
28+
termB = (((b * 5) + 127) / 255)
29+
)
30+
31+
return termbox.Attribute(termR + termG + termB + termboxXtermOffset)
32+
}

color_windows.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// +build windows
2+
3+
package main
4+
5+
import (
6+
"github.com/lucasb-eyer/go-colorful"
7+
"github.com/nsf/termbox-go"
8+
)
9+
10+
// TODO(netux): wait for Termbox to add support for Output256 on Windows.
11+
var termboxPalette = map[colorful.Color]termbox.Attribute{
12+
colorful.Color{R: 0, G: 0, B: 0}: termbox.ColorBlack,
13+
colorful.Color{R: 1, G: 0, B: 0}: termbox.ColorRed,
14+
colorful.Color{R: 0, G: 1, B: 0}: termbox.ColorGreen,
15+
colorful.Color{R: 0, G: 1, B: 0}: termbox.ColorBlue,
16+
colorful.Color{R: 1, G: 1, B: 0}: termbox.ColorYellow,
17+
colorful.Color{R: 1, G: 0, B: 1}: termbox.ColorMagenta,
18+
colorful.Color{R: 0, G: 1, B: 1}: termbox.ColorCyan,
19+
colorful.Color{R: 1, G: 1, B: 1}: termbox.ColorWhite,
20+
}
21+
22+
func colorToTermboxAttr(color colorful.Color) termbox.Attribute {
23+
var closest colorful.Color
24+
var by float64 = 2
25+
for c := range termboxPalette {
26+
d := color.DistanceLab(c)
27+
28+
if d < by {
29+
closest = c
30+
by = d
31+
}
32+
}
33+
34+
return termboxPalette[closest]
35+
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module go-dev.netux.site/shell/pxls-viewer
2+
3+
require (
4+
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08
5+
github.com/mattn/go-runewidth v0.0.4 // indirect
6+
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
7+
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3
8+
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08 h1:5MnxBC15uMxFv5FY/J/8vzyaBiArCOkMdFT9Jsw78iY=
2+
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
3+
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
4+
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
5+
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840=
6+
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
7+
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY=
8+
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

images/ubuntu-xterm.gif

3.01 MB
Loading

images/windows-powershell.gif

3.11 MB
Loading

0 commit comments

Comments
 (0)