{"action":"created","comment":{"url":"https://api.github.com/repos/weaveworks/scope/pulls/comments/46550966","id":46550966,"diff_hunk":"@@ -0,0 +1,180 @@\n+import debug from 'debug';\n+import React from 'react';\n+import ReactDOM from 'react-dom';\n+\n+import { clickCloseTerminal, clickTerminal } from '../actions/app-actions';\n+import { getNeutralColor, getNodeColorDark } from '../utils/color-utils';\n+import Term from '../vendor/term.js';\n+\n+const wsProto = location.protocol === 'https:' ? 'wss' : 'ws';\n+const wsUrl = __WS_URL__ || wsProto + '://' + location.host + location.pathname.replace(/\\/$/, '');\n+const log = debug('scope:terminal');\n+\n+const DEFAULT_COLS = 80;\n+const DEFAULT_ROWS = 24;\n+const MIN_COLS = 40;\n+const MIN_ROWS = 4;\n+\n+function ab2str(buf) {\n+  return String.fromCharCode.apply(null, new Uint8Array(buf));\n+}\n+\n+\n+function terminalCellSize(wrapperNode, rows, cols) {\n+  //\n+  // wrapperNode should be an unsized block. E.g. An element that 'clings' to\n+  // its inner terminal so we get a nice size reading of the inner terminal.\n+  //\n+  const width = wrapperNode.clientWidth;\n+  const height = wrapperNode.clientHeight;\n+  const pixelPerRow = height / rows;\n+  const pixelPerCol = width / cols;\n+  return {pixelPerCol, pixelPerRow};\n+}\n+\n+export default class Terminal extends React.Component {\n+  constructor(props, context) {\n+    super(props, context);\n+    this.state = {\n+      conected: false,\n+      rows: DEFAULT_ROWS,\n+      cols: DEFAULT_COLS,\n+      pixelPerCol: 0,\n+      pixelPerRow: 0\n+    };\n+    this.handleClick = this.handleClick.bind(this);\n+    this.handleCloseClick = this.handleCloseClick.bind(this);\n+    this.handleResize = this.handleResize.bind(this);\n+  }\n+\n+  componentDidMount() {\n+    let socket = new WebSocket(wsUrl + '/api/pipe/' + this.props.pipeId);\n+    socket.binaryType = 'arraybuffer';\n+    const component = this;\n+\n+    const term = new Term({\n+      cols: this.state.cols,\n+      rows: this.state.rows,\n+      screenKeys: true\n+    });\n+\n+    const innerNode = ReactDOM.findDOMNode(component.inner);\n+    term.open(innerNode);\n+\n+    term.on('data', function(data) {\n+      socket.send(data);\n+    });\n+\n+    socket.onopen = function() {\n+      log('socket open');\n+    };\n+\n+    socket.onclose = function() {\n+      log('socket closed');\n+      term.destroy();\n+      socket = null;\n+    };\n+\n+    socket.onerror = function(err) {\n+      log('socket error', err);\n+    };\n+\n+    socket.onmessage = function(event) {\n+      log('pipe data', event.data.size);\n+      const input = ab2str(event.data);\n+      term.write(input);\n+    };\n+\n+    this.term = term;\n+    this.socket = socket;\n+\n+    const {pixelPerCol, pixelPerRow} = terminalCellSize(\n+      innerNode, this.state.rows, this.state.cols);\n+\n+    window.addEventListener('resize', this.handleResize, this);","path":"client/app/scripts/components/terminal.js","position":94,"original_position":94,"commit_id":"090afffa24051563fa6b1ddcf941e609fb37adb4","original_commit_id":"090afffa24051563fa6b1ddcf941e609fb37adb4","user":{"login":"foot","id":22008,"avatar_url":"https://avatars.githubusercontent.com/u/22008?v=3","gravatar_id":"","url":"https://api.github.com/users/foot","html_url":"https://github.com/foot","followers_url":"https://api.github.com/users/foot/followers","following_url":"https://api.github.com/users/foot/following{/other_user}","gists_url":"https://api.github.com/users/foot/gists{/gist_id}","starred_url":"https://api.github.com/users/foot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foot/subscriptions","organizations_url":"https://api.github.com/users/foot/orgs","repos_url":"https://api.github.com/users/foot/repos","events_url":"https://api.github.com/users/foot/events{/privacy}","received_events_url":"https://api.github.com/users/foot/received_events","type":"User","site_admin":false},"body":"Yes! Good catch.","created_at":"2015-12-03T13:34:07Z","updated_at":"2015-12-03T13:34:07Z","html_url":"https://github.com/weaveworks/scope/pull/650#discussion_r46550966","pull_request_url":"https://api.github.com/repos/weaveworks/scope/pulls/650","_links":{"self":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/comments/46550966"},"html":{"href":"https://github.com/weaveworks/scope/pull/650#discussion_r46550966"},"pull_request":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/650"}}},"pull_request":{"url":"https://api.github.com/repos/weaveworks/scope/pulls/650","id":50417979,"html_url":"https://github.com/weaveworks/scope/pull/650","diff_url":"https://github.com/weaveworks/scope/pull/650.diff","patch_url":"https://github.com/weaveworks/scope/pull/650.patch","issue_url":"https://api.github.com/repos/weaveworks/scope/issues/650","number":650,"state":"open","locked":false,"title":"[WIP] Pipes","user":{"login":"tomwilkie","id":444037,"avatar_url":"https://avatars.githubusercontent.com/u/444037?v=3","gravatar_id":"","url":"https://api.github.com/users/tomwilkie","html_url":"https://github.com/tomwilkie","followers_url":"https://api.github.com/users/tomwilkie/followers","following_url":"https://api.github.com/users/tomwilkie/following{/other_user}","gists_url":"https://api.github.com/users/tomwilkie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwilkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwilkie/subscriptions","organizations_url":"https://api.github.com/users/tomwilkie/orgs","repos_url":"https://api.github.com/users/tomwilkie/repos","events_url":"https://api.github.com/users/tomwilkie/events{/privacy}","received_events_url":"https://api.github.com/users/tomwilkie/received_events","type":"User","site_admin":false},"body":"Fixes #365 ","created_at":"2015-11-11T18:29:01Z","updated_at":"2015-12-03T13:34:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"acdba9a5ff4a09c1cea51e417d30a62cf7cec589","assignee":{"login":"tomwilkie","id":444037,"avatar_url":"https://avatars.githubusercontent.com/u/444037?v=3","gravatar_id":"","url":"https://api.github.com/users/tomwilkie","html_url":"https://github.com/tomwilkie","followers_url":"https://api.github.com/users/tomwilkie/followers","following_url":"https://api.github.com/users/tomwilkie/following{/other_user}","gists_url":"https://api.github.com/users/tomwilkie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwilkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwilkie/subscriptions","organizations_url":"https://api.github.com/users/tomwilkie/orgs","repos_url":"https://api.github.com/users/tomwilkie/repos","events_url":"https://api.github.com/users/tomwilkie/events{/privacy}","received_events_url":"https://api.github.com/users/tomwilkie/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/weaveworks/scope/pulls/650/commits","review_comments_url":"https://api.github.com/repos/weaveworks/scope/pulls/650/comments","review_comment_url":"https://api.github.com/repos/weaveworks/scope/pulls/comments{/number}","comments_url":"https://api.github.com/repos/weaveworks/scope/issues/650/comments","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/090afffa24051563fa6b1ddcf941e609fb37adb4","head":{"label":"weaveworks:365-pipes","ref":"365-pipes","sha":"090afffa24051563fa6b1ddcf941e609fb37adb4","user":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"repo":{"id":34659664,"name":"scope","full_name":"weaveworks/scope","owner":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/weaveworks/scope","description":"Container visibility","fork":false,"url":"https://api.github.com/repos/weaveworks/scope","forks_url":"https://api.github.com/repos/weaveworks/scope/forks","keys_url":"https://api.github.com/repos/weaveworks/scope/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weaveworks/scope/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weaveworks/scope/teams","hooks_url":"https://api.github.com/repos/weaveworks/scope/hooks","issue_events_url":"https://api.github.com/repos/weaveworks/scope/issues/events{/number}","events_url":"https://api.github.com/repos/weaveworks/scope/events","assignees_url":"https://api.github.com/repos/weaveworks/scope/assignees{/user}","branches_url":"https://api.github.com/repos/weaveworks/scope/branches{/branch}","tags_url":"https://api.github.com/repos/weaveworks/scope/tags","blobs_url":"https://api.github.com/repos/weaveworks/scope/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weaveworks/scope/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weaveworks/scope/git/refs{/sha}","trees_url":"https://api.github.com/repos/weaveworks/scope/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/{sha}","languages_url":"https://api.github.com/repos/weaveworks/scope/languages","stargazers_url":"https://api.github.com/repos/weaveworks/scope/stargazers","contributors_url":"https://api.github.com/repos/weaveworks/scope/contributors","subscribers_url":"https://api.github.com/repos/weaveworks/scope/subscribers","subscription_url":"https://api.github.com/repos/weaveworks/scope/subscription","commits_url":"https://api.github.com/repos/weaveworks/scope/commits{/sha}","git_commits_url":"https://api.github.com/repos/weaveworks/scope/git/commits{/sha}","comments_url":"https://api.github.com/repos/weaveworks/scope/comments{/number}","issue_comment_url":"https://api.github.com/repos/weaveworks/scope/issues/comments{/number}","contents_url":"https://api.github.com/repos/weaveworks/scope/contents/{+path}","compare_url":"https://api.github.com/repos/weaveworks/scope/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weaveworks/scope/merges","archive_url":"https://api.github.com/repos/weaveworks/scope/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weaveworks/scope/downloads","issues_url":"https://api.github.com/repos/weaveworks/scope/issues{/number}","pulls_url":"https://api.github.com/repos/weaveworks/scope/pulls{/number}","milestones_url":"https://api.github.com/repos/weaveworks/scope/milestones{/number}","notifications_url":"https://api.github.com/repos/weaveworks/scope/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weaveworks/scope/labels{/name}","releases_url":"https://api.github.com/repos/weaveworks/scope/releases{/id}","created_at":"2015-04-27T10:12:35Z","updated_at":"2015-12-02T10:32:02Z","pushed_at":"2015-12-03T12:20:52Z","git_url":"git://github.com/weaveworks/scope.git","ssh_url":"git@github.com:weaveworks/scope.git","clone_url":"https://github.com/weaveworks/scope.git","svn_url":"https://github.com/weaveworks/scope","homepage":"http://weave.works/scope","size":38224,"stargazers_count":415,"watchers_count":415,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":66,"forks":24,"open_issues":66,"watchers":415,"default_branch":"master"}},"base":{"label":"weaveworks:master","ref":"master","sha":"16635ab1b2d5fa200eecb78554f0685cfed32114","user":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"repo":{"id":34659664,"name":"scope","full_name":"weaveworks/scope","owner":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/weaveworks/scope","description":"Container visibility","fork":false,"url":"https://api.github.com/repos/weaveworks/scope","forks_url":"https://api.github.com/repos/weaveworks/scope/forks","keys_url":"https://api.github.com/repos/weaveworks/scope/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weaveworks/scope/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weaveworks/scope/teams","hooks_url":"https://api.github.com/repos/weaveworks/scope/hooks","issue_events_url":"https://api.github.com/repos/weaveworks/scope/issues/events{/number}","events_url":"https://api.github.com/repos/weaveworks/scope/events","assignees_url":"https://api.github.com/repos/weaveworks/scope/assignees{/user}","branches_url":"https://api.github.com/repos/weaveworks/scope/branches{/branch}","tags_url":"https://api.github.com/repos/weaveworks/scope/tags","blobs_url":"https://api.github.com/repos/weaveworks/scope/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weaveworks/scope/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weaveworks/scope/git/refs{/sha}","trees_url":"https://api.github.com/repos/weaveworks/scope/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/{sha}","languages_url":"https://api.github.com/repos/weaveworks/scope/languages","stargazers_url":"https://api.github.com/repos/weaveworks/scope/stargazers","contributors_url":"https://api.github.com/repos/weaveworks/scope/contributors","subscribers_url":"https://api.github.com/repos/weaveworks/scope/subscribers","subscription_url":"https://api.github.com/repos/weaveworks/scope/subscription","commits_url":"https://api.github.com/repos/weaveworks/scope/commits{/sha}","git_commits_url":"https://api.github.com/repos/weaveworks/scope/git/commits{/sha}","comments_url":"https://api.github.com/repos/weaveworks/scope/comments{/number}","issue_comment_url":"https://api.github.com/repos/weaveworks/scope/issues/comments{/number}","contents_url":"https://api.github.com/repos/weaveworks/scope/contents/{+path}","compare_url":"https://api.github.com/repos/weaveworks/scope/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weaveworks/scope/merges","archive_url":"https://api.github.com/repos/weaveworks/scope/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weaveworks/scope/downloads","issues_url":"https://api.github.com/repos/weaveworks/scope/issues{/number}","pulls_url":"https://api.github.com/repos/weaveworks/scope/pulls{/number}","milestones_url":"https://api.github.com/repos/weaveworks/scope/milestones{/number}","notifications_url":"https://api.github.com/repos/weaveworks/scope/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weaveworks/scope/labels{/name}","releases_url":"https://api.github.com/repos/weaveworks/scope/releases{/id}","created_at":"2015-04-27T10:12:35Z","updated_at":"2015-12-02T10:32:02Z","pushed_at":"2015-12-03T12:20:52Z","git_url":"git://github.com/weaveworks/scope.git","ssh_url":"git@github.com:weaveworks/scope.git","clone_url":"https://github.com/weaveworks/scope.git","svn_url":"https://github.com/weaveworks/scope","homepage":"http://weave.works/scope","size":38224,"stargazers_count":415,"watchers_count":415,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":66,"forks":24,"open_issues":66,"watchers":415,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/650"},"html":{"href":"https://github.com/weaveworks/scope/pull/650"},"issue":{"href":"https://api.github.com/repos/weaveworks/scope/issues/650"},"comments":{"href":"https://api.github.com/repos/weaveworks/scope/issues/650/comments"},"review_comments":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/650/comments"},"review_comment":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/650/commits"},"statuses":{"href":"https://api.github.com/repos/weaveworks/scope/statuses/090afffa24051563fa6b1ddcf941e609fb37adb4"}}}}