parent
c55c4bf254
commit
b790c53838
14
app.go
14
app.go
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -55,20 +54,9 @@ func waitKey() error {
|
|||||||
// This is the main event loop of the application. There are two channels to
|
// This is the main event loop of the application. There are two channels to
|
||||||
// read expressions from client and server. Reading and evaluation are done on
|
// read expressions from client and server. Reading and evaluation are done on
|
||||||
// separate goroutines.
|
// separate goroutines.
|
||||||
func (app *app) handleInp() {
|
func (app *app) handleInp(serverChan <-chan expr) {
|
||||||
clientChan := app.ui.readExpr()
|
clientChan := app.ui.readExpr()
|
||||||
|
|
||||||
var serverChan <-chan expr
|
|
||||||
|
|
||||||
c, err := net.Dial("unix", gSocketPath)
|
|
||||||
if err != nil {
|
|
||||||
msg := fmt.Sprintf("connecting server: %s", err)
|
|
||||||
app.ui.message = msg
|
|
||||||
log.Printf(msg)
|
|
||||||
} else {
|
|
||||||
serverChan = readExpr(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.quit:
|
case <-app.quit:
|
||||||
|
13
client.go
13
client.go
@ -31,6 +31,17 @@ func client() {
|
|||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
|
|
||||||
|
var serverChan <-chan expr
|
||||||
|
|
||||||
|
c, err := net.Dial("unix", gSocketPath)
|
||||||
|
if err != nil {
|
||||||
|
msg := fmt.Sprintf("connecting server: %s", err)
|
||||||
|
app.ui.message = msg
|
||||||
|
log.Printf(msg)
|
||||||
|
} else {
|
||||||
|
serverChan = readExpr(c)
|
||||||
|
}
|
||||||
|
|
||||||
if err := app.nav.sync(); err != nil {
|
if err := app.nav.sync(); err != nil {
|
||||||
msg := fmt.Sprintf("sync: %s", err)
|
msg := fmt.Sprintf("sync: %s", err)
|
||||||
app.ui.message = msg
|
app.ui.message = msg
|
||||||
@ -61,7 +72,7 @@ func client() {
|
|||||||
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
|
||||||
app.handleInp()
|
app.handleInp(serverChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readExpr(c net.Conn) <-chan expr {
|
func readExpr(c net.Conn) <-chan expr {
|
||||||
|
Loading…
Reference in New Issue
Block a user