{"id":17680336,"url":"https://github.com/docelic/terminfo","last_synced_at":"2025-05-12T23:04:26.284Z","repository":{"id":66956538,"uuid":"222026908","full_name":"docelic/terminfo","owner":"docelic","description":"Library for parsing standard and extended terminfo files","archived":false,"fork":false,"pushed_at":"2020-12-14T00:17:54.000Z","size":210,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T15:54:04.882Z","etag":null,"topics":["console","crystal","crystal-lang","linux","terminal","terminfo","terminfo-data","terminfo-files"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/docelic.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-16T00:54:42.000Z","updated_at":"2024-06-14T12:04:36.000Z","dependencies_parsed_at":"2023-02-28T02:31:25.726Z","dependency_job_id":null,"html_url":"https://github.com/docelic/terminfo","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docelic%2Fterminfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docelic%2Fterminfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docelic%2Fterminfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docelic%2Fterminfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docelic","download_url":"https://codeload.github.com/docelic/terminfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243226313,"owners_count":20257060,"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":["console","crystal","crystal-lang","linux","terminal","terminfo","terminfo-data","terminfo-files"],"created_at":"2024-10-24T09:06:37.496Z","updated_at":"2025-03-12T13:32:09.979Z","avatar_url":"https://github.com/docelic.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/crystallabs/terminfo.svg?branch=master)](https://travis-ci.com/crystallabs/terminfo)\n[![Version](https://img.shields.io/github/tag/crystallabs/terminfo.svg?maxAge=360)](https://github.com/crystallabs/terminfo/releases/latest)\n[![License](https://img.shields.io/github/license/crystallabs/terminfo.svg)](https://github.com/crystallabs/terminfo/blob/master/LICENSE)\n\n# Terminfo\n\nTerminfo is a terminfo parsing library for Crystal.\n\nIt supports:\n\n1. Auto-detecting and searching for terminfo files\n1. Parsing terminfo files using regular and extended format\n1. Summarizing the content of terminfo files\n1. Providing raw access to parsed terminfo data\n1. Using internally stored terminfo data for most common terminals\n\nIt is implemented natively and does not depend on ncurses or other external library.\n\n## Installation\n\nAdd the dependency to `shard.yml`:\n\n```yaml\ndependencies:\n  terminfo:\n    github: crystallabs/terminfo\n    version: 0.8.1\n```\n\n## Usage in a nutshell\n\nHere is a basic example that parses a terminfo file, prints parsed headers, and accesses raw data.\n\n```crystal\nrequire \"terminfo\"\n\n# Using a module/mixin\nclass MyClass\n  include Terminfo\nend\nmy = MyClass.new # (No arguments provided will trigger term autodetection)\n\n# Using a class\nmy = Terminfo::Data.new path: \"/lib/terminfo/x/xterm\"\n\n# Using internal 'xterm' definition\nmy2 = Terminfo::Data.new builtin: \"xterm\"\n\np my.header.to_h\np my.extended_header.to_h\n\n# Print out a couple raw values. Use p() which inspects variables\n# instead of puts() which would output escape sequences to the terminal.\np my.booleans[\"auto_left_margin\"] # =\u003e false\np my.numbers[\"columns\"]           # =\u003e 80\np my.strings[\"back_tab\"]          # =\u003e \\e[Z\n```\n\n## Terminfo initialization\n\nTerminfo can read terminfo data from files on disk as well as from internal (compiled-in) storage.\nThere are a total of 4 ways to initialize:\n\n\n(1) For specific terminfo files, specify absolute or relative path:\n\n```crystal\ndata = Terminfo::Data.new path: \"/path/to/t/terminfo_file\"\n```\n\n(2) For lookup in default terminfo directories, specify term name:\n\n```crystal\ndata = Terminfo::Data.new term: \"xterm\"\n```\n\nThe default directory search order, from first to last:\n\n```crystal\nENV[\"TERMINFO_DIRS\"]/     # (List of directories split by \":\")\nENV[\"HOME\"]/.terminfo/\n/usr/share/terminfo/\n/usr/share/lib/terminfo/\n/usr/lib/terminfo/\n/usr/local/share/terminfo/\n/usr/local/share/lib/terminfo/\n/usr/local/lib/terminfo/\n/usr/local/ncurses/lib/terminfo/\n/lib/terminfo/\n```\n\nDirectory search order can be changed by modifying `Terminfo.directories`.\n\nA file is searched in each directory using the following attempts:\n\n```crystal\n./file\n./f/file\n./f/fi/file\n./66/file # 66 == hex(\"file\"[0].bytes)\n```\n\n(3) For lookup in the module's built-in storage, specify built-in name:\n\n```crystal\ndata = Terminfo::Data.new builtin: \"xterm\"\n```\n\nBuilt-in terminfo definitions can be changed by modifying the contents of the\ndirectory `filesystem/`. Currently available built-in terminfo files are:\n\n```crystal\nlinux\nwindows-ansi\nxterm\nxterm-256color\n```\n\n(4) For autodetection, call `initialize` with no arguments:\n\n```crystal\ndata = Terminfo::Data.new\n```\n\nIf environment variable `ENV[\"TERMINFO\"]` is set, term definition will\nbe read from the specified file.\n\nOtherwise, term name will be read from `ENV[\"TERM\"]` and the corresponding\nterminfo file will be searched in the above documented directories.\n\nIf `TERMINFO` and `TERM` are unset, a built-in default of \"xterm\" will be used.\n\n## Terminfo data\n\nOnce you have instantiated Terminfo in one of the ways shown above,\nthe following parsed properties and data structures will be available:\n\n```crystal\ndata = Terminfo::Data.new term: \"xterm\"\n\npp data\n\n#\u003cTerminfo::Data\n @name=\"xterm\",\n @names=[\"xterm-debian\"],\n @description=\"X11 terminal emulator\",\n\n @header=\n  #\u003cTerminfo::Header\n   @booleans_size=38,\n   @data_size=3360,\n   @header_size=12,\n   @magic_number=282,\n   @names_size=41,\n   @numbers_size=15,\n   @strings_size=413,\n   @strings_table_size=1397,\n   @total_size=2344\u003e,\n\n @extended_header=\n  #\u003cTerminfo::ExtendedHeader\n   @booleans_size=2,\n   @header_size=10,\n   @last_strings_table_offset=750,\n   @numbers_size=0,\n   @strings_size=62,\n   @strings_table_size=126,\n   @symbol_offsets_size=64,\n   @total_size=262\u003e,\n\n @booleans=\n  {\"auto_left_margin\" =\u003e false,\n  # ...\n  \"backspaces_with_bs\" =\u003e true},\n\n @numbers=\n  {\"columns\" =\u003e 80,\n  # ...\n  \"max_pairs\" =\u003e 64},\n\n @strings=\n  {\"back_tab\" =\u003e \"\\e[Z\",\n  # ...\n  \"memory_unlock\" =\u003e \"\\em\"}\u003e\n\n @extended_booleans=\n  {\"AX\" =\u003e true,\n  # ...\n  \"XT\" =\u003e true},\n\n @extended_numbers=\n  {\"some_name\" =\u003e 0,\n  # ...\n  },\n\n @extended_strings=\n  {\"Cr\" =\u003e \"\\e]112\\a\",\n  # ...\n  \"kc2\" =\u003e \"\"}\n```\n\n## API documentation\n\nRun `crystal docs` as usual, then open file `docs/index.html`.\n\nAlso, see examples in the directory `examples/`.\n\n## Testing\n\nRun `crystal spec` as usual.\n\nAlso, see examples in the directory `examples/`.\n\n## Thanks\n\n* All the fine folks on FreeNode IRC channel #crystal-lang and on Crystal's Gitter channel https://gitter.im/crystal-lang/crystal\n\n## Other projects\n\nList of interesting or related projects in no particular order:\n\n- https://github.com/crystallabs/tput - Low-level component for building term/console applications in Crystal\n- https://github.com/crystallabs/term_colors - Term/console color manipulation library for Crystal\n- https://github.com/bew/unibilium.cr - Unibilium bindings for crystal - A terminfo parsing library\n- https://github.com/bew/terminfo.cr - A Crystal library to parse terminfo database\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocelic%2Fterminfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocelic%2Fterminfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocelic%2Fterminfo/lists"}