#147 Hyperlinks, corrected set/unset

This commit is contained in:
Roman Shevchenko 2019-03-06 18:53:51 +03:00
parent 70b95a71ef
commit 52aedb077c
3 changed files with 33 additions and 16 deletions

View File

@ -12,18 +12,28 @@ func oscHandler(pty chan rune, terminal *Terminal) error {
params := []string{} params := []string{}
param := "" param := ""
for { {
b := <-pty isEscaped := false // flag if the previous character was escape
if terminal.IsOSCTerminator(b) {
params = append(params, param) for {
break b := <-pty
if terminal.IsOSCTerminator(b, isEscaped) {
params = append(params, param)
break
}
if isEscaped {
isEscaped = false
} else if b == 0x1b {
isEscaped = true
continue
}
if b == ';' {
params = append(params, param)
param = ""
continue
}
param = fmt.Sprintf("%s%c", param, b)
} }
if b == ';' {
params = append(params, param)
param = ""
continue
}
param = fmt.Sprintf("%s%c", param, b)
} }
if len(params) == 0 { if len(params) == 0 {
@ -42,8 +52,8 @@ func oscHandler(pty chan rune, terminal *Terminal) error {
case "0", "2": case "0", "2":
terminal.SetTitle(pT) terminal.SetTitle(pT)
case "8": // hyperlink case "8": // hyperlink
if len(pS) > 2 { if len(params) > 2 && len(params[2]) > 0 {
terminal.terminalState.CurrentHyperlink = &buffer.Hyperlink{Uri: pS[2]} terminal.terminalState.CurrentHyperlink = &buffer.Hyperlink{Uri: params[2]}
} else { } else {
terminal.terminalState.CurrentHyperlink = nil terminal.terminalState.CurrentHyperlink = nil
} }

View File

@ -11,14 +11,20 @@ import (
"github.com/liamg/aminal/sixel" "github.com/liamg/aminal/sixel"
) )
type boolFormRuneFunc func(rune) bool type boolFormRuneFunc func(rune, bool) bool
func swallowByFunction(pty chan rune, isTerminator boolFormRuneFunc) { func swallowByFunction(pty chan rune, isTerminator boolFormRuneFunc) {
isEscaped := false
for { for {
b := <-pty b := <-pty
if isTerminator(b) { if isTerminator(b, isEscaped) {
break break
} }
if isEscaped {
isEscaped = false
} else if b == 0x1b {
isEscaped = true
}
} }
} }

View File

@ -134,7 +134,8 @@ func (terminal *Terminal) GetMouseExtMode() MouseExtMode {
return terminal.mouseExtMode return terminal.mouseExtMode
} }
func (terminal *Terminal) IsOSCTerminator(char rune) bool { func (terminal *Terminal) IsOSCTerminator(char rune, isEscaped bool) bool {
// @todo handle isEscaped flag
_, ok := terminal.platformDependentSettings.OSCTerminators[char] _, ok := terminal.platformDependentSettings.OSCTerminators[char]
return ok return ok
} }