+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM fvwmorg/fvwm3-build:latest
#FROM docker.pkg.github.com/fvwmorg/fvwm3/fvwm3-build:latest

ENV GOROOT="/usr/lib/go-1.14/"
ENV PATH="$GOROOT/bin:$PATH"
ENV GO111MODULE="on"

COPY . /build
WORKDIR /build

RUN ./autogen.sh && ./configure && make
RUN ./autogen.sh && ./configure --enable-golang && make -j4
1 change: 1 addition & 0 deletions bin/FvwmPrompt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FvwmPrompt
162 changes: 162 additions & 0 deletions bin/FvwmPrompt/FvwmPrompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io"
"net"
"os"
"strings"
"time"

"github.com/abiosoft/ishell"
"github.com/fatih/color"
"github.com/sirupsen/logrus"
)

const (
fmdSocket = "/tmp/fvwm_mfl.sock"
)

// getopt parsing
type getOpts struct {
promptText *string
}

// FvwmPrompt only cares about a connection profile from Fvwm3 and nothing
// else. Eventually, there should probably be a lightweight API around the
// different JSON objects so that other programs can be written.
type connectionProfileData struct {
// Nested struct so that we represent the desired JSON:
//
// {
// "connection_profile": {
// version: ...,
// },
// }
ConnectionProfile struct {
Version string `json:"version"`
VersionInfo string `json:"version_info"`
} `json:"connection_profile"`
}

var (
cmdLineArgs getOpts
log = logrus.New()
isInteractive = false
)

func initCmdlineFlags(cmdline *getOpts) {
cmdline.promptText = flag.String("p", ">>> ", "The prompt")

flag.Parse()
}

func handleInput(c *ishell.Context, command string, wchan chan string) {
if command != "" {
wchan <- command
}
}

func writeToSocket(c net.Conn, wchan chan string) {
for {
select {
case fString := <-wchan:
c.Write([]byte(fString))
}
}
}

func readFromSocket(c net.Conn, rchan chan string) {
if c == nil {
return
}
defer c.Close()

for {
buf := make([]byte, 8912)
nr, err := c.Read(buf[:])
if err != nil || nr == 0 || err == io.EOF {
log.Printf("Error reading from UDS: %s\n", err)
os.Exit(0)
}

data := string(buf[0:nr])
if data == "" {
return
}

rchan <- data
}
}

func connectToFMD(shell *ishell.Shell, rchan chan string, wchan chan string) {
c, err := net.Dial("unix", fmdSocket)
if err != nil {
log.Fatal("Connection error ", err)
}

go writeToSocket(c, wchan)
go readFromSocket(c, rchan)

for {
select {
case fromFMD := <-rchan:
var cp connectionProfileData
err := json.Unmarshal([]byte(fromFMD), &cp)

if err == nil || isInteractive {
vstr := fmt.Sprintf("*FvwmPrompt %s (%s)\n", cp.ConnectionProfile.Version, cp.ConnectionProfile.VersionInfo)
shell.Println(vstr)

cyan := color.New(color.FgCyan).SprintFunc()
shell.Println(cyan("Press ^D or type 'exit' to end this session\n"))
}
}
}
}

func main() {
initCmdlineFlags(&cmdLineArgs)
writeToFMD := make(chan string)
readFromFMD := make(chan string)

shell := ishell.New()
shell.ShowPrompt(false)
shell.IgnoreCase(true)

shell.DeleteCmd("help")
shell.DeleteCmd("clear")

consoleHistory := os.Getenv("FVWM_USERDIR") + "/" + ".FvwmConsole-History"
shell.SetHistoryPath(consoleHistory)

shell.NotFound(func(c *ishell.Context) {
handleInput(c, strings.Join(c.Args, " "), writeToFMD)
})

// register a function for overriding Fvwm3's "Quit" command, to
// instead run a FvwmForm.
shell.AddCmd(&ishell.Cmd{
Name: "quit",
Help: "Quit Fvwm3",
Func: func(c *ishell.Context) {
handleInput(c, "Module FvwmScript FvwmScript-ConfirmQuit", writeToFMD)
},
})

isInteractive = len(os.Args) > 1 && os.Args[1] != "-p"

go connectToFMD(shell, readFromFMD, writeToFMD)

if isInteractive {
shell.Process(os.Args[1:]...)
} else {
red := color.New(color.FgRed).SprintFunc()
shell.Actions.SetPrompt(red(*cmdLineArgs.promptText))
time.Sleep(100 * time.Millisecond)
shell.ShowPrompt(true)
shell.Run()
}
}
24 changes: 24 additions & 0 deletions bin/FvwmPrompt/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if FVWM_BUILD_GOLANG
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
BINARY_NAME=FvwmPrompt

all: build
build:
$(GOBUILD) -o $(BINARY_NAME) -v
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)

install:
rm -f $(DESTDIR)$(bindir)/$(BINARY_NAME)
install $(BINARY_NAME) $(DESTDIR)$(bindir)

uninstall:
rm -f $(DESTDIR)$(bindir)/$(BINARY_NAME)
endif
16 changes: 16 additions & 0 deletions bin/FvwmPrompt/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/fvwmorg/FvwmPrompt

go 1.14

require (
github.com/abiosoft/ishell v2.0.0+incompatible
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db // indirect
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/fatih/color v1.9.0
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
)
42 changes: 42 additions & 0 deletions bin/FvwmPrompt/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg=
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8=
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions bin/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Process this file with automake to create Makefile.in

SUBDIRS = FvwmPrompt

bin_PROGRAMS = fvwm-root
fvwm_root_SOURCE= fvwm-root.c
fvwm_root_DEPENDENCIES = $(top_builddir)/libs/libfvwm3.a
Expand Down
39 changes: 39 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,43 @@ AC_PATH_PROG([PYTHON],[python3],[:])
AS_IF([test "$PYTHON" != ":"],
[AM_PYTHON_CHECK_VERSION([$PYTHON],[$REQUIRED_PYTHON_VERSION],[:],
[PYTHON=":"])])

# Golang
problem_golang=""
AC_ARG_ENABLE(golang,
AS_HELP_STRING([--enable-golang],[enable compilation of modules written in Go]),
[ if test x"$enableval" = xyes; then
with_golang="yes, check"
else
with_golang="no"
problem_golang=": Explicitly disabled"
fi ],
[ with_golang="no" ]
)

if test ! x"$with_golang" = xno; then
AC_CHECK_PROGS(GO, go)
if test -n "$GO" ; then
GOVERSIONOPTION=version
go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //')
AC_MSG_CHECKING([whether go version is >= 1.4.x])
case $go_version in
go1.[14]*)
AC_MSG_RESULT([yes - version is: $go_version])
with_golang="yes"
GO=
;;
*)
AC_MSG_RESULT([no - version is: $go_version])
with_golang="no"
problem_golang=": version of go ($go_version) <= 1.4.x"
;;
esac
fi
fi
AM_CONDITIONAL([FVWM_BUILD_GOLANG], [test x"$with_golang" = xyes])
AC_SUBST(GO)

#!!!
PERL=""
REQUIRED_PERL_VERSION=5.004
Expand Down Expand Up @@ -1588,6 +1625,7 @@ dnl bin/fvwm-perllib.1
modules/FvwmScript/FvwmScript.1
dnl
bin/Makefile
bin/FvwmPrompt/Makefile
bin/fvwm-config
bin/fvwm-perllib
bin/fvwm-menu-xlock
Expand Down Expand Up @@ -1699,6 +1737,7 @@ Fvwm3 Configuration:
With Xft anti-alias font support? $with_xft$problem_xft
With XPM image support? $with_xpm$problem_xpm
With Xrender image support? $with_xrender$problem_xrender
With Golang support? $with_golang$problem_golang
Build man pages? $with_mandoc$problem_mandoc
Build HTML documentation? $with_htmldoc$problem_htmldoc

Expand Down
8 changes: 7 additions & 1 deletion modules/FvwmConsole/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
## Process this file with automake to create Makefile.in

program_transform_name =

PERL = @PERL@
moduledir = @FVWM_MODULEDIR@

# If FVWM_BUILD_GOLANG has been defined via --enable-golang, then FvwmPrompt
# is preferred. In this case, disable compiling/installing FvwmConsole --
# eventually, FvwmConsole will go away completely, but for compatibility
# reasons, remains here only under this condition.
if !FVWM_BUILD_GOLANG

module_PROGRAMS = FvwmConsole FvwmConsoleC
module_SCRIPTS = FvwmConsoleC.pl

Expand All @@ -24,3 +29,4 @@ LDADD = -L$(top_builddir)/libs -lfvwm3 $(readline_LIBS) $(X_EXTRA_LIBS)
# Despite not using X functions explicitly, the code includes
# fvwmlib.h, which *does* include X headers and xpm.h!
AM_CPPFLAGS = -I$(top_srcdir) $(readline_CFLAGS) $(xpm_CFLAGS) $(X_CFLAGS)
endif !FVWM_BUILD_GOLANG
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载