Compare commits
2 Commits
0b059c9a72
...
7732381a33
Author | SHA1 | Date |
---|---|---|
sloum | 7732381a33 | |
sloum | 8a22a34853 |
5
main.go
5
main.go
|
@ -25,6 +25,7 @@ const (
|
|||
var wb workbook
|
||||
var reAddr *regexp.Regexp = regexp.MustCompile(`^\$?[A-Z]\$?[0-9]+$`)
|
||||
var reAddrRange *regexp.Regexp = regexp.MustCompile(`^\$?[A-Z]\$?[0-9]+:\$?[A-Z]\$?[0-9]+\+$`)
|
||||
var reURL *regexp.Regexp = regexp.MustCompile(`^.*://.*$`)
|
||||
var modified bool = false
|
||||
|
||||
type point struct {
|
||||
|
@ -178,6 +179,10 @@ func IsRange(addr string) bool {
|
|||
return reAddrRange.MatchString(addr)
|
||||
}
|
||||
|
||||
func IsURL(u string) bool {
|
||||
return reURL.MatchString(u)
|
||||
}
|
||||
|
||||
func IsFunc(val string) bool {
|
||||
switch strings.ToUpper(val) {
|
||||
case "+", "-", "/", "*", "MIN", "MAX",
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// This will build for osx without a build tag based on the filename
|
||||
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func OpenInBrowser(url string) (string, error) {
|
||||
err := exec.Command("open", url).Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "Opened in system default web browser", nil
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// +build !darwin,!windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// OpenInBrowser checks for the presence of a display server
|
||||
// and environment variables indicating a gui is present. If found
|
||||
// then xdg-open is called on a url to open said url in the default
|
||||
// gui web browser for the system
|
||||
func OpenInBrowser(url string) (string, error) {
|
||||
disp := os.Getenv("DISPLAY")
|
||||
wayland := os.Getenv("WAYLAND_DISPLAY")
|
||||
_, err := exec.LookPath("Xorg")
|
||||
if disp == "" && wayland == "" && err != nil {
|
||||
return "", fmt.Errorf("No gui is available, check 'webmode' setting")
|
||||
}
|
||||
|
||||
// Use start rather than run or output in order
|
||||
// to release the process and not block
|
||||
err = exec.Command("xdg-open", url).Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "Opened in system default web browser", nil
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// This will only build for windows based on the filename
|
||||
// no build tag required
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func OpenInBrowser(url string) (string, error) {
|
||||
err := exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "Opened in system default web browser", nil
|
||||
}
|
|
@ -34,6 +34,7 @@ const (
|
|||
ModFaint rune = 'f'
|
||||
ModItalic rune = 'i'
|
||||
ModUnderline rune = 'u'
|
||||
OpenLink rune = 'O'
|
||||
)
|
||||
|
||||
type workbook struct {
|
||||
|
@ -133,6 +134,11 @@ func (w *workbook) Run() {
|
|||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Italic)
|
||||
case ModUnderline:
|
||||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Underline)
|
||||
case OpenLink:
|
||||
url := w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].mask
|
||||
if IsURL(url) {
|
||||
OpenInBrowser(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue