{"action":"created","comment":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/39477151","id":39477151,"diff_hunk":"@@ -641,6 +663,213 @@ controller.tesselFirmwareVerion = function(opts) {\n         });\n     });\n };\n+controller.menu = {\n+\n+  prepareMenu: function(opts, tessels, resolve, reject, title, callback) {\n+    //return new Promise(function(resolve, reject) {\n+\n+    var rtm = new Menu({\n+      //  width: process.stdout.columns - 4,\n+      width: 55,\n+      x: 1,\n+      y: 2,\n+      bg: 'red'\n+    });\n+    rtm.reset();\n+    rtm.write(title + '\\n');\n+    rtm.write('                                                \\n');\n+\n+    // create menu entries\n+    for (var i in tessels) {\n+      controller.menu.makeMenu(tessels[i], i, rtm);\n+    }\n+\n+    rtm.add('EXIT\\n');\n+    rtm._draw();\n+    if (!opts.menu) {\n+      // if this is no test, starting the menu as child process\n+      controller.menu.showMenu(rtm, resolve, reject);\n+    } else {\n+      // because the test needs to resolve the promise ...\n+      resolve({\n+        opts: opts,\n+        tessels: tessels\n+      });\n+    }\n+\n+    rtm.once('select', function(label, index) {\n+      rtm.close();\n+      controller.menu.clear();\n+\n+      // Identify the Exit command by first letter (all other entries start with numbers/index)\n+      if (label[0] !== 'E') {\n+        callback(tessels[index].name, index, resolve, reject);\n+        // controller.ssh.runSSH(index, opts, tessels, resolve, reject);\n+      } else {\n+        // going to clear screen and calling exit to resolve promise\n+        controller.menu.clear();\n+        controller.menu.exit(resolve);\n+      }\n+    });\n+    //  });\n+  },\n+  makeMenu: function(tessel, index, rtm) {\n+    if (tessel.lanConnection) {\n+      if (!tessel.lanConnection.authorized) {\n+        rtm.add(index + ') ' + tessel.name + ': ' + tessel.lanConnection.ip + ' (not authorized) \\n');\n+      } else {\n+        rtm.add(index + ') ' + tessel.name + ': ' + tessel.lanConnection.ip + ' (authorized) \\n');\n+      }\n+\n+    } else if (tessel.usbConnection) {\n+      if (!tessel.usbConnection.authorized) {\n+        rtm.add(index + ') ' + tessel.name + ': [USB] (not authorized) \\n');\n+      } else {\n+        rtm.add(index + ') ' + tessel.name + ': [USB] (authorized) \\n');\n+      }\n+    }\n+    // FIXME: Workaround for trouble with dynamic added menu elements\n+    rtm._draw();\n+  },\n+  showMenu: function(rtm, resolve, reject) {\n+    // Menu navigation\n+    process.stdin.pipe(rtm.createStream()).pipe(process.stdout);\n+\n+    // raw mode for gain ability to navigate up and down within the menu\n+    process.stdin.setRawMode(true);\n+\n+    // cb \n+    rtm.on('close', function() {\n+      process.stdin.setRawMode(false);\n+      process.stdin.end();\n+    });\n+    rtm.on('error', function(e) {\n+      process.stdin.setRawMode(false);\n+      reject(e);\n+    });\n+  },\n+  seek: function(opts) {\n+    // to be able to replace the seeker in testing mode\n+    // return Tessel.seekTessels(opts);\n+    return Tessel.get(opts);\n+  },\n+  clear: function() {\n+    // selected exit!\n+    process.stdout.write('\\u001b[2J\\u001b[0;0H');\n+  },\n+  exit: function(resolve) {\n+    resolve();\n+    //process.exit();\n+  }\n+};\n+controller.ssh = {\n+  runSSH: function(id, opts, tessels, resolve, reject) {\n+    // clear console\n+    debug('runSSH...\\n root@' + tessels[id].lanConnection.host);\n+    if (opts.menu) {\n+      // because the test needs to resolve the promise ...\n+      resolve({\n+        opts: opts,\n+        tessels: tessels\n+      });\n+    } else {\n+      // if this is no test, starting the menu as child process\n+      controller.menu.clear();\n+      var ch = require('child_process')\n+        .spawn('ssh', ['-i',\n+          opts.path,\n+          'root@' + tessels[id].lanConnection.ip\n+        ], {\n+          stdio: 'inherit'\n+        });\n+      logs.info('Connect to ' + tessels[id].lanConnection.host + '...');\n+\n+      // FIXME: There is no handler for poweroff Tessel ! Needs to be fixed within the firmware...\n+      // (Terminal freezes imediatelly after poweroff the Tessel)\n+\n+      ch.once('error', function(e) {\n+        if (e === 255) {\n+          controller.menu.clear();\n+          controller.ssh.notAuthorized();","path":"lib/controller.js","position":224,"original_position":224,"commit_id":"0ddb61d06ca991d11fab653e8cfd5a7e8eaaed45","original_commit_id":"0ddb61d06ca991d11fab653e8cfd5a7e8eaaed45","user":{"login":"johnnyman727","id":432909,"avatar_url":"https://avatars.githubusercontent.com/u/432909?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnyman727","html_url":"https://github.com/johnnyman727","followers_url":"https://api.github.com/users/johnnyman727/followers","following_url":"https://api.github.com/users/johnnyman727/following{/other_user}","gists_url":"https://api.github.com/users/johnnyman727/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnyman727/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnyman727/subscriptions","organizations_url":"https://api.github.com/users/johnnyman727/orgs","repos_url":"https://api.github.com/users/johnnyman727/repos","events_url":"https://api.github.com/users/johnnyman727/events{/privacy}","received_events_url":"https://api.github.com/users/johnnyman727/received_events","type":"User","site_admin":false},"body":"How would it get to this point if it's not authorized?","created_at":"2015-09-15T06:06:10Z","updated_at":"2015-09-15T06:06:10Z","html_url":"https://github.com/tessel/t2-cli/pull/307#discussion_r39477151","pull_request_url":"https://api.github.com/repos/tessel/t2-cli/pulls/307","_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/39477151"},"html":{"href":"https://github.com/tessel/t2-cli/pull/307#discussion_r39477151"},"pull_request":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/307"}}},"pull_request":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/307","id":44936419,"html_url":"https://github.com/tessel/t2-cli/pull/307","diff_url":"https://github.com/tessel/t2-cli/pull/307.diff","patch_url":"https://github.com/tessel/t2-cli/pull/307.patch","issue_url":"https://api.github.com/repos/tessel/t2-cli/issues/307","number":307,"state":"open","locked":false,"title":"t2 root","user":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"body":"@johnnyman727 please take a look at both commit comments and additional requests on slack :smile: ","created_at":"2015-09-14T14:28:07Z","updated_at":"2015-09-15T06:06:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f12dd324149e485020ba61872e6e8cc1bb87094","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tessel/t2-cli/pulls/307/commits","review_comments_url":"https://api.github.com/repos/tessel/t2-cli/pulls/307/comments","review_comment_url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tessel/t2-cli/issues/307/comments","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/0ddb61d06ca991d11fab653e8cfd5a7e8eaaed45","head":{"label":"Student007:root","ref":"root","sha":"0ddb61d06ca991d11fab653e8cfd5a7e8eaaed45","user":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"repo":{"id":39995577,"name":"t2-cli","full_name":"Student007/t2-cli","owner":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Student007/t2-cli","description":"Command line interface to Tessel 2.","fork":true,"url":"https://api.github.com/repos/Student007/t2-cli","forks_url":"https://api.github.com/repos/Student007/t2-cli/forks","keys_url":"https://api.github.com/repos/Student007/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Student007/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Student007/t2-cli/teams","hooks_url":"https://api.github.com/repos/Student007/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/Student007/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/Student007/t2-cli/events","assignees_url":"https://api.github.com/repos/Student007/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/Student007/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/Student007/t2-cli/tags","blobs_url":"https://api.github.com/repos/Student007/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Student007/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Student007/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/Student007/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Student007/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/Student007/t2-cli/languages","stargazers_url":"https://api.github.com/repos/Student007/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/Student007/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/Student007/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/Student007/t2-cli/subscription","commits_url":"https://api.github.com/repos/Student007/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/Student007/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/Student007/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/Student007/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/Student007/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/Student007/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Student007/t2-cli/merges","archive_url":"https://api.github.com/repos/Student007/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Student007/t2-cli/downloads","issues_url":"https://api.github.com/repos/Student007/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/Student007/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/Student007/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/Student007/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Student007/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/Student007/t2-cli/releases{/id}","created_at":"2015-07-31T08:38:19Z","updated_at":"2015-07-31T08:38:19Z","pushed_at":"2015-09-14T14:25:21Z","git_url":"git://github.com/Student007/t2-cli.git","ssh_url":"git@github.com:Student007/t2-cli.git","clone_url":"https://github.com/Student007/t2-cli.git","svn_url":"https://github.com/Student007/t2-cli","homepage":"","size":709,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tessel:master","ref":"master","sha":"9336b3987685e0282bd23a4b833bf4d89f7ad762","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":30388450,"name":"t2-cli","full_name":"tessel/t2-cli","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/t2-cli","description":"Command line interface to Tessel 2.","fork":false,"url":"https://api.github.com/repos/tessel/t2-cli","forks_url":"https://api.github.com/repos/tessel/t2-cli/forks","keys_url":"https://api.github.com/repos/tessel/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/t2-cli/teams","hooks_url":"https://api.github.com/repos/tessel/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/tessel/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/t2-cli/events","assignees_url":"https://api.github.com/repos/tessel/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/t2-cli/tags","blobs_url":"https://api.github.com/repos/tessel/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/t2-cli/languages","stargazers_url":"https://api.github.com/repos/tessel/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/tessel/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/tessel/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/tessel/t2-cli/subscription","commits_url":"https://api.github.com/repos/tessel/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/t2-cli/merges","archive_url":"https://api.github.com/repos/tessel/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/t2-cli/downloads","issues_url":"https://api.github.com/repos/tessel/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/tessel/t2-cli/releases{/id}","created_at":"2015-02-06T01:27:53Z","updated_at":"2015-09-08T13:48:27Z","pushed_at":"2015-09-15T06:03:07Z","git_url":"git://github.com/tessel/t2-cli.git","ssh_url":"git@github.com:tessel/t2-cli.git","clone_url":"https://github.com/tessel/t2-cli.git","svn_url":"https://github.com/tessel/t2-cli","homepage":"","size":2370,"stargazers_count":27,"watchers_count":27,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":57,"forks":8,"open_issues":57,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/307"},"html":{"href":"https://github.com/tessel/t2-cli/pull/307"},"issue":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/307"},"comments":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/307/comments"},"review_comments":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/307/comments"},"review_comment":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/307/commits"},"statuses":{"href":"https://api.github.com/repos/tessel/t2-cli/statuses/0ddb61d06ca991d11fab653e8cfd5a7e8eaaed45"}}}}