{"action":"created","comment":{"url":"https://api.github.com/repos/ticki/termion/pulls/comments/103086116","pull_request_review_id":23864746,"id":103086116,"diff_hunk":"@@ -0,0 +1,92 @@\n+//! Managing switching between main and alternate screen buffers\n+//!\n+//! Note that this implementation uses xterm's new escape sequences for screen switching and thus\n+//! only works for xterm compatible terminals (which should be most terminals nowadays).\n+//!\n+//! # Example\n+//!\n+//! ```rust\n+//! use termion::screen::AlternateScreen;\n+//! use std::io::{Write, stdout};\n+//!\n+//! fn main() {\n+//!     {\n+//!         let mut screen = AlternateScreen::from(stdout());\n+//!         write!(screen, \"Writing to alternate screen!\").unwrap();\n+//!         screen.flush().unwrap();\n+//!     }\n+//!     println!(\"Writing to main screen.\");\n+//! }\n+//! ```\n+\n+use std::io::{self, Write};\n+use std::ops;\n+use std::fmt;\n+\n+/// Switch to the main screen buffer of the terminal\n+pub struct ToMainScreen;\n+\n+impl fmt::Display for ToMainScreen {\n+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {\n+        write!(f, csi!(\"?1049l\"))\n+    }\n+}\n+\n+/// Switch to the alternate screen buffer of the terminal\n+pub struct ToAlternateScreen;\n+\n+impl fmt::Display for ToAlternateScreen {\n+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {\n+        write!(f, csi!(\"?1049h\"))\n+    }\n+}\n+\n+/// A terminal restorer, which wraps a type implementing Write, and causes all writes to be written\n+/// to an alternate screen.\n+///\n+/// This is achieved by switching the terminal to the alternate screen on creation and\n+/// automatically switching it back to the original screen on drop.\n+pub struct AlternateScreen<W: Write> {\n+    output: W,","path":"src/screen.rs","position":50,"original_position":50,"commit_id":"c4da500ebd14e73bef13834885ebeee30807a671","original_commit_id":"c4da500ebd14e73bef13834885ebeee30807a671","user":{"login":"ticki","id":13349091,"avatar_url":"https://avatars.githubusercontent.com/u/13349091?v=3","gravatar_id":"","url":"https://api.github.com/users/ticki","html_url":"https://github.com/ticki","followers_url":"https://api.github.com/users/ticki/followers","following_url":"https://api.github.com/users/ticki/following{/other_user}","gists_url":"https://api.github.com/users/ticki/gists{/gist_id}","starred_url":"https://api.github.com/users/ticki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ticki/subscriptions","organizations_url":"https://api.github.com/users/ticki/orgs","repos_url":"https://api.github.com/users/ticki/repos","events_url":"https://api.github.com/users/ticki/events{/privacy}","received_events_url":"https://api.github.com/users/ticki/received_events","type":"User","site_admin":false},"body":"I know this is extremely nitpicky, but could you add a comment like\r\n\r\n```\r\n/// The output target.\r\n```\r\n\r\nto this even though it's private?\r\n\r\nIt slightly improves the docs when private item rendering is enabled.","created_at":"2017-02-25T19:20:32Z","updated_at":"2017-02-25T19:21:40Z","html_url":"https://github.com/ticki/termion/pull/88#discussion_r103086116","pull_request_url":"https://api.github.com/repos/ticki/termion/pulls/88","_links":{"self":{"href":"https://api.github.com/repos/ticki/termion/pulls/comments/103086116"},"html":{"href":"https://github.com/ticki/termion/pull/88#discussion_r103086116"},"pull_request":{"href":"https://api.github.com/repos/ticki/termion/pulls/88"}}},"pull_request":{"url":"https://api.github.com/repos/ticki/termion/pulls/88","id":106859861,"html_url":"https://github.com/ticki/termion/pull/88","diff_url":"https://github.com/ticki/termion/pull/88.diff","patch_url":"https://github.com/ticki/termion/pull/88.patch","issue_url":"https://api.github.com/repos/ticki/termion/issues/88","number":88,"state":"open","locked":false,"title":"Add support for alternate screen","user":{"login":"ftilde","id":18011053,"avatar_url":"https://avatars.githubusercontent.com/u/18011053?v=3","gravatar_id":"","url":"https://api.github.com/users/ftilde","html_url":"https://github.com/ftilde","followers_url":"https://api.github.com/users/ftilde/followers","following_url":"https://api.github.com/users/ftilde/following{/other_user}","gists_url":"https://api.github.com/users/ftilde/gists{/gist_id}","starred_url":"https://api.github.com/users/ftilde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ftilde/subscriptions","organizations_url":"https://api.github.com/users/ftilde/orgs","repos_url":"https://api.github.com/users/ftilde/repos","events_url":"https://api.github.com/users/ftilde/events{/privacy}","received_events_url":"https://api.github.com/users/ftilde/received_events","type":"User","site_admin":false},"body":"I went ahead and reimplemented the screen switching escape codes introduced in #66, but followed the suggestions of @jackpot51 in #77 and implemented a separate wrapper struct `AlternateScreen`.\r\n\r\nAdditionally I added two types `ToAlternateScreen` and `ToMainScreen` that can be used directly to switch between screens manually.\r\n\r\nI tried adding tests similar to how it is done in raw.rs, but switching the screen would often mess up the output of `cargo test`, so I removed them.","created_at":"2017-02-18T12:17:01Z","updated_at":"2017-02-25T19:21:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c22d332c674d5e791ce4c19141e400fb4f840566","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ticki/termion/pulls/88/commits","review_comments_url":"https://api.github.com/repos/ticki/termion/pulls/88/comments","review_comment_url":"https://api.github.com/repos/ticki/termion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ticki/termion/issues/88/comments","statuses_url":"https://api.github.com/repos/ticki/termion/statuses/c4da500ebd14e73bef13834885ebeee30807a671","head":{"label":"ftilde:master","ref":"master","sha":"c4da500ebd14e73bef13834885ebeee30807a671","user":{"login":"ftilde","id":18011053,"avatar_url":"https://avatars.githubusercontent.com/u/18011053?v=3","gravatar_id":"","url":"https://api.github.com/users/ftilde","html_url":"https://github.com/ftilde","followers_url":"https://api.github.com/users/ftilde/followers","following_url":"https://api.github.com/users/ftilde/following{/other_user}","gists_url":"https://api.github.com/users/ftilde/gists{/gist_id}","starred_url":"https://api.github.com/users/ftilde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ftilde/subscriptions","organizations_url":"https://api.github.com/users/ftilde/orgs","repos_url":"https://api.github.com/users/ftilde/repos","events_url":"https://api.github.com/users/ftilde/events{/privacy}","received_events_url":"https://api.github.com/users/ftilde/received_events","type":"User","site_admin":false},"repo":{"id":82337474,"name":"termion","full_name":"ftilde/termion","owner":{"login":"ftilde","id":18011053,"avatar_url":"https://avatars.githubusercontent.com/u/18011053?v=3","gravatar_id":"","url":"https://api.github.com/users/ftilde","html_url":"https://github.com/ftilde","followers_url":"https://api.github.com/users/ftilde/followers","following_url":"https://api.github.com/users/ftilde/following{/other_user}","gists_url":"https://api.github.com/users/ftilde/gists{/gist_id}","starred_url":"https://api.github.com/users/ftilde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ftilde/subscriptions","organizations_url":"https://api.github.com/users/ftilde/orgs","repos_url":"https://api.github.com/users/ftilde/repos","events_url":"https://api.github.com/users/ftilde/events{/privacy}","received_events_url":"https://api.github.com/users/ftilde/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ftilde/termion","description":"A bindless library for manipulating terminals.","fork":true,"url":"https://api.github.com/repos/ftilde/termion","forks_url":"https://api.github.com/repos/ftilde/termion/forks","keys_url":"https://api.github.com/repos/ftilde/termion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ftilde/termion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ftilde/termion/teams","hooks_url":"https://api.github.com/repos/ftilde/termion/hooks","issue_events_url":"https://api.github.com/repos/ftilde/termion/issues/events{/number}","events_url":"https://api.github.com/repos/ftilde/termion/events","assignees_url":"https://api.github.com/repos/ftilde/termion/assignees{/user}","branches_url":"https://api.github.com/repos/ftilde/termion/branches{/branch}","tags_url":"https://api.github.com/repos/ftilde/termion/tags","blobs_url":"https://api.github.com/repos/ftilde/termion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ftilde/termion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ftilde/termion/git/refs{/sha}","trees_url":"https://api.github.com/repos/ftilde/termion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ftilde/termion/statuses/{sha}","languages_url":"https://api.github.com/repos/ftilde/termion/languages","stargazers_url":"https://api.github.com/repos/ftilde/termion/stargazers","contributors_url":"https://api.github.com/repos/ftilde/termion/contributors","subscribers_url":"https://api.github.com/repos/ftilde/termion/subscribers","subscription_url":"https://api.github.com/repos/ftilde/termion/subscription","commits_url":"https://api.github.com/repos/ftilde/termion/commits{/sha}","git_commits_url":"https://api.github.com/repos/ftilde/termion/git/commits{/sha}","comments_url":"https://api.github.com/repos/ftilde/termion/comments{/number}","issue_comment_url":"https://api.github.com/repos/ftilde/termion/issues/comments{/number}","contents_url":"https://api.github.com/repos/ftilde/termion/contents/{+path}","compare_url":"https://api.github.com/repos/ftilde/termion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ftilde/termion/merges","archive_url":"https://api.github.com/repos/ftilde/termion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ftilde/termion/downloads","issues_url":"https://api.github.com/repos/ftilde/termion/issues{/number}","pulls_url":"https://api.github.com/repos/ftilde/termion/pulls{/number}","milestones_url":"https://api.github.com/repos/ftilde/termion/milestones{/number}","notifications_url":"https://api.github.com/repos/ftilde/termion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ftilde/termion/labels{/name}","releases_url":"https://api.github.com/repos/ftilde/termion/releases{/id}","deployments_url":"https://api.github.com/repos/ftilde/termion/deployments","created_at":"2017-02-17T21:00:39Z","updated_at":"2017-02-17T21:00:41Z","pushed_at":"2017-02-18T12:15:23Z","git_url":"git://github.com/ftilde/termion.git","ssh_url":"git@github.com:ftilde/termion.git","clone_url":"https://github.com/ftilde/termion.git","svn_url":"https://github.com/ftilde/termion","homepage":"","size":4455,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"ticki:master","ref":"master","sha":"04f6bcd677ac68e6c029be2338d4b3b2d3c851cf","user":{"login":"ticki","id":13349091,"avatar_url":"https://avatars.githubusercontent.com/u/13349091?v=3","gravatar_id":"","url":"https://api.github.com/users/ticki","html_url":"https://github.com/ticki","followers_url":"https://api.github.com/users/ticki/followers","following_url":"https://api.github.com/users/ticki/following{/other_user}","gists_url":"https://api.github.com/users/ticki/gists{/gist_id}","starred_url":"https://api.github.com/users/ticki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ticki/subscriptions","organizations_url":"https://api.github.com/users/ticki/orgs","repos_url":"https://api.github.com/users/ticki/repos","events_url":"https://api.github.com/users/ticki/events{/privacy}","received_events_url":"https://api.github.com/users/ticki/received_events","type":"User","site_admin":false},"repo":{"id":53257295,"name":"termion","full_name":"ticki/termion","owner":{"login":"ticki","id":13349091,"avatar_url":"https://avatars.githubusercontent.com/u/13349091?v=3","gravatar_id":"","url":"https://api.github.com/users/ticki","html_url":"https://github.com/ticki","followers_url":"https://api.github.com/users/ticki/followers","following_url":"https://api.github.com/users/ticki/following{/other_user}","gists_url":"https://api.github.com/users/ticki/gists{/gist_id}","starred_url":"https://api.github.com/users/ticki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ticki/subscriptions","organizations_url":"https://api.github.com/users/ticki/orgs","repos_url":"https://api.github.com/users/ticki/repos","events_url":"https://api.github.com/users/ticki/events{/privacy}","received_events_url":"https://api.github.com/users/ticki/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ticki/termion","description":"A bindless library for manipulating terminals.","fork":false,"url":"https://api.github.com/repos/ticki/termion","forks_url":"https://api.github.com/repos/ticki/termion/forks","keys_url":"https://api.github.com/repos/ticki/termion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ticki/termion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ticki/termion/teams","hooks_url":"https://api.github.com/repos/ticki/termion/hooks","issue_events_url":"https://api.github.com/repos/ticki/termion/issues/events{/number}","events_url":"https://api.github.com/repos/ticki/termion/events","assignees_url":"https://api.github.com/repos/ticki/termion/assignees{/user}","branches_url":"https://api.github.com/repos/ticki/termion/branches{/branch}","tags_url":"https://api.github.com/repos/ticki/termion/tags","blobs_url":"https://api.github.com/repos/ticki/termion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ticki/termion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ticki/termion/git/refs{/sha}","trees_url":"https://api.github.com/repos/ticki/termion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ticki/termion/statuses/{sha}","languages_url":"https://api.github.com/repos/ticki/termion/languages","stargazers_url":"https://api.github.com/repos/ticki/termion/stargazers","contributors_url":"https://api.github.com/repos/ticki/termion/contributors","subscribers_url":"https://api.github.com/repos/ticki/termion/subscribers","subscription_url":"https://api.github.com/repos/ticki/termion/subscription","commits_url":"https://api.github.com/repos/ticki/termion/commits{/sha}","git_commits_url":"https://api.github.com/repos/ticki/termion/git/commits{/sha}","comments_url":"https://api.github.com/repos/ticki/termion/comments{/number}","issue_comment_url":"https://api.github.com/repos/ticki/termion/issues/comments{/number}","contents_url":"https://api.github.com/repos/ticki/termion/contents/{+path}","compare_url":"https://api.github.com/repos/ticki/termion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ticki/termion/merges","archive_url":"https://api.github.com/repos/ticki/termion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ticki/termion/downloads","issues_url":"https://api.github.com/repos/ticki/termion/issues{/number}","pulls_url":"https://api.github.com/repos/ticki/termion/pulls{/number}","milestones_url":"https://api.github.com/repos/ticki/termion/milestones{/number}","notifications_url":"https://api.github.com/repos/ticki/termion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ticki/termion/labels{/name}","releases_url":"https://api.github.com/repos/ticki/termion/releases{/id}","deployments_url":"https://api.github.com/repos/ticki/termion/deployments","created_at":"2016-03-06T13:54:02Z","updated_at":"2017-02-24T05:10:50Z","pushed_at":"2017-02-25T19:17:55Z","git_url":"git://github.com/ticki/termion.git","ssh_url":"git@github.com:ticki/termion.git","clone_url":"https://github.com/ticki/termion.git","svn_url":"https://github.com/ticki/termion","homepage":"","size":4452,"stargazers_count":420,"watchers_count":420,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":35,"mirror_url":null,"open_issues_count":15,"forks":35,"open_issues":15,"watchers":420,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ticki/termion/pulls/88"},"html":{"href":"https://github.com/ticki/termion/pull/88"},"issue":{"href":"https://api.github.com/repos/ticki/termion/issues/88"},"comments":{"href":"https://api.github.com/repos/ticki/termion/issues/88/comments"},"review_comments":{"href":"https://api.github.com/repos/ticki/termion/pulls/88/comments"},"review_comment":{"href":"https://api.github.com/repos/ticki/termion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ticki/termion/pulls/88/commits"},"statuses":{"href":"https://api.github.com/repos/ticki/termion/statuses/c4da500ebd14e73bef13834885ebeee30807a671"}}}}
{"actor":{"display_login":"ticki"}}