{"id":20481164,"url":"https://github.com/inversion-des/paralines","last_synced_at":"2025-04-13T14:10:50.240Z","repository":{"id":56887416,"uuid":"452714054","full_name":"Inversion-des/paralines","owner":"Inversion-des","description":"Nice output to console/file from concurrent threads","archived":false,"fork":false,"pushed_at":"2022-01-28T18:21:58.000Z","size":45,"stargazers_count":46,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T12:37:28.584Z","etag":null,"topics":["concurrency","console","gem","output","ruby","threads"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inversion-des.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"inve","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-01-27T14:26:33.000Z","updated_at":"2025-04-02T17:18:45.000Z","dependencies_parsed_at":"2022-08-21T00:50:43.195Z","dependency_job_id":null,"html_url":"https://github.com/Inversion-des/paralines","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inversion-des%2Fparalines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inversion-des%2Fparalines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inversion-des%2Fparalines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inversion-des%2Fparalines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inversion-des","download_url":"https://codeload.github.com/Inversion-des/paralines/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724629,"owners_count":21151561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","console","gem","output","ruby","threads"],"created_at":"2024-11-15T16:07:05.242Z","updated_at":"2025-04-13T14:10:50.218Z","avatar_url":"https://github.com/Inversion-des.png","language":"Ruby","funding_links":["https://patreon.com/inve"],"categories":[],"sub_categories":[],"readme":"# ParaLines Ruby Gem [![version](https://badge.fury.io/rb/paralines.svg)](https://rubygems.org/gems/paralines)\n\nNice output to console/file from concurrent threads:\n\n![sample output](sample_output.gif)\n\n#### Features:\n- only 170 lines of code;\n- no dependencies;\n- works on Linux and Windows;\n- if output to file and the script crashes in the middle — it is handled with at_exit and in the file, you will find partial output not an empty file.\n\n## Installation\n\n    gem install paralines\n\nor in your Gemfile\n\n    gem 'paralines'\n\n## Sample with all the features (output is on the gif animation)\n\n```ruby\nrequire 'paralines'\n\nputs '- start -'\n\nParaLines.new do |plines|\n\n    odd_line = plines.add_shared_line 'Odd: '\n    even_line = plines.add_shared_line 'Even: '\n    done_order_line = plines.add_shared_line 'Done order: '\n\n    workers = (0..9).map do |n|\n        Thread.new do\n            if n == 0\n                # special case with sub-tasks in sub-threads\n                shared_line = plines.add_shared_line \"Worker_#{n}: \"\n                (1..3).map do |sn|\n                    Thread.new do\n                        sleep 0.01\n                        ticks_n = 5\n                        part = shared_line.part_open \"[subtask#{sn}…#{' '*(ticks_n-1)}] \"\n                        ticks_n.times do |n|\n                            sleep rand\n                            part.close '.' * (n+1)\n                        end\n                    end\n                end.each \u0026:join\n                next\n            else\n                sleep n\u003e5 ? 0.3 : 0.1  # make Worker_0 to be the first in the list\n            end\n            plines \u003c\u003c \"Worker_#{n}\"\n            start = Time.now\n            n.odd? \\\n                ? (odd_part = odd_line.part_open \"#{n}… \")\n                : (even_part = even_line.part_open \"[#{n} \")\n            2.times do\n                sleep rand\n                plines \u003c\u003c '.'\n                fail if rand \u003c 0.07 if !:with_fail_chanse   # remove ! here to test crashes\n            end\n            time = Time.now - start\n            plines \u003c\u003c \"done (in %.3fs)\" % time\n            done_order_line \u003c\u003c n\n            odd_part\u0026.close '+'\n            even_part\u0026.close ']'\n        end\n            .tap do\n                if n==5\n                    sleep 0.2\n                    plines.add_static_line '- 5 workers added'\n                elsif n==9\n                    sleep 0.4\n                    plines.add_static_line '- all workers added'\n                end\n            end\n    end.each \u0026:join\n\nend\n\nputs '- ready -'\n\n```\n\n### Usage without a block\n```ruby\nrequire 'paralines'\n\nplines = ParaLines.new\n\nplines.add_static_line 'Gems latest versions'\nplines.add_empty_line\n\ngems = %w[sinatra rspec paralines rails hanami]\n\nplines.add_static_line '- Random order:'\nthreads = gems.map do |name|\n    Thread.new do\n        plines \u003c\u003c name.ljust(15, '.')\n        res = `gem list -r #{name} -e`\n        plines \u003c\u003c 'v' + res[/\\((.+)\\)/, 1]\n    end\nend\nsleep 0.2\nplines.add_empty_line\nplines.add_static_line '- Sorted:'\nthreads += gems.sort.map do |name|\n    sline = plines.add_shared_line name.ljust(15, '.')\n    Thread.new do\n        res = `gem list -r #{name} -e`\n        sline \u003c\u003c 'v' + res[/\\((.+)\\)/, 1]\n    end\nend\n\nthreads.each \u0026:join\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub: https://github.com/Inversion-des/paralines\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversion-des%2Fparalines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finversion-des%2Fparalines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversion-des%2Fparalines/lists"}