{"id":13465446,"url":"https://github.com/andybest/linenoise-swift","last_synced_at":"2025-10-21T10:54:50.111Z","repository":{"id":39042467,"uuid":"94822141","full_name":"andybest/linenoise-swift","owner":"andybest","description":"A pure Swift replacement for readline","archived":false,"fork":false,"pushed_at":"2023-01-20T11:06:34.000Z","size":66,"stargazers_count":151,"open_issues_count":5,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-21T10:54:25.756Z","etag":null,"topics":["console","library","linenoise","pure-swift","swift","terminal"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andybest.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":"2017-06-19T21:23:14.000Z","updated_at":"2025-08-08T14:45:06.000Z","dependencies_parsed_at":"2023-02-12T01:45:49.210Z","dependency_job_id":null,"html_url":"https://github.com/andybest/linenoise-swift","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/andybest/linenoise-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andybest%2Flinenoise-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andybest%2Flinenoise-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andybest%2Flinenoise-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andybest%2Flinenoise-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andybest","download_url":"https://codeload.github.com/andybest/linenoise-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andybest%2Flinenoise-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280248570,"owners_count":26297925,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","library","linenoise","pure-swift","swift","terminal"],"created_at":"2024-07-31T15:00:30.017Z","updated_at":"2025-10-21T10:54:50.081Z","avatar_url":"https://github.com/andybest.png","language":"Swift","funding_links":[],"categories":["Libs","Command Line","Command Line [🔝](#readme)","Swift","CLI and Server","Recently Updated"],"sub_categories":["Command Line","Linter","[Feb 05, 2025](/content/2025/02/05/README.md)"],"readme":"# Linenoise-Swift\n\nA pure Swift implementation of the [Linenoise](http://github.com/antirez/linenoise) library. A minimal, zero-config readline replacement.\n\n### Supports\n* Mac OS and Linux\n* Line editing with emacs keybindings\n* History handling\n* Completion\n* Hints\n\n### Pure Swift\nImplemented in pure Swift, with a Swifty API, this library is easy to embed in projects using Swift Package Manager, and requires no additional dependencies.\n\n## Contents\n- [API](#api)\n  * [Quick Start](#quick-start)\n  * [Basics](#basics)\n  * [History](#history)\n    + [Adding to History](#adding-to-history)\n    + [Limit the Number of Items in History](#limit-the-number-of-items-in-history)\n    + [Saving the History to a File](#saving-the-history-to-a-file)\n    + [Loading History From a File](#loading-history-from-a-file)\n    + [History Editing Behavior](#history-editing-behavior)\n  * [Completion](#completion)\n  * [Hints](#hints)\n- [Acknowledgements](#acknowledgements)\n\n# API\n\n## Quick Start\nLinenoise-Swift is easy to use, and can be used as a replacement for [`Swift.readLine`](https://developer.apple.com/documentation/swift/1641199-readline). Here is a simple example:\n\n```swift\nlet ln = LineNoise()\n\ndo {\n\tlet input = try ln.getLine(prompt: \"\u003e \")\n} catch {\n\tprint(error)\n}\n\t\n```\n\n## Basics\nSimply creating a new `LineNoise` object is all that is necessary in most cases, with STDIN used for input and STDOUT used for output by default. However, it is possible to supply different files for input and output if you wish:\n\n```swift\n// 'in' and 'out' are standard POSIX file handles\nlet ln = LineNoise(inputFile: in, outputFile: out)\n```\n\n## History\n### Adding to History\nAdding to the history is easy:\n\n```swift\nlet ln = LineNoise()\n\ndo {\n\tlet input = try ln.getLine(prompt: \"\u003e \")\n\tln.addHistory(input)\n} catch {\n\tprint(error)\n}\n```\n\n### Limit the Number of Items in History\nYou can optionally set the maximum amount of items to keep in history. Setting this to `0` (the default) will keep an unlimited amount of items in history.\n```swift\nln.setHistoryMaxLength(100)\n```\n\n### Saving the History to a File\n```swift\nln.saveHistory(toFile: \"/tmp/history.txt\")\n```\n\n### Loading History From a File\nThis will add all of the items from the file to the current history\n```swift\nln.loadHistory(fromFile: \"/tmp/history.txt\")\n```\n\n### History Editing Behavior\nBy default, any edits by the user to a line in the history will be discarded if the user moves forward or back in the history without pressing Enter.  If you prefer to have all edits preserved, then use the following:\n```swift\nln.preserveHistoryEdits = true\n```\n\n## Completion\n![Completion example](https://github.com/andybest/linenoise-swift/raw/master/images/completion.gif)\n\nLinenoise supports completion with `tab`. You can provide a callback to return an array of possible completions:\n\n```swift\nlet ln = LineNoise()\n\nln.setCompletionCallback { currentBuffer in\n    let completions = [\n        \"Hello, world!\",\n        \"Hello, Linenoise!\",\n        \"Swift is Awesome!\"\n    ]\n    \n    return completions.filter { $0.hasPrefix(currentBuffer) }\n}\n```\n\nThe completion callback gives you whatever has been typed before `tab` is pressed. Simply return an array of Strings for possible completions. These can be cycled through by pressing `tab` multiple times.\n\n## Hints\n![Hints example](https://github.com/andybest/linenoise-swift/raw/master/images/hints.gif)\n\nLinenoise supports providing hints as you type. These will appear to the right of the current input, and can be selected by pressing `Return`.\n\nThe hints callback has the contents of the current line as input, and returns a tuple consisting of an optional hint string and an optional color for the hint text, e.g.:\n\n```swift\nlet ln = LineNoise()\n\nln.setHintsCallback { currentBuffer in\n    let hints = [\n        \"Carpe Diem\",\n        \"Lorem Ipsum\",\n        \"Swift is Awesome!\"\n    ]\n    \n    let filtered = hints.filter { $0.hasPrefix(currentBuffer) }\n    \n    if let hint = filtered.first {\n        // Make sure you return only the missing part of the hint\n        let hintText = String(hint.dropFirst(currentBuffer.count))\n        \n        // (R, G, B)\n        let color = (127, 0, 127)\n        \n        return (hintText, color)\n    } else {\n        return (nil, nil)\n    }\n}\n\n```\n\n# Acknowledgements\nLinenoise-Swift is heavily based on the [original linenoise library](http://github.com/antirez/linenoise) by [Salvatore Sanfilippo (antirez)](http://github.com/antirez)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandybest%2Flinenoise-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandybest%2Flinenoise-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandybest%2Flinenoise-swift/lists"}