{"id":13401073,"url":"https://github.com/Yomguithereal/react-blessed","last_synced_at":"2025-03-14T06:32:08.287Z","repository":{"id":35249362,"uuid":"39509091","full_name":"Yomguithereal/react-blessed","owner":"Yomguithereal","description":"A react renderer for blessed.","archived":false,"fork":false,"pushed_at":"2021-05-06T19:44:11.000Z","size":2217,"stargazers_count":4453,"open_issues_count":39,"forks_count":176,"subscribers_count":59,"default_branch":"master","last_synced_at":"2024-10-29T14:57:03.198Z","etag":null,"topics":["blessed","cli","react","renderer"],"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/Yomguithereal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"Yomguithereal"}},"created_at":"2015-07-22T13:55:44.000Z","updated_at":"2024-10-28T05:32:04.000Z","dependencies_parsed_at":"2022-08-08T07:00:33.602Z","dependency_job_id":null,"html_url":"https://github.com/Yomguithereal/react-blessed","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomguithereal%2Freact-blessed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomguithereal%2Freact-blessed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomguithereal%2Freact-blessed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomguithereal%2Freact-blessed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yomguithereal","download_url":"https://codeload.github.com/Yomguithereal/react-blessed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243381163,"owners_count":20281906,"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":["blessed","cli","react","renderer"],"created_at":"2024-07-30T19:00:58.408Z","updated_at":"2025-03-14T06:32:08.280Z","avatar_url":"https://github.com/Yomguithereal.png","language":"JavaScript","funding_links":["https://github.com/sponsors/Yomguithereal"],"categories":["Miscellaneous","Uncategorized","JavaScript","Command Line Interface","React","React [🔝](#readme)","Libraries"],"sub_categories":["Miscellaneous","Uncategorized","React Components"],"readme":"# react-blessed\n\nA [React](https://facebook.github.io/react/) custom renderer for the [blessed](https://github.com/chjj/blessed) library.\n\nThis renderer should currently be considered as experimental, is subject to change and will only work with React's latest version (`17.x.x`, using Fiber).\n\n![demo](https://raw.githubusercontent.com/Yomguithereal/react-blessed/master/img/demo.gif)\n\n## Summary\n\n* [Installation](#installation)\n* [Demo](#demo)\n* [Usage](#usage)\n  * [Rendering a basic application](#rendering-a-basic-application)\n  * [Nodes \u0026 text nodes](#nodes--text-nodes)\n  * [Refs](#refs)\n  * [Events](#events)\n  * [Classes](#classes)\n  * [Using blessed forks](#using-blessed-forks)\n  * [Using the devtools](#using-the-devtools)\n* [Roadmap](#roadmap)\n* [FAQ](#faq)\n* [Contribution](#contribution)\n* [License](#license)\n\n## Installation\n\nYou can install `react-blessed` through npm:\n\n```bash\n# Be sure to install react\u003e=17.0.0 \u0026 blessed\u003e=0.1.81 before\nnpm install blessed react\n\n# Then just install `react-blessed`\nnpm install react-blessed\n```\n\n## Demo\n\nFor a quick demo of what you could achieve with such a renderer you can clone this repository and check some of the [examples](./examples):\n\n```bash\ngit clone https://github.com/Yomguithereal/react-blessed\ncd react-blessed\nnpm install\n\n# To see which examples you can run:\nnpm run demo\n\n# Then choose one to run:\nnpm run demo animation\n```\n\n## Usage\n\n### Rendering a basic application\n\n```jsx\nimport React, {Component} from 'react';\nimport blessed from 'blessed';\nimport {render} from 'react-blessed';\n\n// Rendering a simple centered box\nclass App extends Component {\n  render() {\n    return (\n      \u003cbox top=\"center\"\n           left=\"center\"\n           width=\"50%\"\n           height=\"50%\"\n           border={{type: 'line'}}\n           style={{border: {fg: 'blue'}}}\u003e\n        Hello World!\n      \u003c/box\u003e\n    );\n  }\n}\n\n// Creating our screen\nconst screen = blessed.screen({\n  autoPadding: true,\n  smartCSR: true,\n  title: 'react-blessed hello world'\n});\n\n// Adding a way to quit the program\nscreen.key(['escape', 'q', 'C-c'], function(ch, key) {\n  return process.exit(0);\n});\n\n// Rendering the React app using our screen\nconst component = render(\u003cApp /\u003e, screen);\n```\n\n### Nodes \u0026 text nodes\n\nAny of the blessed [widgets](https://github.com/chjj/blessed#widgets) can be rendered through `react-blessed` by using a lowercased tag title.\n\nText nodes, on the other hand, will be rendered by applying the `setContent` method with the given text on the parent node.\n\n### Refs\n\nAs with React's DOM renderer, `react-blessed` lets you handle the original blessed nodes, if you ever need them, through refs.\n\n```jsx\nclass CustomList extends Component {\n  componentDidMount() {\n\n    // Focus on the first box\n    this.refs.first.focus();\n  }\n\n  render() {\n    return (\n      \u003celement\u003e\n        \u003cbox ref=\"first\"\u003e\n          First box.\n        \u003c/box\u003e\n        \u003cbox ref=\"second\"\u003e\n          Second box.\n        \u003c/box\u003e\n      \u003c/element\u003e\n    );\n  }\n}\n```\n\n### Events\n\nAny blessed node event can be caught through a `on`-prefixed listener:\n\n```jsx\nclass Completion extends Component {\n  constructor(props) {\n    super(props);\n\n    this.state = {progress: 0, color: 'blue'};\n\n    const interval = setInterval(() =\u003e {\n      if (this.state.progress \u003e= 100)\n        return clearInterval(interval);\n\n      this.setState({progress: this.state.progress + 1});\n    }, 50);\n  }\n\n  render() {\n    const {progress} = this.state,\n          label = `Progress - ${progress}%`;\n\n    // See the `onComplete` prop\n    return \u003cprogressbar label={label}\n                        onComplete={() =\u003e this.setState({color: 'green'})}\n                        filled={progress}\n                        style={{bar: {bg: this.state.color}}} /\u003e;\n  }\n}\n```\n\n### Classes\n\nFor convenience, `react-blessed` lets you handle classes looking like what [react-native](https://facebook.github.io/react-native/docs/style.html#content) proposes.\n\nJust pass object or an array of objects as the class of your components likewise:\n\n```jsx\n// Let's say we want all our elements to have a fancy blue border\nconst stylesheet = {\n  bordered: {\n    border: {\n      type: 'line'\n    },\n    style: {\n      border: {\n        fg: 'blue'\n      }\n    }\n  }\n};\n\nclass App extends Component {\n  render() {\n    return (\n      \u003celement\u003e\n        \u003cbox class={stylesheet.bordered}\u003e\n          First box.\n        \u003c/box\u003e\n        \u003cbox class={stylesheet.bordered}\u003e\n          Second box.\n        \u003c/box\u003e\n      \u003c/element\u003e\n    );\n  }\n}\n```\n\nYou can of course combine classes (note that the given array of classes will be compacted):\n```jsx\n// Let's say we want all our elements to have a fancy blue border\nconst stylesheet = {\n  bordered: {\n    border: {\n      type: 'line'\n    },\n    style: {\n      border: {\n        fg: 'blue'\n      }\n    }\n  },\n  magentaBackground: {\n    style: {\n      bg: 'magenta'\n    }\n  }\n};\n\nclass App extends Component {\n  render() {\n\n    // If this flag is false, then the class won't apply to the second box\n    const backgroundForSecondBox = this.props.backgroundForSecondBox;\n\n    return (\n      \u003celement\u003e\n        \u003cbox class={[stylesheet.bordered, stylesheet.magentaBackground]}\u003e\n          First box.\n        \u003c/box\u003e\n        \u003cbox class={[\n          stylesheet.bordered,\n          backgroundForSecondBox \u0026\u0026 stylesheet.magentaBackground\n        ]}\u003e\n          Second box.\n        \u003c/box\u003e\n      \u003c/element\u003e\n    );\n  }\n}\n```\n\n### Using blessed forks\n\nBecause [blessed](https://github.com/chjj/blessed) is not actively maintained in quite a while, you might want to use one of it's forks. To do that, import `createBlessedRenderer` function instead:\n\n```\nimport React, {Component} from 'react';\nimport blessed from 'neo-blessed';\nimport {createBlessedRenderer} from 'react-blessed';\n\nconst render = createBlessedRenderer(blessed);\n```\n\n### Using the devtools\n\n`react-blessed` can be used along with React's own devtools for convenience. To do so, just install [`react-devtools`](https://www.npmjs.com/package/react-devtools) in your project and all should work out of the box when running the Electron app, as soon as a `react-blessed` program is running on one of your shells.\n\n## Roadmap\n\n* Full support (meaning every tags and options should be handled by the renderer).\n* `react-blessed-contrib` to add some sugar over the [blessed-contrib](https://github.com/yaronn/blessed-contrib) library (probably through full-fledged components).\n\n## Faq\n\n * `\u003clist/\u003e` : To enable interactions, add `mouse={ true }` and/or `keys={ true }`\n\n## Contribution\n\nContributions are obviously welcome.\n\nBe sure to add unit tests if relevant and pass them all before submitting your pull request.\n\n```bash\n# Installing the dev environment\ngit clone git@github.com:Yomguithereal/react-blessed.git\ncd react-blessed\nnpm install\n\n# Running the tests\nnpm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYomguithereal%2Freact-blessed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYomguithereal%2Freact-blessed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYomguithereal%2Freact-blessed/lists"}