mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-22 12:24:25 +00:00
Simplify structure of command messages
The first byte of a input message shows the type of that message. 0: normal keystrokes 1: resize window command
This commit is contained in:
parent
ce96943af2
commit
5eea5067db
71
app/app.go
71
app/app.go
@ -158,7 +158,7 @@ func (app *App) generateHandler() func(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch data[0] {
|
switch data[0] {
|
||||||
case '0':
|
case Input:
|
||||||
if !app.options.PermitWrite {
|
if !app.options.PermitWrite {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -168,51 +168,31 @@ func (app *App) generateHandler() func(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
case '1':
|
case ResizeTerminal:
|
||||||
var remoteCmd command
|
var args argResizeTerminal
|
||||||
err = json.Unmarshal(data[1:], &remoteCmd)
|
err = json.Unmarshal(data[1:], &args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Malformed remote command")
|
log.Print("Malformed remote command")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch remoteCmd.Name {
|
window := struct {
|
||||||
case "resize_terminal":
|
row uint16
|
||||||
|
col uint16
|
||||||
rows := remoteCmd.Arguments["rows"]
|
x uint16
|
||||||
switch rows.(type) {
|
y uint16
|
||||||
case float64:
|
}{
|
||||||
default:
|
uint16(args.Rows),
|
||||||
log.Print("Malformed remote command")
|
uint16(args.Columns),
|
||||||
return
|
0,
|
||||||
}
|
0,
|
||||||
|
|
||||||
cols := remoteCmd.Arguments["columns"]
|
|
||||||
switch cols.(type) {
|
|
||||||
case float64:
|
|
||||||
default:
|
|
||||||
log.Print("Malformed remote command")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
window := struct {
|
|
||||||
row uint16
|
|
||||||
col uint16
|
|
||||||
x uint16
|
|
||||||
y uint16
|
|
||||||
}{
|
|
||||||
uint16(rows.(float64)),
|
|
||||||
uint16(cols.(float64)),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
}
|
|
||||||
syscall.Syscall(
|
|
||||||
syscall.SYS_IOCTL,
|
|
||||||
fio.Fd(),
|
|
||||||
syscall.TIOCSWINSZ,
|
|
||||||
uintptr(unsafe.Pointer(&window)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
syscall.Syscall(
|
||||||
|
syscall.SYS_IOCTL,
|
||||||
|
fio.Fd(),
|
||||||
|
syscall.TIOCSWINSZ,
|
||||||
|
uintptr(unsafe.Pointer(&window)),
|
||||||
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Print("Unknown message type")
|
log.Print("Unknown message type")
|
||||||
@ -230,9 +210,14 @@ func (app *App) generateHandler() func(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type command struct {
|
const (
|
||||||
Name string `json:"name"`
|
Input = '0'
|
||||||
Arguments map[string]interface{} `json:"arguments"`
|
ResizeTerminal = '1'
|
||||||
|
)
|
||||||
|
|
||||||
|
type argResizeTerminal struct {
|
||||||
|
Columns float64
|
||||||
|
Rows float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomString(length int) string {
|
func generateRandomString(length int) string {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -24,11 +24,8 @@
|
|||||||
ws.send(
|
ws.send(
|
||||||
"1" + JSON.stringify(
|
"1" + JSON.stringify(
|
||||||
{
|
{
|
||||||
name: "resize_terminal",
|
columns: columns,
|
||||||
arguments: {
|
rows: rows,
|
||||||
columns: columns,
|
|
||||||
rows: rows,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user