nsh README

项目的 README,来自 github.com/longbridge/nsh。合并为一个 markdown 文件:README.md。

Native Shell (NSH)

Build once, native everywhere. Native Shell is a native UI framework for iOS, Android, macOS, Windows, Linux and the web, built in Rust. It unifies components, state, logic and API, with app-owned visual design and platform rendering: native views on iOS, Android, macOS, Windows and Linux, HTML on the web, GPUI in GPUI apps, character Cells in a terminal, with the platform's own text, input and interaction (a menu is a popup on the desktop and a sheet on a phone). Write the whole app in Rust, its screens in TSX, or combine both with shared Rust components.

image

Package it as a standalone app on every platform, or embed it in an existing one. On the same engine, apps load TSX modules at run time — plugins, features, UI generated by AI — delivered as signed packages and run in a sandbox the host configures.

Documentation, guides and live demos: nsh.dev.

Goals

Native views and interaction, with an app-owned design: NSH shares components, state and APIs across platforms, while the app controls colors, typography, spacing, shapes and motion. nsh/base provides the behavior and accessible structure of common controls such as Button, Checkbox and Switch; apps and community libraries give them a look. Platform modules expose capabilities specific to their platforms, such as the mobile system tab bar.

Read Goals and design principles for the component boundaries and how these goals guide Rust apps, TSX modules and AI-generated UI.

Features

Platforms

Platform Drawn with Embed with Requires
iOS UIKit, CoreText NshAppView (Swift, NativeShell.xcframework) iOS 15+
Android Android views, StaticLayout NshView (Java / Kotlin, nsh.aar) Android 8 (API 26)+
macOS AppKit, Core Animation, CoreText AppView (Rust, nsh-platform-macos) macOS 14+
Windows Win32, Direct2D, DirectWrite AppView (Rust, nsh-platform-windows) Windows 10 1809+
Linux GTK 4, Pango AppView (Rust, nsh-platform-linux) GTK 4.14+
GPUI (macOS, Windows, Linux) GPUI (GPUI Fast) AppView (Rust, a GPUI view, nsh-platform-gpui) macOS, Windows; Linux with Vulkan
Terminal ratatui, the terminal's Cell grid AppView (Rust, an area of a ratatui frame, nsh-platform-tui) Terminals on macOS, Windows, Linux
Web HTML, CSS createPlayer (JavaScript) or an iframe Modern browsers

Each desktop runs and packages apps with its own backend (AppKit, Win32, GTK 4). The GPUI backend draws with GPUI on all three desktops and embeds NSH in GPUI and GPUI Kit apps; nsh run --target gpui shows an app as they do. The web platform (nsh run --target web, nsh package --target web) publishes apps as static sites and runs the website's live demos. The terminal backend (nsh run --target tui) draws apps on a terminal's character grid in its own colors, with the keyboard and the mouse.

Quick start

Install the nsh command (other ways):

macOS / Linux
curl -fsSL https://nsh.dev/install.sh | sh

The nightly build of the latest main, rebuilt every night that it changes:

curl -fsSL https://nsh.dev/install.sh | sh -s -- --nightly
Homebrew
brew install longbridge/tap/nsh
Windows (PowerShell)
irm https://nsh.dev/install.ps1 | iex
From source (macOS / Linux)

Build and install the latest main from source (Git, Rust and the platform build dependencies required):

curl -fsSL https://nsh.dev/install.sh | sh -s -- --source

Re-run to update. The checkout stays in ~/.nsh/source for runtime builds.

Choose how to write your app:

Rust TSX
Create nsh init my-app --template rust nsh init my-app --template ts
Write Rust components, typed styles and signals TSX components, Tailwind classes and signals
Iterate Rebuild and restart on Rust changes Hot updates that preserve state
Toolchain nsh and Rust, built with huacnlee/cargo nsh

You can also combine them (nsh init my-app --template mixed): TSX screens import your Rust components and modules. See Building with Rust for Rust apps and mixed projects.

Run either app on your chosen platform:

iOS
nsh run my-app --target ios        # iOS simulator; requires Xcode
nsh run my-app --target catalyst   # Mac Catalyst window on macOS
Android
nsh run my-app --target android    # emulator or device; requires the Android SDK
macOS
nsh run my-app --target macos      # AppKit window
Windows
nsh run my-app --target windows    # Win32 window
Linux
nsh run my-app --target linux      # GTK 4 window
GPUI (macOS, Windows, Linux)
nsh run my-app --target gpui       # as GPUI apps that embed it show it
Terminal
nsh run my-app --target tui        # in the current terminal
Web
nsh run my-app --target web        # open in the browser

The Rust template includes a Cargo project with its root component in src/lib.rs. The TSX template includes App.tsx, nsh.json and tsconfig.json, with generated TypeScript declarations in .nsh/types for your editor. Logs and errors show in the terminal. What each platform needs: Installation.

Examples

Example What it shows
examples/gallery-rs The gallery written in Rust: an app with no TSX and no QuickJS
examples/rust-exports A TSX app using a component, a module and a class of its own Rust crate
examples/gallery A tour of what NSH supports: lists, navigation, forms, controls, gestures, animation, images, styles, text, web view and video, fetch
examples/counter The smallest app
examples/tasks-rs A small Rust app with a store, pages, a list, a system alert and tests, laid out as the Coding Guides say
examples/tasks The same app in TSX
examples/hopper A dark, tabbed dashboard built only from primitives: interactive canvas charts, sliders, menus, animation
examples/desktop A desktop app with a title bar and menus of its own (nsh/desktop)
examples/embed-ios, examples/embed-android NSH inside existing native apps, with a native component the app registers
examples/bench Rust components against the same components in TSX
cargo run

Skills for AI coding agents

Install the NSH skills for your coding agent (Claude Code, Codex, Cursor, Gemini CLI and others), so it follows NSH's model in Rust, Rust with TSX, or TSX:

npx skills add longbridge/nsh
Skill What it gives the agent
nsh Building apps in Rust (preferred), Rust with TSX, or TSX: the Coding Guides, a page per mode, tooling, and a tested app in Rust and in TSX
nsh-design-guides The Design Guides, for any screen, interaction or interface copy

Acknowledgements

NSH builds on the ideas of these projects:

License

Licensed under the Apache License, Version 2.0.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed under Apache-2.0, without any additional terms or conditions.

nsh (longbridge/nsh)

正在搜索数据库…

3K ·GitHub
这是什么?NSH 是一个用 Rust 编写的引擎,用于构建跨平台应用。界面使用 TSX(或 Rust)编写,每个平台都用自己的原生 UI 来渲染:iOS 上使用 UIKit,Android 上使用 Android 视图,macOS 上使用 AppKit,Windows 上使用 Win32/Direct2D,Linux 上使用 GTK 4,桌面端使用 GPUI,网页端则使用 HTML。
这是我用来构建整个应用的框架,还是只是用来嵌入的组件?两种方式都支持:你可以完全用 NSH 构建独立应用,也可以把 NSH 嵌入到现有的原生应用中,与地图、网页视图等组件并存。
我该如何开始使用?在 macOS/Linux 上通过 Homebrew、在 Windows 上通过 PowerShell 安装程序安装 'nsh' 命令行工具,然后运行 'nsh init my-app --template ts'(或 '--template rust' / '--template mixed'),再用 'nsh run --target ' 启动应用。
每个平台需要什么系统版本?iOS 15+、Android 9 (API 28)+、macOS 14+、Windows 10 1809+,Linux 上需要 GTK 4.14+;GPUI 后端在 Linux 上还需要 Vulkan。
如果 TSX 界面可以在运行时加载,这会有安全风险吗?动态加载的 TSX 模块必须是已签名的包,并且在沙箱中运行,沙箱的权限由宿主应用配置,因此宿主可以控制加载的界面被允许执行哪些操作。
我应该用 Rust 还是 TSX 编写应用?两者皆可,也可以同时使用:Rust 提供带类型的组件和信号,修改后会自动重新编译;TSX 提供基于 Tailwind 样式的组件,支持保留状态的热更新。此外,'mixed' 模板允许 TSX 界面导入你的 Rust 组件。
GPUI 后端相比普通原生视图能带来什么?GPUI 后端在三个桌面操作系统上都使用 GPUI 渲染同一个应用,而不是使用各系统自带的原生工具包;它还可以直接嵌入到其他 GPUI 或 GPUI Kit 应用中。
AI 工具能生成 NSH 界面吗?可以。NSH 会生成 TypeScript 声明文件和模型可读的文档,专门用于让 AI 生成的 TSX 和 Tailwind 界面能够在各个平台上原生运行。
示例应用都涵盖哪些内容?示例从最简单的 'counter' 计数应用,到完整的控件 'gallery' 展示应用,还包括一个不使用 TSX/QuickJS 的纯 Rust 版 gallery、iOS 和 Android 原生嵌入演示,以及一个对比 Rust 组件与同样 TSX 组件的基准测试。
有哪些类似的项目?react-native, ng-native, perry, expo, lynx, weex, PakePlus, native
它属于哪些主题?generative-ui, jsx, native, mobile-app, ui, sdk, mobile, ios, framework, android, rust, gui
大小
82.1 MB
星标
3K
时长
1个月
提交 · 90 天