-
Notifications
You must be signed in to change notification settings - Fork 7
go-tui: Go SDK Quickstart #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
0ae11f0
Added a basic go-tui app that mirrors the rust-tui app
bigfish24 bfeb02a
Added one-liner to run
bigfish24 b04cd96
feat: migrate go-tui to v5 Config-based Ditto API
kristopherjohnson 44407a3
style: apply go fmt formatting to main.go
kristopherjohnson 2e5f8c4
refactor: apply Go-idiomatic improvements to go-tui
kristopherjohnson 1f56d2d
chore: add .gitignore for go-tui executables
kristopherjohnson eb3411f
docs: remove go-tui executable references, use only ditto-tasks-termui
kristopherjohnson dda9498
feat: integrate new Go SDK authentication API
kristopherjohnson 090fe31
fix: update imports for flattened Ditto Go SDK structure
kristopherjohnson b9818ff
refactor: update config type to DittoConfig
kristopherjohnson 0e4b049
fix: update to use ServerConnect instead of deprecated OnlinePlaygrou…
kristopherjohnson 45c6bf0
refactor: modernize logging and platform support
kristopherjohnson be2d714
fix: resolve terminal UI display issues and clean up debug code
kristopherjohnson 2c95aee
refactor: remove call to deprecated DisableSyncWithV3
kristopherjohnson a5b81e9
chore(go-tui): make the path to the Go SDK machine-independent
kristopherjohnson dfab631
chore(go-tui): remove unnecessary call to `UpdateTransportConfig()`
kristopherjohnson f04c63e
fix(go-tui): update API calls to match Go SDK v5 interface
kristopherjohnson fbb05db
fix(go-tui): update ServerConnect to DittoConfigConnectServer
kristopherjohnson ba11526
fix(go-tui): update sync API calls to use new Sync type methods
kristopherjohnson 6b1dd4d
perf(go-tui): use Items() method instead of iterating GetItem()
kristopherjohnson 451d5b7
chore(go): rename Go quickstart executable to `ditto-tasks-termui`
kristopherjohnson ba988f6
chore(go): add dsharp-pivotal to CODEOWNERS for go-tui
kristopherjohnson 9e39ddf
go-tui: Use os.DevNull for name of /dev/null
dsharp-pivotal 390fbfc
go-tui: Use channels over Mutex in the App struct
dsharp-pivotal 4f183bc
go-tui: Clear highlight from non-selected rows
dsharp-pivotal 603b78b
go-tui: Shrink the selector and done columns to fixed sizes
dsharp-pivotal c2fe91d
go-tui: Re-render on terminal resize
dsharp-pivotal fbcda3c
go-tui: Update input box size
dsharp-pivotal bee75f1
git-tui: Handle all ui events in handleEvent; fix "q" in edit modes
dsharp-pivotal 7a206cb
resolve CODEOWNERS merge conflicts
kristopherjohnson 78ea368
update go-tui for Go SDK public preview.1
kristopherjohnson 30b8bc5
Delete GO_IMPROVEMENTS.md
kristopherjohnson 75c1e17
use downloaded libraries and Go module
kristopherjohnson 265a72f
Update SDK version to 5.0.0-experimental-go-publish.10
kristopherjohnson 85e06b9
remove `replace` directive
kristopherjohnson fabfb34
Merge branch 'main' into kj/go-tui
kristopherjohnson f4e9bd7
Update go-tui/Makefile
kristopherjohnson e818f70
update to 5.0.0-go-preview.3
kristopherjohnson a875699
Merge branch 'kj/go-tui' of github.com:getditto/quickstart into kj/go…
kristopherjohnson e22053f
Apply suggestion from @Copilot
kristopherjohnson 1bb06da
Enable the `ditto.SetMinimumLogLevel()` line which was causing segfau…
kristopherjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [{*.go,*.go2}] | ||
| indent_style = tab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ditto-tasks-termui | ||
| go-tui | ||
| *.log | ||
| *.out | ||
| go-sdk/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Makefile for Ditto QuickStart Go TUI Tasks application | ||
|
|
||
| # Display help information | ||
| .PHONY: help | ||
| help: | ||
| @echo "Ditto Go TUI Tasks Application" | ||
| @echo "" | ||
| @echo "Available targets:" | ||
| @echo " build - Build the FFI library and application" | ||
| @echo " run - Build and run the application" | ||
| @echo " run-go - Run directly with 'go run'" | ||
| @echo " clean - Remove build artifacts" | ||
| @echo " help - Show this help message" | ||
| @echo "" | ||
| @echo "Note: Ensure .env file exists with proper Ditto configuration" | ||
|
|
||
| GO=go | ||
|
|
||
| # Ditto SDK version and platform detection | ||
| #DITTO_SDK_VERSION ?= 5.0.0-go-preview.1 | ||
| DITTO_SDK_VERSION ?= 5.0.0-experimental-go-publish.10 | ||
| PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]') | ||
| ARCH := $(shell uname -m) | ||
|
|
||
| # Determine Ditto SDK platform string | ||
| ifeq ($(PLATFORM),linux) | ||
| DITTO_PLATFORM = linux-$(ARCH) | ||
| else ifeq ($(PLATFORM),darwin) | ||
| DITTO_PLATFORM = macos-aarch64 | ||
|
|
||
| # avoid version mismatch warnings when linking | ||
| export MACOSX_DEPLOYMENT_TARGET := 11.0 | ||
| export CGO_CFLAGS := -mmacosx-version-min=11.0 | ||
| export CGO_LDFLAGS := -mmacosx-version-min=11.0 | ||
| else | ||
| $(error Unsupported platform: $(PLATFORM)) | ||
| endif | ||
|
|
||
| DITTO_SDK_URL = "https://software.ditto.live/go-$(DITTO_PLATFORM)/Ditto/$(DITTO_SDK_VERSION)/libs/libdittoffi-$(DITTO_PLATFORM).tar.gz" | ||
|
|
||
| # Build the application | ||
| .PHONY: build | ||
| build: go-sdk ditto-tasks-termui | ||
|
|
||
| ditto-tasks-termui: main.go redirect_unix.go redirect_windows.go widgets.go Makefile go.mod go.sum | ||
| @echo "Building ditto-tasks-termui..." | ||
| $(GO) mod tidy | ||
| $(GO) build -o ditto-tasks-termui -ldflags='-extldflags "-L./go-sdk"' | ||
|
|
||
| .PHONY: go-sdk | ||
| go-sdk: ## Downloads and installs the Ditto Go SDK library to go-sdk directory | ||
| @ if [ ! -f go-sdk/libdittoffi.so ] && [ ! -f go-sdk/libdittoffi.dylib ] ; then \ | ||
| echo "📥 Downloading Ditto Go SDK v$(DITTO_SDK_VERSION) for $(DITTO_PLATFORM) $(DITTO_SDK_URL)..."; \ | ||
| mkdir -p go-sdk; \ | ||
| if curl -L -f $(DITTO_SDK_URL) | tar xz --strip-components=0 -C go-sdk/; then \ | ||
| echo "✅ Ditto Go SDK v$(DITTO_SDK_VERSION) installed successfully"; \ | ||
| else \ | ||
| echo "❌ Failed to download SDK for $(DITTO_PLATFORM)"; \ | ||
| fi; \ | ||
| else \ | ||
| echo "✅ Ditto Go SDK already installed"; \ | ||
| fi | ||
|
|
||
| # Run the application (built binary) | ||
| .PHONY: build | ||
| run: build | ||
| @echo "Running ditto-tasks-termui..." | ||
| LD_LIBRARY_PATH="$$(pwd)/go-sdk" DYLD_LIBRARY_PATH="$$(pwd)/go-sdk" ./ditto-tasks-termui 2>/dev/null | ||
|
|
||
| # Run directly with Go | ||
| .PHONY: run-go | ||
| run-go: | ||
| @echo "Running ditto tasks-termui with go run..." | ||
| LD_LIBRARY_PATH="$$(pwd)/go-sdk" DYLD_LIBRARY_PATH="$$(pwd)/go-sdk" $(GO) run main.go 2>/dev/null | ||
|
|
||
| # Clean build artifacts | ||
| .PHONY: clean | ||
| clean: | ||
| @echo "Cleaning ditto-tasks-termui and build artifacts..." | ||
| rm -f ditto-tasks-termui | ||
| rm -rf go-sdk | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # Ditto Go Quickstart App 🚀 | ||
|
|
||
| This directory contains Ditto's quickstart app for the Go SDK. | ||
| This app is a Terminal User Interface (TUI) that allows for creating | ||
| a todo list that syncs between multiple peers. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| To get started, you'll first need to create an app in the [Ditto Portal][0] | ||
| with the "Online Playground" authentication type. You'll need to find your | ||
| AppID and Online Playground Token, Auth URL, and Websocket URL in order to use this quickstart. | ||
|
|
||
| [0]: https://portal.ditto.live | ||
|
|
||
| Create a `.env` file in this directory with your Ditto credentials: | ||
|
|
||
| ```bash | ||
| # Create .env file | ||
| cat > .env << 'EOF' | ||
| DITTO_APP_ID=your-app-id | ||
| DITTO_PLAYGROUND_TOKEN=your-playground-token | ||
| DITTO_AUTH_URL=https://your-app-id.cloud.ditto.live | ||
| EOF | ||
| ``` | ||
|
|
||
| Alternatively, you can set these as environment variables: | ||
|
|
||
| ```bash | ||
| export DITTO_APP_ID="your-app-id" | ||
| export DITTO_PLAYGROUND_TOKEN="your-playground-token" | ||
| export DITTO_AUTH_URL="https://your-app-id.cloud.ditto.live" | ||
| ``` | ||
|
|
||
| ## Building | ||
|
|
||
| From this directory (`go-tui`): | ||
|
|
||
| ```bash | ||
| # Using the Makefile | ||
| make build | ||
|
|
||
| # Or build directly with Go | ||
| go build -o ditto-tasks-termui | ||
| ``` | ||
|
|
||
|
|
||
| ## Running | ||
|
|
||
| **Note:** the Ditto Go SDK `libdittoffi.so` (Linux) or `libdittoffi.dylib` | ||
| shared library must be present and in one of the directories searched by the | ||
| system's dynamic linker to run the application. This is handled automatically | ||
| by `make run`. If you use one of the other options, you may need to perform | ||
| additional steps. See the [Go SDK Install Guide](https://docs.ditto.live/sdk/latest/install-guides/go) | ||
| for details. | ||
|
|
||
| Run the quickstart app with the following command: | ||
|
|
||
|
|
||
| ```bash | ||
| # Using the Makefile (which will download the shared library and set shared-library load paths automatically) | ||
| make run | ||
| ``` | ||
|
|
||
| ```bash | ||
| # Run the executable that was created via make build | ||
| ./ditto-tasks-termui 2>/dev/null | ||
| ``` | ||
|
|
||
| Or run directly with Go: | ||
| ```bash | ||
| go run main.go 2>/dev/null | ||
| ``` | ||
|
|
||
| > NOTE: The `2>/dev/null` is a workaround to silence output on `stderr`, since | ||
| > that would interfere with the TUI application. Without it, the screen will | ||
| > quickly become garbled due to Ditto's internal logging. | ||
|
|
||
| ## Controls | ||
|
|
||
| - **j/↓**: Move down | ||
| - **k/↑**: Move up | ||
| - **Enter/Space**: Toggle task completion | ||
| - **c**: Create new task | ||
| - **e**: Edit selected task | ||
| - **d**: Delete selected task | ||
| - **q**: Quit application | ||
| - **Esc**: Cancel input mode | ||
|
|
||
| ## Features | ||
|
|
||
| - ✅ Create, edit, and delete tasks | ||
| - ✅ Mark tasks as complete/incomplete | ||
| - ✅ Real-time synchronization across devices | ||
| - ✅ Terminal-based interface using termui | ||
| - ✅ Cross-platform compatibility with other Ditto quickstart apps | ||
|
|
||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Logs | ||
|
|
||
| To find errors and messages that are not printed to the TUI display, check the application logs. | ||
| Logs are output to `/tmp/ditto-tasks-termui.log`. | ||
|
|
||
| ### libdittoffi Library not found | ||
|
|
||
| If you get a library loading error, ensure that the `libdittoffi.so` (Linux) or | ||
| `libdittoffi.dylib` (macOS) shared library is present and that `LD_LIBRARY_PATH` | ||
| (Linux) or `DYLD_LIBRARY_PATH` (macOS) is set appropriately. | ||
|
|
||
| ### Environment variables not found | ||
|
|
||
| The app looks for a `.env` file in the current directory. Ensure it exists with | ||
| all required variables set, or export them as environment variables. | ||
|
|
||
| ### Garbled screen output | ||
|
|
||
| Always run the application with `2>/dev/null` to suppress stderr output that can | ||
| interfere with the TUI display: | ||
|
|
||
| ```bash | ||
| ./ditto-tasks-termui 2>/dev/null | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| The application uses: | ||
| - [termui v3](https://github.com/gizak/termui) for the TUI framework (similar to Rust's ratatui) | ||
| - [Ditto Go SDK](https://github.com/getditto/ditto-go-sdk) for edge sync | ||
| - Channels for async communication between Ditto observers and the UI | ||
|
|
||
| ## Architecture | ||
|
|
||
| The app follows an event-driven architecture: | ||
| - Direct event loop handling keyboard input | ||
| - Table widget for displaying tasks (similar to Rust's ratatui) | ||
| - Manual text input handling for create/edit modes | ||
| - Async updates from Ditto observers via Go channels | ||
| - Real-time sync with other Ditto peers running the same app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| module github.com/getditto/quickstart/go-tui/ditto-tasks-termui | ||
|
|
||
| go 1.24.0 | ||
|
|
||
| require ( | ||
| github.com/getditto/ditto-go-sdk/v5 v5.0.0-experimental-go-publish.10 | ||
| github.com/gizak/termui/v3 v3.1.0 | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/joho/godotenv v1.5.1 | ||
| golang.org/x/sys v0.37.0 | ||
| golang.org/x/term v0.36.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/clipperhouse/stringish v0.1.1 // indirect | ||
| github.com/clipperhouse/uax29/v2 v2.3.0 // indirect | ||
| github.com/fxamacker/cbor/v2 v2.9.0 // indirect | ||
| github.com/mattn/go-runewidth v0.0.19 // indirect | ||
| github.com/mitchellh/go-wordwrap v1.0.1 // indirect | ||
| github.com/nsf/termbox-go v1.1.1 // indirect | ||
| github.com/x448/float16 v0.8.4 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs= | ||
| github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA= | ||
| github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4= | ||
| github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g= | ||
| github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= | ||
| github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= | ||
| github.com/getditto/ditto-go-sdk/v5 v5.0.0-experimental-go-publish.10 h1:yXmgeTUVdVY/pBBW35cFBWA7xFEr2aPQ4LjatIRdid8= | ||
| github.com/getditto/ditto-go-sdk/v5 v5.0.0-experimental-go-publish.10/go.mod h1:LFVfgkbjAENnhaxjd4rUfOUVOH7BC3yEuKCo1Ps/Kbg= | ||
| github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= | ||
| github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
| github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
| github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= | ||
| github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= | ||
| github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= | ||
| github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= | ||
| github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= | ||
| github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= | ||
| github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= | ||
| github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= | ||
| github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY= | ||
| github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= | ||
| github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= | ||
| github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= | ||
| golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= | ||
| golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= | ||
| golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= | ||
| golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.