Skip to content

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Oct 29, 2016

This PR adds the possibility to resize TTYs. It adds (optional) arguments to controls and modifies the UI<->App contract in the following way:

  • Control requests now take optional arguments (a JSON string map)
  • Pipe request add an additional key in the response: resize_tty_control which indicates what control to use in order to resize the TTY
  • That control takes three (mandatory) parameters: width, height and pipeID

Here's an example:

  1. The UI requests POST http://172.16.0.3:4040/api/control/3b89ec4023a94f3e/516cc48f99788d7d6b558d4ebf3d0e3bd1d3f2eae65ceb4e405a53498ed99b45%3B%3Ccontainer%3E/docker_exec_container to create a containter TTY
  2. The App responds with {"pipe":"pipe-4012265930510560261","raw_tty":true,"resize_tty_control":"docker_resize_exec_tty"}. Note the new resize_tty_control field.
  3. We can set the terminal size by doing curl -X POST -d '{ "pipeID": "pipe-4012265930510560261", "height": "100", "width": "100"}' http://172.16.0.3:4040/api/control/3b89ec4023a94f3e/516cc48f99788d7d6b558d4ebf3d0e3bd1d3f2eae65ceb4e405a53498ed99b45%3B%3Ccontainer%3E/docker_resize_exec_tty
  4. The tty gets adjusted accordingly by the App:

screen shot 2016-10-29 at 13 25 20

TODO:

  • Implement (3) in the UI (CC @foot )
  • Implement resizing for host TTYs in the backend

I would appreciate a design review (maybe by @tomwilkie )

Fixes #746.
Fixs #1964

@foot
Copy link
Contributor

foot commented Oct 31, 2016

Works great for containers!

Using the controls endpoint is a bit awkward right now: to construct the url /api/control/:control.probeId}/:control.nodeId/docker_resize_exec_tty we have to look up probeId and nodeId from some other control.

A pipe based endpoint feels like it would be cleaner: /api/pipes/:pipeId/resize.

If thats not feasible I guess either:

  • nodeDetails.resizeControl property
  • as suggested somewhere else include a docker_resize_exec_tty control in nodeDetails.controls w/ a hidden: true, a bit awkward.

@2opremio
Copy link
Contributor Author

2opremio commented Oct 31, 2016

Works great for containers!

Awesome! but shouldn't it be generic? (i.e. if the pipe response sets raw_tty and has a resize_tty_control field, set the initial size and every time the user resizes the window, regardless of what control it is (container, host and what not)

Using the controls endpoint is a bit awkward right now: to construct the url /api/control/:control.probeId}/:control.nodeId/docker_resize_exec_tty we have to look up probeId and nodeId from some other control.

Can't you save them with the pipeID and associate them to the terminal instance?

A pipe based endpoint feels like it would be cleaner: /api/pipes/:pipeId/resize

That makes it awkward for the backend. I gave it a lot of thought and this was the best option I could come up with, respecting what we already have for controls (we cannot use the pipes directly because we don't have a way to send out of band control information cleanly without breaking backwards compatibility in the pipes protocol).

We could use your proposed API and still use controls under the hood, but that would make it internally stateful (we would have to keep a map from pipeIDs to probeIDs and control)

@foot
Copy link
Contributor

foot commented Oct 31, 2016

Can't you save them with the pipeID and associate them to the terminal instance?

Yep, true, we can do that.

if the pipe response sets raw_tty and has a resize_tty_control field

Ah hah! This is probably why host is not working right now.

Will clean up and fix this.

Adds terminal resizing on popped out windows
@foot
Copy link
Contributor

foot commented Oct 31, 2016

Working on hosts and popped out windows too now.

Can the resize_tty_control be missing sometimes?

@2opremio
Copy link
Contributor Author

2opremio commented Oct 31, 2016

Can the resize_tty_control be missing sometimes?

It won't be missing in the response of docker_exec/host_exec controls but it's optional, so I would handle it as such.

@2opremio 2opremio changed the title [WIP] Resize TTYs Resize TTYs Oct 31, 2016
Copy link
Contributor

@jml jml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go code LGTM. One comment that you can act on at your discretion.

return ResponseErrorf("Bad parameter: width (%q): %v", widthS, err)
}

return next(pipeID, uint(height), uint(width))

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Contributor

@davkal davkal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, nicely done. Apart from naming issues, LGTM


log('Caculated (col, row) sizes in px: ', pixelPerCol, pixelPerRow);
return {pixelPerCol, pixelPerRow};
log('Caculated (charWidth, charHeight) sizes in px: ', characterWidth, characterHeight);

This comment was marked as abuse.

This comment was marked as abuse.

@@ -248,6 +252,22 @@ export function doControlRequest(nodeId, control, dispatch) {
});
}


export function doResizePipe(pipeId, control, cols, rows) {

This comment was marked as abuse.

res.pipe,
nodeId,
res.raw_tty,
{id: res.resize_tty_control, probeId: control.probeId, nodeId: control.nodeId}));

This comment was marked as abuse.

This comment was marked as abuse.

@@ -580,16 +580,17 @@ export function receiveControlNodeRemoved(nodeId) {
};
}

export function receiveControlPipeFromParams(pipeId, rawTty) {
export function receiveControlPipeFromParams(pipeId, rawTty, resizeTtyControl) {

This comment was marked as abuse.

@foot
Copy link
Contributor

foot commented Nov 3, 2016

So we don't receive a resize control from attach. Does it makes sense to have one there? @2opremio

…tach)

- Fix text selection in terminal (was our force focus stuff, introduced
  if you clicked on the black border that was not actually the terminal
@2opremio
Copy link
Contributor Author

2opremio commented Nov 3, 2016

So we don't receive a resize control from attach. Does it makes sense to have one there?

I don't think it does. Logs are not in raw mode, so it shouldn't matter (in general at least)

@2opremio
Copy link
Contributor Author

2opremio commented Nov 3, 2016

Docker provides https://godoc.org/github.com/fsouza/go-dockerclient#Client.ResizeContainerTTY so it should be easy to add, but I don't think it's even worth it. That could change if I am presented with a reasonable usecase.

@foot foot merged commit 7e5166e into master Nov 3, 2016
@foot foot deleted the 746-resize-ttys branch November 3, 2016 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants