mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-12-22 23:17:29 +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] {
|
||||
case '0':
|
||||
case Input:
|
||||
if !app.options.PermitWrite {
|
||||
break
|
||||
}
|
||||
@ -168,51 +168,31 @@ func (app *App) generateHandler() func(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
case '1':
|
||||
var remoteCmd command
|
||||
err = json.Unmarshal(data[1:], &remoteCmd)
|
||||
case ResizeTerminal:
|
||||
var args argResizeTerminal
|
||||
err = json.Unmarshal(data[1:], &args)
|
||||
if err != nil {
|
||||
log.Print("Malformed remote command")
|
||||
return
|
||||
}
|
||||
|
||||
switch remoteCmd.Name {
|
||||
case "resize_terminal":
|
||||
|
||||
rows := remoteCmd.Arguments["rows"]
|
||||
switch rows.(type) {
|
||||
case float64:
|
||||
default:
|
||||
log.Print("Malformed remote command")
|
||||
return
|
||||
}
|
||||
|
||||
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)),
|
||||
)
|
||||
window := struct {
|
||||
row uint16
|
||||
col uint16
|
||||
x uint16
|
||||
y uint16
|
||||
}{
|
||||
uint16(args.Rows),
|
||||
uint16(args.Columns),
|
||||
0,
|
||||
0,
|
||||
}
|
||||
syscall.Syscall(
|
||||
syscall.SYS_IOCTL,
|
||||
fio.Fd(),
|
||||
syscall.TIOCSWINSZ,
|
||||
uintptr(unsafe.Pointer(&window)),
|
||||
)
|
||||
|
||||
default:
|
||||
log.Print("Unknown message type")
|
||||
@ -230,9 +210,14 @@ func (app *App) generateHandler() func(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
type command struct {
|
||||
Name string `json:"name"`
|
||||
Arguments map[string]interface{} `json:"arguments"`
|
||||
const (
|
||||
Input = '0'
|
||||
ResizeTerminal = '1'
|
||||
)
|
||||
|
||||
type argResizeTerminal struct {
|
||||
Columns float64
|
||||
Rows float64
|
||||
}
|
||||
|
||||
func generateRandomString(length int) string {
|
||||
|
File diff suppressed because one or more lines are too long
@ -24,11 +24,8 @@
|
||||
ws.send(
|
||||
"1" + JSON.stringify(
|
||||
{
|
||||
name: "resize_terminal",
|
||||
arguments: {
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
},
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user