{"action":"created","comment":{"url":"https://api.github.com/repos/SirCmpwn/sway/pulls/comments/48267867","id":48267867,"diff_hunk":"@@ -401,6 +462,247 @@ void render() {\n \t}\n }\n \n+void free_status_block(void *item) {\n+\tif (!item) {\n+\t\treturn;\n+\t}\n+\tstruct status_block *sb = (struct status_block*)item;\n+\tif (sb->full_text) { \n+\t\tfree(sb->full_text);\n+\t}\n+\tif (sb->short_text) {\n+\t\tfree(sb->short_text);\n+\t}\n+\tif (sb->align) {\n+\t\tfree(sb->align);\n+\t}\n+\tif (sb->name) {\n+\t\tfree(sb->name);\n+\t}\n+\tif (sb->instance) {\n+\t\tfree(sb->instance);\n+\t}\n+\tfree(sb);\n+}\n+\n+void parse_json(const char *text) {\n+/* the array of objects looks like this:\n+ * [ {\n+ *     \"full_text\": \"E: 10.0.0.1 (1000 Mbit/s)\",\n+ *     \"short_text\": \"10.0.0.1\",\n+ *     \"color\": \"#00ff00\",\n+ *     \"min_width\": 300,\n+ *     \"align\": \"right\",\n+ *     \"urgent\": false,\n+ *     \"name\": \"ethernet\",\n+ *     \"instance\": \"eth0\",\n+ *     \"separator\": true,\n+ *     \"separator_block_width\": 9\n+ *   },\n+ *   { ... }, ...\n+ * ]\n+ */\n+\tjson_object *results = json_tokener_parse(text);\n+\tif (!results) {\n+\t\tsway_log(L_DEBUG, \"xxx Failed to parse json\");\n+\t\treturn;\n+\t}\n+\n+\tif (json_object_array_length(results) < 1) {\n+\t\treturn;\n+\t}\n+\n+\tif (status_line) {\n+\t\tlist_foreach(status_line, free_status_block);\n+\t\tlist_free(status_line);\n+\t}\n+\n+\tstatus_line = create_list();\n+\n+\tint i;\n+\tfor (i = 0; i < json_object_array_length(results); ++i) {\n+\t\tjson_object *full_text, *short_text, *color, *min_width, *align, *urgent;\n+\t\tjson_object *name, *instance, *separator, *separator_block_width;\n+\n+\t\tjson_object *json = json_object_array_get_idx(results, i);\n+\t\tif (!json) {\n+\t\t\t\tcontinue;\n+\t\t}\n+\n+\t\tjson_object_object_get_ex(json, \"full_text\", &full_text);\n+\t\tjson_object_object_get_ex(json, \"short_text\", &short_text);\n+\t\tjson_object_object_get_ex(json, \"color\", &color);\n+\t\tjson_object_object_get_ex(json, \"min_width\", &min_width);\n+\t\tjson_object_object_get_ex(json, \"align\", &align);\n+\t\tjson_object_object_get_ex(json, \"urgent\", &urgent);\n+\t\tjson_object_object_get_ex(json, \"name\", &name);\n+\t\tjson_object_object_get_ex(json, \"instance\", &instance);\n+\t\tjson_object_object_get_ex(json, \"separator\", &separator);\n+\t\tjson_object_object_get_ex(json, \"separator_block_width\", &separator_block_width);\n+\n+\t\tstruct status_block *new = malloc(sizeof(struct status_block));\n+\t\tmemset(new, 0, sizeof(struct status_block));\n+\n+\t\tif (full_text) {\n+\t\t\tnew->full_text = strdup(json_object_get_string(full_text));\n+\t\t}\n+\n+\t\tif (short_text) {\n+\t\t\tnew->short_text = strdup(json_object_get_string(short_text));\n+\t\t}\n+\n+\t\tif (color) {\n+\t\t\tnew->color = parse_color(json_object_get_string(color));\n+\t\t}\n+\t\telse {\n+\t\t\tnew->color = 0xFFFFFFFF;\n+\t\t}\n+\n+\t\tif (min_width) {\n+\t\t\tnew->min_width = json_object_get_int(min_width);\n+\t\t}\n+\n+\t\tif (align) {\n+\t\t\tnew->align = strdup(json_object_get_string(align));\n+\t\t}\n+\t\telse {\n+\t\t\tnew->align = strdup(\"left\");\n+\t\t}\n+\n+\t\tif (urgent) {\n+\t\t\tnew->urgent = json_object_get_int(urgent);\n+\t\t}\n+\n+\t\tif (name) {\n+\t\t\tnew->name = strdup(json_object_get_string(name));\n+\t\t}\n+\n+\t\tif (instance) {\n+\t\t\tnew->instance = strdup(json_object_get_string(instance));\n+\t\t}\n+\n+\t\tif (separator) {\n+\t\t\tnew->separator = json_object_get_int(separator);\n+\t\t}\n+\t\telse {\n+\t\t\tnew->separator = true; // i3bar spec\n+\t\t}\n+\n+\t\tif (separator_block_width) {\n+\t\t\tnew->separator_block_width = json_object_get_int(separator_block_width);\n+\t\t}\n+\t\telse {\n+\t\t\tnew->separator_block_width = 9; // i3bar spec\n+\t\t}\n+\n+\t\tlist_add(status_line, new);\n+\t}\n+\n+\tjson_object_put(results);\n+}\n+\n+/*void i3json_handle_line(const char *data, ssize_t len) {\n+\tjson_object *parts = json_tokener_parse(data);\n+\tif (!parts){\n+\t\treturn;\n+\t}\n+\tline[0]='\\0';\n+\tint n = json_object_array_length(parts);\n+\tint i;\n+\tint l = 0;\n+\tfor (i = 0; i < n; ++i) {\n+\t\t// create basic text-only result\n+\t\tjson_object *part = json_object_array_get_idx(parts, i);\n+\t\tjson_object *text;\n+\t\tif (json_object_object_get_ex(part, \"full_text\", &text)) {\n+\t\t\tl += json_object_get_string_len(text) + 1;\n+\t\t\tif (l > 1024) {\n+\t\t\t\t// cut too long lines\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tstrcat(line, json_object_get_string(text));\n+\t\t\tline[l-1] = '|';\n+\t\t\tif (l < 1024) {\n+\t\t\t\tline[l] = '\\0';\n+\t\t\t}\n+\t\t}\n+\t}\n+\tline[l-1] = '\\0';\n+\tjson_object_put(parts);\n+}\n+*/\n+\n+int i3json_handle(FILE *file) {\n+\tchar *c;\n+\tint handled = 0;\n+\t// handle partially buffered data\n+\t// make sure 1023+1 bytes at the end are free\n+\tif (i3json_state.line_start) {\n+\t\tint len = strlen(i3json_state.line_start);\n+\t\tmemmove(i3json_state.buffer, i3json_state.line_start, len+1);\n+\t\tif ( i3json_state.bufsize < len+1024 ) {\n+\t\t\ti3json_state.bufsize += 1024;\n+\t\t\ti3json_state.buffer = realloc(i3json_state.buffer, i3json_state.bufsize);\n+\t\t}\n+\t\tc = i3json_state.buffer+len;\n+\t\ti3json_state.line_start = i3json_state.buffer;\n+\t} else if (!i3json_state.buffer) {\n+\t\ti3json_state.buffer = malloc(1024);\n+\t\ti3json_state.bufsize = 1024;\n+\t\tc = i3json_state.buffer;\n+\t} else {\n+\t\tc = i3json_state.buffer;\n+\t}\n+\tif (!i3json_state.buffer) {\n+\t\tsway_abort(\"Could not allocate buffer.\");\n+\t}\n+\t// get fresh data at the end of the buffer\n+\tif (!fgets(c, 1023, file)) return -1;\n+\tc[1023] = '\\0';\n+\n+\twhile (*c) {\n+\t\tif (i3json_state.state[i3json_state.depth] == I3JSON_STRING) {\n+\t\t\tif (!i3json_state.escape && *c == '\"') {\n+\t\t\t\t--i3json_state.depth;\n+\t\t\t}\n+\t\t\ti3json_state.escape = !i3json_state.escape && *c == '\\\\';\n+\t\t} else switch (*c) {","path":"swaybar/main.c","position":324,"original_position":324,"commit_id":"1efd3b5fba2ff28307f3216d5eca04f8987a8add","original_commit_id":"1efd3b5fba2ff28307f3216d5eca04f8987a8add","user":{"login":"progandy","id":1003865,"avatar_url":"https://avatars.githubusercontent.com/u/1003865?v=3","gravatar_id":"","url":"https://api.github.com/users/progandy","html_url":"https://github.com/progandy","followers_url":"https://api.github.com/users/progandy/followers","following_url":"https://api.github.com/users/progandy/following{/other_user}","gists_url":"https://api.github.com/users/progandy/gists{/gist_id}","starred_url":"https://api.github.com/users/progandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/progandy/subscriptions","organizations_url":"https://api.github.com/users/progandy/orgs","repos_url":"https://api.github.com/users/progandy/repos","events_url":"https://api.github.com/users/progandy/events{/privacy}","received_events_url":"https://api.github.com/users/progandy/received_events","type":"User","site_admin":false},"body":"Is this ok?\r\n```\r\nif () {\r\n} else {\r\n  switch () {\r\n  case:\r\n  }\r\n}\r\n```","created_at":"2015-12-22T16:08:15Z","updated_at":"2015-12-22T16:08:15Z","html_url":"https://github.com/SirCmpwn/sway/pull/394#discussion_r48267867","pull_request_url":"https://api.github.com/repos/SirCmpwn/sway/pulls/394","_links":{"self":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/comments/48267867"},"html":{"href":"https://github.com/SirCmpwn/sway/pull/394#discussion_r48267867"},"pull_request":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/394"}}},"pull_request":{"url":"https://api.github.com/repos/SirCmpwn/sway/pulls/394","id":54381333,"html_url":"https://github.com/SirCmpwn/sway/pull/394","diff_url":"https://github.com/SirCmpwn/sway/pull/394.diff","patch_url":"https://github.com/SirCmpwn/sway/pull/394.patch","issue_url":"https://api.github.com/repos/SirCmpwn/sway/issues/394","number":394,"state":"open","locked":false,"title":"swaybar: I3bar json protocol","user":{"login":"progandy","id":1003865,"avatar_url":"https://avatars.githubusercontent.com/u/1003865?v=3","gravatar_id":"","url":"https://api.github.com/users/progandy","html_url":"https://github.com/progandy","followers_url":"https://api.github.com/users/progandy/followers","following_url":"https://api.github.com/users/progandy/following{/other_user}","gists_url":"https://api.github.com/users/progandy/gists{/gist_id}","starred_url":"https://api.github.com/users/progandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/progandy/subscriptions","organizations_url":"https://api.github.com/users/progandy/orgs","repos_url":"https://api.github.com/users/progandy/repos","events_url":"https://api.github.com/users/progandy/events{/privacy}","received_events_url":"https://api.github.com/users/progandy/received_events","type":"User","site_admin":false},"body":"This commit series implements three things:\r\n* Allow swaybar to understand the i3bar json protocol.\r\n* Format output with specified colors and separators.\r\n* Fall back to legacy single line text if the status_command doesn't ask for the json protocol.","created_at":"2015-12-22T15:29:39Z","updated_at":"2015-12-22T16:08:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"471722d8d173187261d92920c5ded12c2d6ec7aa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SirCmpwn/sway/pulls/394/commits","review_comments_url":"https://api.github.com/repos/SirCmpwn/sway/pulls/394/comments","review_comment_url":"https://api.github.com/repos/SirCmpwn/sway/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SirCmpwn/sway/issues/394/comments","statuses_url":"https://api.github.com/repos/SirCmpwn/sway/statuses/1efd3b5fba2ff28307f3216d5eca04f8987a8add","head":{"label":"progandy:i3bar-json-protocol","ref":"i3bar-json-protocol","sha":"1efd3b5fba2ff28307f3216d5eca04f8987a8add","user":{"login":"progandy","id":1003865,"avatar_url":"https://avatars.githubusercontent.com/u/1003865?v=3","gravatar_id":"","url":"https://api.github.com/users/progandy","html_url":"https://github.com/progandy","followers_url":"https://api.github.com/users/progandy/followers","following_url":"https://api.github.com/users/progandy/following{/other_user}","gists_url":"https://api.github.com/users/progandy/gists{/gist_id}","starred_url":"https://api.github.com/users/progandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/progandy/subscriptions","organizations_url":"https://api.github.com/users/progandy/orgs","repos_url":"https://api.github.com/users/progandy/repos","events_url":"https://api.github.com/users/progandy/events{/privacy}","received_events_url":"https://api.github.com/users/progandy/received_events","type":"User","site_admin":false},"repo":{"id":47418838,"name":"sway","full_name":"progandy/sway","owner":{"login":"progandy","id":1003865,"avatar_url":"https://avatars.githubusercontent.com/u/1003865?v=3","gravatar_id":"","url":"https://api.github.com/users/progandy","html_url":"https://github.com/progandy","followers_url":"https://api.github.com/users/progandy/followers","following_url":"https://api.github.com/users/progandy/following{/other_user}","gists_url":"https://api.github.com/users/progandy/gists{/gist_id}","starred_url":"https://api.github.com/users/progandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/progandy/subscriptions","organizations_url":"https://api.github.com/users/progandy/orgs","repos_url":"https://api.github.com/users/progandy/repos","events_url":"https://api.github.com/users/progandy/events{/privacy}","received_events_url":"https://api.github.com/users/progandy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/progandy/sway","description":"i3-compatible window manager for Wayland (WIP)","fork":true,"url":"https://api.github.com/repos/progandy/sway","forks_url":"https://api.github.com/repos/progandy/sway/forks","keys_url":"https://api.github.com/repos/progandy/sway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/progandy/sway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/progandy/sway/teams","hooks_url":"https://api.github.com/repos/progandy/sway/hooks","issue_events_url":"https://api.github.com/repos/progandy/sway/issues/events{/number}","events_url":"https://api.github.com/repos/progandy/sway/events","assignees_url":"https://api.github.com/repos/progandy/sway/assignees{/user}","branches_url":"https://api.github.com/repos/progandy/sway/branches{/branch}","tags_url":"https://api.github.com/repos/progandy/sway/tags","blobs_url":"https://api.github.com/repos/progandy/sway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/progandy/sway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/progandy/sway/git/refs{/sha}","trees_url":"https://api.github.com/repos/progandy/sway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/progandy/sway/statuses/{sha}","languages_url":"https://api.github.com/repos/progandy/sway/languages","stargazers_url":"https://api.github.com/repos/progandy/sway/stargazers","contributors_url":"https://api.github.com/repos/progandy/sway/contributors","subscribers_url":"https://api.github.com/repos/progandy/sway/subscribers","subscription_url":"https://api.github.com/repos/progandy/sway/subscription","commits_url":"https://api.github.com/repos/progandy/sway/commits{/sha}","git_commits_url":"https://api.github.com/repos/progandy/sway/git/commits{/sha}","comments_url":"https://api.github.com/repos/progandy/sway/comments{/number}","issue_comment_url":"https://api.github.com/repos/progandy/sway/issues/comments{/number}","contents_url":"https://api.github.com/repos/progandy/sway/contents/{+path}","compare_url":"https://api.github.com/repos/progandy/sway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/progandy/sway/merges","archive_url":"https://api.github.com/repos/progandy/sway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/progandy/sway/downloads","issues_url":"https://api.github.com/repos/progandy/sway/issues{/number}","pulls_url":"https://api.github.com/repos/progandy/sway/pulls{/number}","milestones_url":"https://api.github.com/repos/progandy/sway/milestones{/number}","notifications_url":"https://api.github.com/repos/progandy/sway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/progandy/sway/labels{/name}","releases_url":"https://api.github.com/repos/progandy/sway/releases{/id}","created_at":"2015-12-04T17:23:40Z","updated_at":"2015-12-04T17:23:40Z","pushed_at":"2015-12-22T14:39:19Z","git_url":"git://github.com/progandy/sway.git","ssh_url":"git@github.com:progandy/sway.git","clone_url":"https://github.com/progandy/sway.git","svn_url":"https://github.com/progandy/sway","homepage":"http://swaywm.org/","size":1199,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SirCmpwn:master","ref":"master","sha":"8a22ac3966047353daffe88dd4b8c2910ef519f5","user":{"login":"SirCmpwn","id":1310872,"avatar_url":"https://avatars.githubusercontent.com/u/1310872?v=3","gravatar_id":"","url":"https://api.github.com/users/SirCmpwn","html_url":"https://github.com/SirCmpwn","followers_url":"https://api.github.com/users/SirCmpwn/followers","following_url":"https://api.github.com/users/SirCmpwn/following{/other_user}","gists_url":"https://api.github.com/users/SirCmpwn/gists{/gist_id}","starred_url":"https://api.github.com/users/SirCmpwn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirCmpwn/subscriptions","organizations_url":"https://api.github.com/users/SirCmpwn/orgs","repos_url":"https://api.github.com/users/SirCmpwn/repos","events_url":"https://api.github.com/users/SirCmpwn/events{/privacy}","received_events_url":"https://api.github.com/users/SirCmpwn/received_events","type":"User","site_admin":false},"repo":{"id":40217904,"name":"sway","full_name":"SirCmpwn/sway","owner":{"login":"SirCmpwn","id":1310872,"avatar_url":"https://avatars.githubusercontent.com/u/1310872?v=3","gravatar_id":"","url":"https://api.github.com/users/SirCmpwn","html_url":"https://github.com/SirCmpwn","followers_url":"https://api.github.com/users/SirCmpwn/followers","following_url":"https://api.github.com/users/SirCmpwn/following{/other_user}","gists_url":"https://api.github.com/users/SirCmpwn/gists{/gist_id}","starred_url":"https://api.github.com/users/SirCmpwn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirCmpwn/subscriptions","organizations_url":"https://api.github.com/users/SirCmpwn/orgs","repos_url":"https://api.github.com/users/SirCmpwn/repos","events_url":"https://api.github.com/users/SirCmpwn/events{/privacy}","received_events_url":"https://api.github.com/users/SirCmpwn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SirCmpwn/sway","description":"i3-compatible window manager for Wayland (WIP)","fork":false,"url":"https://api.github.com/repos/SirCmpwn/sway","forks_url":"https://api.github.com/repos/SirCmpwn/sway/forks","keys_url":"https://api.github.com/repos/SirCmpwn/sway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SirCmpwn/sway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SirCmpwn/sway/teams","hooks_url":"https://api.github.com/repos/SirCmpwn/sway/hooks","issue_events_url":"https://api.github.com/repos/SirCmpwn/sway/issues/events{/number}","events_url":"https://api.github.com/repos/SirCmpwn/sway/events","assignees_url":"https://api.github.com/repos/SirCmpwn/sway/assignees{/user}","branches_url":"https://api.github.com/repos/SirCmpwn/sway/branches{/branch}","tags_url":"https://api.github.com/repos/SirCmpwn/sway/tags","blobs_url":"https://api.github.com/repos/SirCmpwn/sway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SirCmpwn/sway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SirCmpwn/sway/git/refs{/sha}","trees_url":"https://api.github.com/repos/SirCmpwn/sway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SirCmpwn/sway/statuses/{sha}","languages_url":"https://api.github.com/repos/SirCmpwn/sway/languages","stargazers_url":"https://api.github.com/repos/SirCmpwn/sway/stargazers","contributors_url":"https://api.github.com/repos/SirCmpwn/sway/contributors","subscribers_url":"https://api.github.com/repos/SirCmpwn/sway/subscribers","subscription_url":"https://api.github.com/repos/SirCmpwn/sway/subscription","commits_url":"https://api.github.com/repos/SirCmpwn/sway/commits{/sha}","git_commits_url":"https://api.github.com/repos/SirCmpwn/sway/git/commits{/sha}","comments_url":"https://api.github.com/repos/SirCmpwn/sway/comments{/number}","issue_comment_url":"https://api.github.com/repos/SirCmpwn/sway/issues/comments{/number}","contents_url":"https://api.github.com/repos/SirCmpwn/sway/contents/{+path}","compare_url":"https://api.github.com/repos/SirCmpwn/sway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SirCmpwn/sway/merges","archive_url":"https://api.github.com/repos/SirCmpwn/sway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SirCmpwn/sway/downloads","issues_url":"https://api.github.com/repos/SirCmpwn/sway/issues{/number}","pulls_url":"https://api.github.com/repos/SirCmpwn/sway/pulls{/number}","milestones_url":"https://api.github.com/repos/SirCmpwn/sway/milestones{/number}","notifications_url":"https://api.github.com/repos/SirCmpwn/sway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SirCmpwn/sway/labels{/name}","releases_url":"https://api.github.com/repos/SirCmpwn/sway/releases{/id}","created_at":"2015-08-05T01:31:45Z","updated_at":"2015-12-22T15:14:20Z","pushed_at":"2015-12-22T15:29:40Z","git_url":"git://github.com/SirCmpwn/sway.git","ssh_url":"git@github.com:SirCmpwn/sway.git","clone_url":"https://github.com/SirCmpwn/sway.git","svn_url":"https://github.com/SirCmpwn/sway","homepage":"http://swaywm.org/","size":1279,"stargazers_count":754,"watchers_count":754,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":53,"mirror_url":null,"open_issues_count":32,"forks":53,"open_issues":32,"watchers":754,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/394"},"html":{"href":"https://github.com/SirCmpwn/sway/pull/394"},"issue":{"href":"https://api.github.com/repos/SirCmpwn/sway/issues/394"},"comments":{"href":"https://api.github.com/repos/SirCmpwn/sway/issues/394/comments"},"review_comments":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/394/comments"},"review_comment":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SirCmpwn/sway/pulls/394/commits"},"statuses":{"href":"https://api.github.com/repos/SirCmpwn/sway/statuses/1efd3b5fba2ff28307f3216d5eca04f8987a8add"}}}}