TUIOS can be imported and used as a library in your own Go applications. This allows you to embed a full-featured terminal window manager in your Bubble Tea applications.
go get github.com/Gaurav-Gosain/tuios/pkg/tuiospackage main
import (
"log"
"github.com/Gaurav-Gosain/tuios/pkg/tuios"
tea "github.com/charmbracelet/bubbletea/v2"
)
func main() {
// Create a new TUIOS instance with default options
model := tuios.New()
// Create the Bubble Tea program with recommended options
p := tea.NewProgram(model, tuios.ProgramOptions()...)
// Run the program
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}model := tuios.New(
tuios.WithTheme("dracula"),
tuios.WithShowKeys(true),
tuios.WithAnimations(false),
tuios.WithWorkspaces(9),
tuios.WithBorderStyle("rounded"),
tuios.WithDockbarPosition("bottom"),
tuios.WithScrollbackLines(20000),
)For better performance, use the provided mouse motion filter:
p := tea.NewProgram(
model,
tea.WithFPS(60),
tea.WithFilter(tuios.FilterMouseMotion),
)Set the color theme. Available themes include "dracula", "nord", "tokyonight", and 300+ others from bubbletint.
tuios.WithTheme("dracula")Enable the showkeys overlay to display pressed keys (useful for demos).
tuios.WithShowKeys(true)Enable or disable window animations. When disabled, windows snap instantly.
tuios.WithAnimations(false)Use ASCII characters instead of Nerd Font icons for compatibility.
tuios.WithASCIIOnly(true)Set the number of workspaces (1-9).
tuios.WithWorkspaces(4)Set the window border style. Valid values:
"rounded"(default)"normal""thick""double""hidden""block""ascii"
tuios.WithBorderStyle("thick")Set the dockbar position. Valid values:
"bottom"(default)"top""hidden"
tuios.WithDockbarPosition("top")Hide the minimize/maximize/close buttons in window title bars.
tuios.WithHideWindowButtons(true)Set the scrollback buffer size (100-1000000).
tuios.WithScrollbackLines(50000)Set the initial terminal size. Usually not needed as TUIOS auto-detects.
tuios.WithSize(120, 40)Enable SSH mode for running over SSH connections.
tuios.WithSSHMode(true)Provide a custom user configuration instead of loading from file.
cfg := tuios.Config.DefaultConfig()
cfg.Keybindings.LeaderKey = "ctrl+a"
tuios.WithUserConfig(cfg)TUIOS can be served through the browser using the sip library:
package main
import (
"context"
"log"
"github.com/Gaurav-Gosain/sip"
"github.com/Gaurav-Gosain/tuios/pkg/tuios"
tea "github.com/charmbracelet/bubbletea/v2"
)
func main() {
server := sip.NewServer(sip.DefaultConfig())
err := server.Serve(context.Background(), func(sess sip.Session) (tea.Model, []tea.ProgramOption) {
pty := sess.Pty()
// Create TUIOS for the web session
model := tuios.New(
tuios.WithSize(pty.Width, pty.Height),
tuios.WithTheme("dracula"),
)
return model, tuios.ProgramOptions()
})
if err != nil {
log.Fatal(err)
}
}For SSH server integration, use the Wish library:
package main
import (
"context"
"github.com/Gaurav-Gosain/tuios/pkg/tuios"
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/wish/v2"
"github.com/charmbracelet/wish/v2/bubbletea"
)
func main() {
s, _ := wish.NewServer(
wish.WithAddress(":2222"),
wish.WithMiddleware(
bubbletea.Middleware(func(sess ssh.Session) (tea.Model, []tea.ProgramOption) {
pty, _, _ := sess.Pty()
model := tuios.New(
tuios.WithSize(pty.Window.Width, pty.Window.Height),
tuios.WithSSHMode(true),
)
return model, tuios.ProgramOptions()
}),
),
)
s.ListenAndServe()
}The tuios.Config struct provides access to configuration utilities:
// Load user config from file
cfg, err := tuios.Config.LoadUserConfig()
// Get default config
cfg := tuios.Config.DefaultConfig()
// Get config file path
path, err := tuios.Config.GetConfigPath()The TUIOS model provides several public methods:
AddWindow(title string)- Create a new terminal windowDeleteWindow(i int)- Close window at indexFocusWindow(i int)- Focus window at indexGetFocusedWindow()- Get the currently focused window
SwitchWorkspace(n int)- Switch to workspace n (1-9)MoveWindowToWorkspace(windowIndex, workspace int)- Move a window
ToggleTiling()- Toggle automatic tiling modeTileAllWindows()- Retile all windows
Cleanup()- Clean up resources (call when done)
You can wrap TUIOS in your own model for additional functionality:
type MyApp struct {
tuios *tuios.Model
// your additional state
}
func (m *MyApp) Init() tea.Cmd {
return m.tuios.Init()
}
func (m *MyApp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Handle your custom messages first
switch msg := msg.(type) {
case myCustomMsg:
// handle it
return m, nil
}
// Delegate to TUIOS
updated, cmd := m.tuios.Update(msg)
m.tuios = updated.(*tuios.Model)
return m, cmd
}
func (m *MyApp) View() string {
return m.tuios.View()
}- Architecture - Technical architecture
- Keybindings - Keyboard shortcuts
- Configuration - Config file options
- Web Terminal - Browser-based access
- Sip Library - Web serving library