{"id":13729287,"url":"https://github.com/KoharaKazuya/forest","last_synced_at":"2025-05-08T01:32:12.641Z","repository":{"id":146799542,"uuid":"98030106","full_name":"KoharaKazuya/forest","owner":"KoharaKazuya","description":"forest は行指向で構造化された木構造を表すテキストを整形して出力するコマンド","archived":false,"fork":false,"pushed_at":"2017-07-23T11:46:01.000Z","size":11,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-04T02:08:34.919Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/KoharaKazuya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-07-22T12:32:35.000Z","updated_at":"2022-10-03T14:25:13.000Z","dependencies_parsed_at":"2023-04-07T07:46:29.556Z","dependency_job_id":null,"html_url":"https://github.com/KoharaKazuya/forest","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoharaKazuya%2Fforest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoharaKazuya%2Fforest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoharaKazuya%2Fforest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoharaKazuya%2Fforest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KoharaKazuya","download_url":"https://codeload.github.com/KoharaKazuya/forest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224688954,"owners_count":17353292,"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":[],"created_at":"2024-08-03T02:00:57.936Z","updated_at":"2024-11-14T20:30:41.281Z","avatar_url":"https://github.com/KoharaKazuya.png","language":"Rust","funding_links":[],"categories":["Text Editing"],"sub_categories":["Open USP Tsukubai"],"readme":"# forest\n\n[![Build Status](https://travis-ci.org/KoharaKazuya/forest.svg?branch=master)](https://travis-ci.org/KoharaKazuya/forest)\n\nforest は行指向で構造化された木構造を表すテキストを整形して出力するコマンド。\n\n\n## 例\n\n(sample1.txt)\n\n```\npattern1_root\npattern1_root/pattern2_last_leaf\nroot_node\nroot_node/pattern3_non-last_leaf\nroot_node/pattern3_non-last_leaf/sample\nroot_node/pattern3_non-last_leaf/pattern4_non-last_node's_child\nroot_node/leaf_node\n```\n\n```console\n$ cat sample1.txt | forest\n├ ─ pattern1_root\n│   └ ─ /pattern2_last_leaf\n└ ─ root_node\n    ├ ─ /pattern3_non-last_leaf\n    │   ├ ─ /sample\n    │   └ ─ /pattern4_non-last_node's_child\n    └ ─ /leaf_node\n```\n\n(sample2.txt)\n\n```\nサ\nサン\nサンプル\nforest\nforest doesn't specify any characters\nforest doesn't specify any characters as separater.\n```\n\n```console\n$ cat sample2.txt | forest\n├ ─ サ\n│   └ ─ ン\n│       └ ─ プル\n└ ─ forest\n    └ ─  doesn't specify any characters\n        └ ─  as separator.\n```\n\n\n## ダウンロード\n\n\u003chttps://github.com/KoharaKazuya/forest/releases\u003e\n\n\n## forest がなぜ必要か\n\n考えられる用途としては tree コマンドや ps --forest オプションで十分だが、単機能として分離しておくと柔軟に組み合わせられるため。\n\nfind コマンドの柔軟な検索結果を forest で整形表示するなど。\n\n\n## アルゴリズム\n\nアルゴリズムを擬似コードで示す。\n\n```\n入力: テキスト input\n出力: テキスト output\n\nentries ← 空キュー\n\n// 木構造構築フェーズ\nancestors ← 空スタック\nprev ← null\nwhile line ← input の先頭行\n  while ancestor ← ancestors.pop()\n    if line が ancestor.value から始まる\n      ancestors.push(ancestor)\n      break\n    if prev != null\n      prev.shape ← CLOSE\n    prev ← ancestor\n  entry ← (depth: ancestors の長さ + 1, shape: Pending, value: line)\n  if prev != null\n    prev.shape ← OPEN\n  ancestors.push(entry)\n  entries.enqueue(entry)\nwhile ancestor ← ancestors.pop()\n  ancestor.shape ← CLOSE\n\n// 木構造出力フェーズ\nancestor_shapes ← 空リスト\nwhile entry ← entries.dequeue()\n  ancestor_shapes ← ancestor_shapes の先頭 (entry.depth - 1) 要素\n  shape for each ancestor_shapes\n    if shape = OPEN\n      ANCESTOR_GUIDE_OPEN を output 出力\n    else if shape = CLOSE\n      ANCESTOR_GUIDE_CLOSE を output 出力\n  if entry.shape = OPEN\n    NAME_GUIDE_OPEN を output に出力\n  else if entry.shape = CLOSE\n    NAME_GUIDE_CLOSE を output に出力\n  entry.value を output 出力\n  ancestor_shapes の末尾に entry.shape を追加\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKoharaKazuya%2Fforest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKoharaKazuya%2Fforest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKoharaKazuya%2Fforest/lists"}