{"id":13413943,"url":"https://github.com/isbm/textwrap","last_synced_at":"2025-04-10T03:14:27.495Z","repository":{"id":57496118,"uuid":"199059598","full_name":"isbm/textwrap","owner":"isbm","description":"Port of Python's \"textwrap\" module to Go","archived":false,"fork":false,"pushed_at":"2019-08-03T19:01:29.000Z","size":26,"stargazers_count":5,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T03:14:12.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/isbm.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}},"created_at":"2019-07-26T17:57:55.000Z","updated_at":"2023-08-21T08:56:49.000Z","dependencies_parsed_at":"2022-09-02T20:50:33.457Z","dependency_job_id":null,"html_url":"https://github.com/isbm/textwrap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isbm%2Ftextwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isbm%2Ftextwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isbm%2Ftextwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isbm%2Ftextwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isbm","download_url":"https://codeload.github.com/isbm/textwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148242,"owners_count":21055548,"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-07-30T20:01:53.307Z","updated_at":"2025-04-10T03:14:27.477Z","avatar_url":"https://github.com/isbm.png","language":"Go","readme":"# Text Wrap\n\nThis is a port of Python's \"textwrap\" module for Go. Well, sort of...\n\n# Limitations\n\nThis modules (at least for now) is not wrapping on whitespaces and\nright after hyphens in compound words, as it is customary in\nEnglish. That said, `break_on_hyphens` and `break_long_words` are not\nyet supported.\n\nAlso `fix_sentence_endings` is not supported as well for now, which\ndoesn't work reliably in Python anyways (since it requires two spaces\nand other conditions nobody cares of).\n\nThe implementation for hyphens support is planned however, while\n`fix_sentence_endings` is not (but! your PRs are welcome and free to\nimplement it).\n\n# Usage\n\nThe usage is quite similar as in Python:\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/isbm/textwrap\"\n)\n\n...\n\ntext := \"Your very long text here\"\nwrapper := textwrap.NewTextWrap() // Defaults to 70\nfmt.Println(wrapper.Fill(text))      // Returns string\n\n// Get each line\nfor idx, line := range wrapper.Wrap(text) {\n\tfmt.Println(idx, line)\n}\n\n```\n\nDe-dent is also implemented and works exactly the same as in Python:\n\n```go\nmultilineText := `\n    There is some multiline text\n  with different identation\n      everywhere. So it will be\n    aligned to the minimal.\n`\n\n// This will remove two leading spaces from each line\nfmt.Println(wrapper.Dedent(multilineText))\n\n```\n\n\n# Configuration\n\nYou can setup wrapper object constructor the following way (given values are its\ndefaults, so you can change it to whatever you want):\n\n```go\nwrapper := textwrap.NewTextWrap().\n\tSetNewLine(\"\\n\").\n\tSetWidth(70),\n\tSetTabSpacesWidth(4).\n\tSetDropWhitespace(true).\n\tSetInitialIndent(\"\").\n\tSetReplaceWhitespace(true)\n```\n\nHave fun.\n\n# Bonus Functions\n\nWhile it is possible to do it differently, this module also gives you\nstring whitespace trimming for _only_ leading whitespace (`TrimLeft`) or _only_\ntrailing (`TrimRight`), as contrary to `strings.TrimSpace` that trims\neverything.\n\nThe whitespace is the same as defined in Python's `strings.whitespace`.\n\n","funding_links":[],"categories":["Text Processing","Bot Building","文本处理","文本处理`解析和操作文本的代码库`","Utility","Template Engines"],"sub_categories":["Formatters","格式器","查询语","HTTP Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisbm%2Ftextwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisbm%2Ftextwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisbm%2Ftextwrap/lists"}