(data []byte)
| 199 | } |
| 200 | |
| 201 | func (wt *WebTTY) handleMasterReadEvent(data []byte) error { |
| 202 | if len(data) == 0 { |
| 203 | return errors.New("unexpected zero length read from master") |
| 204 | } |
| 205 | |
| 206 | switch data[0] { |
| 207 | case Input: |
| 208 | if !wt.permitWrite { |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | if len(data) <= 1 { |
| 213 | return nil |
| 214 | } |
| 215 | _, err := wt.slave.Write(data[1:]) |
| 216 | if err != nil { |
| 217 | return errors.Wrapf(err, "failed to write received data to slave") |
| 218 | } |
| 219 | |
| 220 | case Ping: |
| 221 | err := wt.masterWrite([]byte{Pong}) |
| 222 | wt.lastPingTime = time.Now() |
| 223 | if err != nil { |
| 224 | return errors.Wrapf(err, "failed to return Pong message to master") |
| 225 | } |
| 226 | |
| 227 | case ResizeTerminal: |
| 228 | if wt.columns != 0 && wt.rows != 0 { |
| 229 | break |
| 230 | } |
| 231 | |
| 232 | if len(data) <= 1 { |
| 233 | return errors.New("received malformed remote command for terminal resize: empty payload") |
| 234 | } |
| 235 | |
| 236 | var args argResizeTerminal |
| 237 | err := json.Unmarshal(data[1:], &args) |
| 238 | if err != nil { |
| 239 | return errors.Wrapf(err, "received malformed data for terminal resize") |
| 240 | } |
| 241 | rows := wt.rows |
| 242 | if rows == 0 { |
| 243 | rows = int(args.Rows) |
| 244 | } |
| 245 | |
| 246 | columns := wt.columns |
| 247 | if columns == 0 { |
| 248 | columns = int(args.Columns) |
| 249 | } |
| 250 | |
| 251 | return wt.slave.ResizeTerminal(columns, rows) |
| 252 | default: |
| 253 | return errors.Errorf("unknown message type `%c`", data[0]) |
| 254 | } |
| 255 | |
| 256 | return nil |
| 257 | } |
| 258 |
no test coverage detected