{"id":15646459,"url":"https://github.com/martinheidegger/simple-terminal-menu","last_synced_at":"2025-07-02T20:07:03.618Z","repository":{"id":30336292,"uuid":"33888654","full_name":"martinheidegger/simple-terminal-menu","owner":"martinheidegger","description":"A menu that is easier to use on the terminal than terminal-menu","archived":false,"fork":false,"pushed_at":"2020-08-21T07:24:12.000Z","size":26,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-02T20:06:54.540Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/martinheidegger.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","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":"2015-04-13T19:19:41.000Z","updated_at":"2023-01-26T17:26:02.000Z","dependencies_parsed_at":"2022-07-31T08:48:06.436Z","dependency_job_id":null,"html_url":"https://github.com/martinheidegger/simple-terminal-menu","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/martinheidegger/simple-terminal-menu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fsimple-terminal-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fsimple-terminal-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fsimple-terminal-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fsimple-terminal-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinheidegger","download_url":"https://codeload.github.com/martinheidegger/simple-terminal-menu/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fsimple-terminal-menu/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263208051,"owners_count":23430675,"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-10-03T12:12:59.458Z","updated_at":"2025-07-02T20:07:03.593Z","avatar_url":"https://github.com/martinheidegger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-terminal-menu\n\n[`terminal-menu`](https://github.com/substack/terminal-menu) does a good job for starting a menu but it is a bit tedious to set-up reliably for process.stdin / process.stdout and also for the use with double width characters.\n\nFor simply taking charge of the power this terminal menu offers a few things:\n\n## Automatically connects to process.stdin/stdout\nYou don't have to do that, it will just work :)\n\nYou can manually trigger start if you like using the `.autoStart: false` option and start it by hand:\n\n```javascript\nconst menu = new TerminalMenu({\n  autoStart: false\n})\n// Then start it manually\nmenu.start(process) // Optionally you can pass in a custom process here for testing.\n```\n\n## Markers\n`.add` gets an new signature\n\n```JavaScript\nconst label = 'hello' // will be aligned left\nconst marker = '(tm)' // (optional) will be aligned right\nconst handler = (label, marker) =\u003e {\n  // (optional) will be called in case the item is chosen\n}\nmenu.add(label, marker, handler)\n```\n\nWith this you can add entries that have a right-aligned marker text shown.\n\n## Menu Items\nYou can also use `.addItem` to use objects to add menu items.\n\n```JavaScript\nmenu.addItem({\n  label: 'hello', // will be aligned left\n  marker: '(tm)', // (optional) will be aligned right\n  handler: (label, index, item) =\u003e {\n    // (optional) will be called in case the item is chosen\n  }\n})\n```\n\n## Separators\nJust use ```.writeSeparator()``` to create a separator line.\n\n## Automatic truncating of entries\nIf an entry exceeds the width of the menu it will be truncated with `opts.truncator` or `...`\n\n## Writing of text\nSimilar like `.add` it supports `.writeLine` that allows you to write a text that is both left \u0026 right aligned.\n\n```JavaScript\n.writeLine(\u003cleft\u003e[, \u003cright\u003e])\n```\n\n## tty Tests\nIf the terminal doesn't support TTY `new TerminalMenu` will just `null`!\n\n```js\nconst TerminalMenu = require('simple-terminal-menu')\nconst menu = new TerminalMenu()\nif (menu === null) {\n  console.log('interactive menu not supported')\n  process.exit(1)\n}\n```\n\n## Comfort functions\nTo write a nice title and subtitle the comfort functions `.writeTitle` and `.writeSubtitle` exist.\n\n## Factory\nIf you have several menus that need to look alike, you can use the factory. It is available via `require('simple-terminal-menu/factory')`.\n\n\n# Installation \u0026 Usage\nInstall it using npm\n\n```\nnpm install simple-terminal-menu --save\n```\n\nAnd then create a menu it in your code using\n\n```JavaScript\nconst TerminalMenu = require('../simple-terminal-menu')\n\nfunction showSelection(label, index, item) {\n  console.log(\"label: \" + label + \"; marker: \" + item.marker + \";\")\n}\n\nfunction mainMenu() {\n  const menu = new TerminalMenu({ // settings passed through to terminal-menu\n    width: 80,   // menu width in columns\n    x: 1,        // top-left corner x offset, default: 1\n    y: 1,        // top-left corner y offset, default: 1\n    fg: 'white', // foreground color, default: 'white'\n    bg: 'blue',  // background color, default: 'blue'\n    padding: {\n      left: 0    // left padding in columns\n      right: 0   // right padding in columns\n      top: 0     // top padding in rows\n      bottom: 0  // bottom padding in rows\n    },\n    selected: 0  // set the selected element by its index\n  })\n\n  if (menu === null) {\n    // In case the terminal is not interactive the result is null\n    console.log('terminal is not interactive')\n    return\n  }\n  menu.writeLine(\"My Menu\", \"(tm)\")\n  menu.writeSeparator()\n  menu.add(\"A\", \"[selected]\", showSelection)\n  menu.add(\"B\", showSelection)\n  menu.writeSeparator()\n  menu.add(\"open submenu\", subMenu)\n  menu.add(\"exit\", menu.close)\n}\n\nfunction subMenu() {\n  const menu = new TerminalMenu()\n  menu.writeLine(\"SubMenu\")\n  menu.writeSeparator()\n  menu.add(\"C\", \"[selected]\", showSelection)\n  menu.add(\"D\", showSelection)\n  menu.writeSeparator()\n  menu.add(\"cancel\", mainMenu)\n  menu.add(\"niceTitle\", nicelyTitledMenu)\n  menu.add(\"exit\", menu.close)\n}\n\nfunction nicelyTitledMenu() {\n  const menu = new TerminalMenu();\n  menu.writeTitle(\"Awesome window\")\n  menu.writeSubtitle(\"A little more colorful\")\n  menu.writeSeparator()\n  menu.add(\"cancel\", subMenu)\n  menu.add(\"factoryA\", factoryMenuA)\n  menu.add(\"exit\", menu.close)\n}\n\n\n// Options for the menu when created through the factory\nvar factoryMenuOptions = {} // Can be empty! the factory uses some sensible defaults!\n\n// Defaults for creating menu with the factory\nvar defaultFactoryOptions = {\n  title: \"Factory Title\",\n  // you could also specify `subtitle:`, menu \u0026 extras are not available.\n}\nvar factory = require('simple-terminal-menu/factory')(factoryMenuOptions, defaultFactoryOptions);\n\nfunction factoryMenuA() {\n  factory.create({\n    subtitle: \"factory-a\",\n    before: (menu) =\u003e {\n      // Do anything you like before menu/extras are added\n    }\n    menu: [{\n      label: \"E\",\n      handler: showSelection\n    }, {\n      label: \"F\",\n      handler: showSelection\n    }],\n    extras: [{\n        label: \"factoryB\",\n        handler: factoryMenuB\n      },{\n        label: \"cancel\",\n        handler: nicelyTitledMenu\n      }],\n    after: (menu) =\u003e {\n      // Do anything you like after menu/extras are added\n    }\n  })\n}\n\nfunction factoryMenuB() {\n  factory.create({\n    subtitle: \"factory-b\",\n    menu: [{\n        label: \"G\",\n        handler: showSelection\n      }],\n    extras: [{\n        label: \"factoryA\",\n        handler: factoryMenuA\n      },{\n        label: \"cancel\",\n        handler: nicelyTitledMenu\n      }]\n  });\n}\n\n\nmainMenu()\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fsimple-terminal-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinheidegger%2Fsimple-terminal-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fsimple-terminal-menu/lists"}