gdamore/tcell

Cannot select text from the terminal nor click links with style.Url(someUrl)

otaxhu opened this issue · 5 comments

otaxhu commented

I'm using windows 10, literally this is my code:

package main

import (
	"log"

	"github.com/gdamore/tcell/v2"
	"github.com/mattn/go-runewidth"
)

func main() {
	s, err := tcell.NewConsoleScreen()
	if err != nil {
		log.Fatal(err)
	}
	if err := s.Init(); err != nil {
		log.Fatal(err)
	}
	s.EnableMouse()
	renderUi := func() {
		s.Clear()
		w, h := s.Size()
		h = h - 2
		msg := "app started in this url "
		appUrl := "http://127.0.0.1:" + fmt.Sprint(cfg.Server.Port)
		x := (w - len(msg) - len(appUrl)) / 2
		y := h / 2
		x = emitStr(s, x, y, tcell.StyleDefault, msg)
		emitStr(s, x, y, tcell.StyleDefault.Underline(true).Url(appUrl), appUrl)
		exitMsg := "Press any key to exit the program..."
		emitStr(s, (w-len(exitMsg))/2, y+2, tcell.StyleDefault.Background(tcell.NewRGBColor(0, 0, 135)), exitMsg)
		s.Show()
	}
	renderUi()
PollEventLoop:
	for {
		switch s.PollEvent().(type) {
		case *tcell.EventResize:
			renderUi()
		case *tcell.EventKey:
			s.Fini()
			break PollEventLoop
		}
	}
}

func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) int {
	for _, c := range str {
		var comb []rune
		w := runewidth.RuneWidth(c)
		if w == 0 {
			comb = []rune{c}
			c = ' '
			w = 1
		}
		s.SetContent(x, y, c, comb, style)
		x += w
	}
	return x
}

Are you using Windows Terminal, or some other emulator?

Using cmd.exe.

So style.Url is dependent entirely on your terminal emulator. Only a few terminal emulators support it. CMD.exe is not one. Sorry, but there is nothing I can do about it.

Which terminals are supported?