getting-started.mdx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ---
  2. title: Getting started
  3. description: Install OpenTUI and create your first terminal UI
  4. order: 1
  5. navTitle: Introduction
  6. skill:
  7. entry: true
  8. intents: [getting-started, installation, quickstart, intro]
  9. ---
  10. # Getting started
  11. OpenTUI is a native terminal UI core written in Zig with TypeScript bindings. The native core exposes a C ABI and can be used from any language. OpenTUI powers OpenCode in production today and will also power terminal.shop. It is an extensible core with a focus on correctness, stability, and high performance. It provides a component-based architecture with flexible layout capabilities, allowing you to create complex terminal applications.
  12. ## Installation
  13. OpenTUI is currently [Bun](https://bun.sh) exclusive but Deno and Node support in-progress.
  14. ```bash
  15. mkdir my-tui && cd my-tui
  16. bun init -y
  17. bun add @opentui/core
  18. ```
  19. ## Hello world
  20. Create `index.ts`:
  21. ```typescript
  22. import { createCliRenderer, Text } from "@opentui/core"
  23. const renderer = await createCliRenderer({
  24. exitOnCtrlC: true,
  25. })
  26. renderer.root.add(
  27. Text({
  28. content: "Hello, OpenTUI!",
  29. fg: "#00FF00",
  30. }),
  31. )
  32. ```
  33. Run it:
  34. ```bash
  35. bun index.ts
  36. ```
  37. You should see green text. Press `Ctrl+C` to exit.
  38. ## Composing components
  39. Components nest naturally. Here's a bordered panel with content:
  40. ```typescript
  41. import { createCliRenderer, Box, Text } from "@opentui/core"
  42. const renderer = await createCliRenderer({
  43. exitOnCtrlC: true,
  44. })
  45. renderer.root.add(
  46. Box(
  47. { borderStyle: "rounded", padding: 1, flexDirection: "column", gap: 1 },
  48. Text({ content: "Welcome", fg: "#FFFF00" }),
  49. Text({ content: "Press Ctrl+C to exit" }),
  50. ),
  51. )
  52. ```
  53. `Box` and `Text` are factory functions. The first argument is props; additional arguments are children.
  54. ## What's next
  55. ### Core concepts
  56. - [Renderer](/docs/core-concepts/renderer) - The rendering engine
  57. - [Layout](/docs/core-concepts/layout) - Flexbox positioning
  58. - [Constructs](/docs/core-concepts/constructs) - The declarative component API
  59. ### Components
  60. - [Text](/docs/components/text), [Box](/docs/components/box) - Display and layout
  61. - [Input](/docs/components/input), [Select](/docs/components/select) - User interaction
  62. ### Framework bindings
  63. - [React](/docs/bindings/react)
  64. - [Solid.js](/docs/bindings/solid)