{"id":703,"date":"2020-05-28T20:02:19","date_gmt":"2020-05-28T14:32:19","guid":{"rendered":"http:\/\/www.cyberaka.com\/?p=703"},"modified":"2020-05-28T20:02:20","modified_gmt":"2020-05-28T14:32:20","slug":"progress-bar-implementation-in-java-for-terminal-application","status":"publish","type":"post","link":"https:\/\/www.cyberaka.com\/?p=703","title":{"rendered":"Progress Bar implementation in Java for Terminal application"},"content":{"rendered":"\n<p>Th e&#8221;\\r&#8221; character basically reverts the current cursor back to the 1st column in the current line. This concept should basically work on Mac, Linux and Windows. So to test it I wrote a quick hack and it worked properly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public class ProgressBar {\n\n    public static void main(String[] args) {\n        int size = 10;\n        for (int i=1; i&lt;size; i++) {\n            try {\n                Thread.<em>sleep<\/em>(500);\n                System.<em>out<\/em>.print(\"|\" + \"=\".repeat(i) + \">\" + \" \".repeat(size-i) + \"|\\r\");\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n        }\n        System.<em>out<\/em>.print(\"|\" + \"=\".repeat(size) + \"|\\r\");\n    }\n}\n\n\/\/ Initial Output\n\/\/ |=>        |\n\/\/ Final Output\n\/\/ |==========|<\/pre>\n\n\n\n<p>I got the desired output and a humble do nothing progress bar did come up on terminal. To further this idea I did some internet search and I ended up finding <a href=\"https:\/\/github.com\/ctongfei\/progressbar\">this repo<\/a> on GitHub. It basically allows you to implement beautiful progress bars for terminal based Java application. The basic concept is the same but it provides much more functionality. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Th e&#8221;\\r&#8221; character basically reverts the current cursor back to the 1st column in the current line. This concept should basically work on Mac, Linux and Windows. So to test it I wrote a quick hack and it worked properly: public class ProgressBar { public static void main(String[] args) { int size = 10; for [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"class_list":["post-703","post","type-post","status-publish","format-standard","hentry","category-java","category-programming"],"_links":{"self":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=703"}],"version-history":[{"count":1,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}