Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/swap to tcell/v2 #73

Merged
merged 29 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cb1cfb0
Add frame customization
dankox Oct 28, 2020
bf52b10
first try to swap termbox to tcell
dankox Nov 2, 2020
ace8fe6
copy of termbox compat from tcell with some changes
dankox Nov 4, 2020
83d33e6
add debug configuration
dankox Nov 4, 2020
a4fe1ef
return back CtrlC (it works now)
dankox Nov 4, 2020
5f6ae5b
fix CtrlSpace and Spacebar keys
dankox Nov 4, 2020
db74815
fix widget example (coloring)
dankox Nov 4, 2020
462a239
True colors implementation with example
dankox Nov 5, 2020
8e73c55
fix colors for lower output modes
dankox Nov 5, 2020
a78cd5e
Fix colorstrue example terminal settings
dankox Nov 7, 2020
7a7f847
Add mouse event support
dankox Nov 7, 2020
a81de49
Change to tcell v2
dankox Nov 7, 2020
765f780
Change tcell calls to private
dankox Nov 8, 2020
0414b07
minor correction in mouse example
dankox Nov 8, 2020
eaa6f5a
Change colors to mimic tcell/v2 colors
dankox Nov 8, 2020
4377f3d
remove .vscode/launch.json and update gitignore
dankox Nov 8, 2020
7e477c7
update go.sum
dankox Nov 8, 2020
f84d3fd
Update mouse example and add comment to SetKeybinding about mouse keys
dankox Nov 8, 2020
ea044eb
Update readme and hello example
mjarkk Nov 8, 2020
ae9b323
Add new feature to readme
mjarkk Nov 8, 2020
e19a29b
Move attributes and keys to respective files
dankox Nov 8, 2020
99abdfd
Fix some keybindings
dankox Nov 8, 2020
da67745
refactoring tcell functions part 1
dankox Nov 9, 2020
5c8be1d
Add strikethrough attribute
dankox Nov 9, 2020
5921dae
fix KeySpace
dankox Nov 9, 2020
8b345d0
refactoring tcell functions finished
dankox Nov 10, 2020
e283cd1
fix g.Rune() function
dankox Nov 10, 2020
ab1c231
Add CHANGES documentation
dankox Nov 10, 2020
d20d452
Remove all gocui. prefixes in changes_tcell
mjarkk Nov 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
mjarkk marked this conversation as resolved.
Show resolved Hide resolved
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",
"configurations": [
{
// for remote run this command in terminal:
// dlv debug --headless --listen=:2345 --log --api-version 2
"name": "Connect to server",
"type": "go",
"request": "launch",
"mode": "remote",
"program": "${workspaceRoot}",
"remotePath": "${workspaceFolder}",
"port": 2345,
"host": "127.0.0.1"
},
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
// "program": "${workspaceFolder}/_examples/colors256.go",
"env": {},
"args": []
}
]
}
109 changes: 109 additions & 0 deletions _examples/colorstrue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"fmt"
"log"
"os"

"github.com/awesome-gocui/gocui"
colorful "github.com/lucasb-eyer/go-colorful"
)

var dark = false

func main() {
os.Setenv("COLORTERM", "truecolor")
g, err := gocui.NewGui(gocui.OutputTrue, true)

if err != nil {
log.Panicln(err)
}
defer g.Close()

g.SetManagerFunc(layout)

if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrlR, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
if dark {
dark = false
} else {
dark = true
}
displayHsv(v)

return nil
}); err != nil {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
rows := 33
cols := 182
if maxY < rows {
rows = maxY
}
if maxX < cols {
cols = maxX
}

if v, err := g.SetView("colors", 0, 0, cols-1, rows-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}

v.FrameColor = gocui.GetColor("#FFAA55")
displayHsv(v)

if _, err := g.SetCurrentView("colors"); err != nil {
return err
}
}
return nil
}

func displayHsv(v *gocui.View) {
v.Clear()
str := ""
// HSV color space (lines are value or saturation)
for i := 50; i > 0; i -= 2 {
// Hue
for j := 0; j < 360; j += 2 {
ir, ig, ib := hsv(j, i-1)
ir2, ig2, ib2 := hsv(j, i)
str += fmt.Sprintf("\x1b[48;2;%d;%d;%dm\x1b[38;2;%d;%d;%dm▀\x1b[0m", ir, ig, ib, ir2, ig2, ib2)
}
str += "\n"
fmt.Fprint(v, str)
str = ""
}

fmt.Fprintln(v, "\n\x1b[38;5;245mCtrl + R - Switch light/dark mode")
fmt.Fprintln(v, "\nCtrl + C - Exit\n")
fmt.Fprint(v, "Example should enable true color, but if it doesn't work run this command: \x1b[0mexport COLORTERM=truecolor")
}

func hsv(hue, sv int) (uint32, uint32, uint32) {
if !dark {
ir, ig, ib, _ := colorful.Hsv(float64(hue), float64(sv)/50, float64(1)).RGBA()
return ir >> 8, ig >> 8, ib >> 8
}
ir, ig, ib, _ := colorful.Hsv(float64(hue), float64(1), float64(sv)/50).RGBA()
return ir >> 8, ig >> 8, ib >> 8
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
141 changes: 141 additions & 0 deletions _examples/custom_frame.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package main

import (
"fmt"
"log"

"github.com/awesome-gocui/gocui"
)

var (
viewArr = []string{"v1", "v2", "v3", "v4"}
active = 0
)

func setCurrentViewOnTop(g *gocui.Gui, name string) (*gocui.View, error) {
if _, err := g.SetCurrentView(name); err != nil {
return nil, err
}
return g.SetViewOnTop(name)
}

func nextView(g *gocui.Gui, v *gocui.View) error {
nextIndex := (active + 1) % len(viewArr)
name := viewArr[nextIndex]

out, err := g.View("v1")
if err != nil {
return err
}
fmt.Fprintln(out, "Going from view "+v.Name()+" to "+name)

if _, err := setCurrentViewOnTop(g, name); err != nil {
return err
}

if nextIndex == 3 {
g.Cursor = true
} else {
g.Cursor = false
}

active = nextIndex
return nil
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("v1", 0, 0, maxX/2-1, maxY/2-1, gocui.RIGHT); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v1"
v.Autoscroll = true
fmt.Fprintln(v, "View with default frame color")
fmt.Fprintln(v, "It's connected to v2 with overlay RIGHT.\n")
if _, err = setCurrentViewOnTop(g, "v1"); err != nil {
return err
}
}

if v, err := g.SetView("v2", maxX/2-1, 0, maxX-1, maxY/2-1, gocui.LEFT); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v2"
v.Wrap = true
v.FrameColor = gocui.ColorMagenta
v.FrameRunes = []rune{'═', '│'}
fmt.Fprintln(v, "View with minimum frame customization and colored frame.")
fmt.Fprintln(v, "It's connected to v1 with overlay LEFT.\n")
fmt.Fprintln(v, "\033[35;1mInstructions:\033[0m")
fmt.Fprintln(v, "Press TAB to change current view")
fmt.Fprintln(v, "Press Ctrl+O to toggle gocui.SupportOverlap\n")
fmt.Fprintln(v, "\033[32;2mSelected frame is highlighted with green color\033[0m")
}
if v, err := g.SetView("v3", 0, maxY/2, maxX/2-1, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v3"
v.Wrap = true
v.Autoscroll = true
v.FrameColor = gocui.ColorCyan
v.TitleColor = gocui.ColorCyan
v.FrameRunes = []rune{'═', '║', '╔', '╗', '╚', '╝'}
fmt.Fprintln(v, "View with basic frame customization and colored frame and title")
fmt.Fprintln(v, "It's not connected to any view.")
}
if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1, gocui.LEFT); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v4"
v.Subtitle = "(editable)"
v.Editable = true
v.TitleColor = gocui.ColorYellow
v.FrameColor = gocui.ColorRed
v.FrameRunes = []rune{'═', '║', '╔', '╗', '╚', '╝', '╠', '╣', '╦', '╩', '╬'}
fmt.Fprintln(v, "View with fully customized frame and colored title differently.")
fmt.Fprintln(v, "It's connected to v3 with overlay LEFT.\n")
v.SetCursor(0, 3)
}
return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

func toggleOverlap(g *gocui.Gui, v *gocui.View) error {
g.SupportOverlaps = !g.SupportOverlaps
return nil
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
defer g.Close()

g.Highlight = true
g.SelFgColor = gocui.ColorGreen
g.SelFrameColor = gocui.ColorGreen

g.SetManagerFunc(layout)

if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlO, gocui.ModNone, toggleOverlap); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextView); err != nil {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}
1 change: 1 addition & 0 deletions _examples/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func main() {

g.Highlight = true
g.SelFgColor = gocui.ColorRed
g.SelFrameColor = gocui.ColorRed

g.SetManagerFunc(layout)

Expand Down
11 changes: 10 additions & 1 deletion _examples/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func keybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, delMsg); err != nil {
return err
}
// These keys are global, but they work only when you click them while hovering over View.
// ModAlt is actually `CTRL` key, not `ALT` key. Tcell generates it like that, not sure why.
if err := g.SetKeybinding("", gocui.MouseRight, gocui.ModAlt, delMsg); err != nil {
mjarkk marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if err := g.SetKeybinding("", gocui.MouseMiddle, gocui.ModNone, delMsg); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -104,7 +112,8 @@ func showMsg(g *gocui.Gui, v *gocui.View) error {

func delMsg(g *gocui.Gui, v *gocui.View) error {
if err := g.DeleteView("msg"); err != nil {
return err
// Error removed for testing purpose, because delete could be called multiple times with the above keybindings
// return err
}
dankox marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
2 changes: 1 addition & 1 deletion _examples/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func main() {
defer g.Close()

g.Highlight = true
g.SelFgColor = gocui.ColorRed
g.SelFrameColor = gocui.ColorRed

help := NewHelpWidget("help", 1, 1, helpText)
status := NewStatusbarWidget("status", 1, 7, 50)
Expand Down
32 changes: 0 additions & 32 deletions attribute.go

This file was deleted.

Loading