Skip to content

Commit 978d506

Browse files
authored
Merge pull request #44 from liamg/sixel-mk2
Sixel support
2 parents 0cc73f1 + 78d6730 commit 978d506

File tree

13 files changed

+431
-29
lines changed

13 files changed

+431
-29
lines changed

README.md

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ The project is experimental at the moment, so you probably won't want to rely on
1010

1111
Ensure you have your latest graphics card drivers installed before use.
1212

13+
Sixels are now supported.
14+
15+
![Example sixel](sixel.png)
16+
17+
1318
## Aims
1419

15-
- Full unicode support
20+
- Unicode support
1621
- OpenGL rendering
1722
- Full customisation options
1823
- True colour support
@@ -23,6 +28,7 @@ Ensure you have your latest graphics card drivers installed before use.
2328
- Resize logic that wraps/unwraps lines _correctly_
2429
- Bullshit graphical effects
2530
- Multi platform support
31+
- Sixel support
2632

2733
## What isn't supported?
2834

@@ -32,13 +38,6 @@ Ensure you have your latest graphics card drivers installed before use.
3238
<img alt="Overheating" src="https://imgs.xkcd.com/comics/workflow.png"/>
3339
</p>
3440

35-
## Build Dependencies
36-
37-
- Go 1.10.3+
38-
- On macOS, you need Xcode or Command Line Tools for Xcode (`xcode-select --install`) for required headers and libraries.
39-
- On Ubuntu/Debian-like Linux distributions, you need `libgl1-mesa-dev xorg-dev`.
40-
- On CentOS/Fedora-like Linux distributions, you need `libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel`.
41-
4241
## Platform Support
4342

4443
| Platform | Supported |
@@ -47,25 +46,12 @@ Ensure you have your latest graphics card drivers installed before use.
4746
| MacOSX ||
4847
| Windows ||
4948

50-
## Planned Features
51-
52-
| Feature | Done | Notes |
53-
|-----------------------------|------|-------|
54-
| Pty allocation ||
55-
| OpenGL rendering ||
56-
| 8-bit (256) colour ||
57-
| 24-bit (true) colour ||
58-
| Resizing/content reordering ||
59-
| ANSI escape codes ||
60-
| UTF-8 input ||
61-
| UTF-8 output ||
62-
| Copy/paste ||
63-
| Customisable colour schemes ||
64-
| Config file ||
65-
| Scrolling ||
66-
| Mouse interaction ||
67-
| Clickable URLs ||
68-
| Sweet render effects | |
49+
## Build Dependencies
50+
51+
- Go 1.10.3+
52+
- On macOS, you need Xcode or Command Line Tools for Xcode (`xcode-select --install`) for required headers and libraries.
53+
- On Ubuntu/Debian-like Linux distributions, you need `libgl1-mesa-dev xorg-dev`.
54+
- On CentOS/Fedora-like Linux distributions, you need `libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel`.
6955

7056
## Keyboard Shortcuts
7157

buffer/cell.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package buffer
22

3+
import (
4+
"image"
5+
6+
"github.com/go-gl/gl/all-core/gl"
7+
)
8+
39
type Cell struct {
4-
r rune
5-
attr CellAttributes
10+
r rune
11+
attr CellAttributes
12+
image *image.RGBA
613
}
714

815
type CellAttributes struct {
@@ -16,6 +23,64 @@ type CellAttributes struct {
1623
Hidden bool
1724
}
1825

26+
func (cell *Cell) Image() *image.RGBA {
27+
return cell.image
28+
}
29+
30+
func (cell *Cell) SetImage(img *image.RGBA) {
31+
32+
cell.image = img
33+
34+
}
35+
36+
func (cell *Cell) DrawImage(x, y float32) {
37+
38+
if cell.image == nil {
39+
return
40+
}
41+
42+
var tex uint32
43+
gl.Enable(gl.TEXTURE_2D)
44+
gl.GenTextures(1, &tex)
45+
gl.BindTexture(gl.TEXTURE_2D, tex)
46+
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
47+
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
48+
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
49+
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
50+
51+
gl.TexImage2D(
52+
gl.TEXTURE_2D,
53+
0,
54+
gl.RGBA,
55+
int32(cell.image.Bounds().Size().X),
56+
int32(cell.image.Bounds().Size().Y),
57+
0,
58+
gl.RGBA,
59+
gl.UNSIGNED_BYTE,
60+
gl.Ptr(cell.image.Pix),
61+
)
62+
gl.BindTexture(gl.TEXTURE_2D, 0)
63+
gl.Disable(gl.TEXTURE_2D)
64+
65+
gl.Disable(gl.BLEND)
66+
67+
var w float32 = float32(cell.image.Bounds().Size().X)
68+
var h float32 = float32(cell.image.Bounds().Size().Y)
69+
70+
var readFboId uint32
71+
gl.GenFramebuffers(1, &readFboId)
72+
gl.BindFramebuffer(gl.READ_FRAMEBUFFER, readFboId)
73+
74+
gl.FramebufferTexture2D(gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
75+
gl.TEXTURE_2D, tex, 0)
76+
gl.BlitFramebuffer(0, 0, int32(w), int32(h),
77+
int32(x), int32(y), int32(x+w), int32(y+h),
78+
gl.COLOR_BUFFER_BIT, gl.LINEAR)
79+
gl.BindFramebuffer(gl.READ_FRAMEBUFFER, 0)
80+
gl.DeleteFramebuffers(1, &readFboId)
81+
82+
}
83+
1984
func (cell *Cell) Attr() CellAttributes {
2085
return cell.attr
2186
}

example.sixel

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

gui/gui.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
8181
gui.logger.Debugf("Setting viewport size...")
8282
gl.Viewport(0, 0, int32(gui.width), int32(gui.height))
8383

84+
gui.terminal.SetCharSize(gui.renderer.cellWidth, gui.renderer.cellHeight)
85+
8486
gui.logger.Debugf("Resize complete!")
8587

8688
}
@@ -191,6 +193,8 @@ func (gui *GUI) Render() error {
191193
}
192194
}()
193195

196+
gui.terminal.SetProgram(program)
197+
194198
for !gui.window.ShouldClose() {
195199

196200
select {
@@ -242,10 +246,20 @@ func (gui *GUI) Render() error {
242246
if hasText {
243247
gui.renderer.DrawCellText(cell, uint(x), uint(y), nil)
244248
}
249+
250+
if cell.Image() != nil {
251+
ix := float32(x) * gui.renderer.cellWidth
252+
iy := float32(gui.height) - (float32(y+1) * gui.renderer.cellHeight)
253+
iy -= float32(cell.Image().Bounds().Size().Y)
254+
gl.UseProgram(program)
255+
cell.DrawImage(ix, iy)
256+
}
257+
245258
}
246259
}
247260

248261
gui.window.SwapBuffers()
262+
249263
}
250264

251265
}

gui/renderer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func (r *OpenGLRenderer) DrawCellBg(cell buffer.Cell, col uint, row uint, cursor
214214
rect.setColour(bg)
215215
rect.Draw()
216216
}
217+
217218
}
218219

219220
func (r *OpenGLRenderer) DrawCellText(cell buffer.Cell, col uint, row uint, colour *config.Colour) {

sixel.png

45.9 KB
Loading

sixel/img.bmp

614 Bytes
Binary file not shown.

sixel/img.jpg

Loading

0 commit comments

Comments
 (0)