### Install displaywidth with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/clipperhouse/displaywidth/README.md Install the displaywidth package using the Go module tool. ```bash go get github.com/clipperhouse/displaywidth ``` -------------------------------- ### Install go-colorful with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/lucasb-eyer/go-colorful/README.md Use this command to install the go-colorful library. It is the standard Go package installation command. ```bash $ go get github.com/lucasb-eyer/go-colorful ``` -------------------------------- ### Install tint with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/lmittmann/tint/README.md Installs the tint package using the Go module tool. ```shell go get github.com/lmittmann/tint ``` -------------------------------- ### Install Ultraviolet with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/README.md Use this command to install the latest version of the Ultraviolet library. ```bash go get github.com/charmbracelet/ultraviolet@latest ``` -------------------------------- ### Install from archive or go install Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Best for manual foreground use or development. The archive installs the binary to /usr/local/bin; go install requires VERSION set to a supported v-prefixed tag. ```text curl -LO https://github.com/abilisoft/usbip-go/releases/download/vX.Y.Z/usbip-go_X.Y.Z_linux_amd64.tar.gz tar xzf usbip-go_X.Y.Z_linux_amd64.tar.gz sudo install -m 0755 usbip-go /usr/local/bin/ # or, after setting VERSION to a supported v-prefixed tag go install "github.com/abilisoft/usbip-go/cmd/usbip-go@${VERSION}" ``` -------------------------------- ### usbip-go serve --allow-cidr example Source: https://github.com/abilisoft/usbip-go/blob/main/docs/security.md Shows how to start the daemon with CIDR allow-listing. Repeat the flag to allow multiple networks. When any entry is provided, the daemon switches to fail-closed ACL mode, rejecting connections outside the listed CIDRs. ```text usbip-go serve --allow-cidr 10.0.0.0/8 --allow-cidr 192.168.0.0/16 ``` -------------------------------- ### Install Cobra library with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/spf13/cobra/README.md Use this command to install the latest version of the Cobra library. Run it before importing Cobra in your application. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install terminfo with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/xo/terminfo/README.md Install the terminfo package using the standard Go toolchain. Run this command in your terminal to fetch the latest version. ```sh $ go get -u github.com/xo/terminfo ``` -------------------------------- ### Install uniseg with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/rivo/uniseg/README.md Installs the uniseg package via the standard Go module command. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Install pflag with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/spf13/pflag/README.md Install the pflag package using the standard Go tool. Run this command in your terminal. ```bash go get github.com/spf13/pflag ``` -------------------------------- ### Install yaml package with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/gopkg.in/yaml.v3/README.md Install the yaml package using the import path gopkg.in/yaml.v3. ```shell go get gopkg.in/yaml.v3 ``` -------------------------------- ### go get install command for goleak Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/go.uber.org/goleak/README.md Use `go get -u go.uber.org/goleak` to install the latest version. Supports semver releases. Note: only supports the two most recent minor versions of Go. ```bash go get -u go.uber.org/goleak ``` -------------------------------- ### Install .deb or .rpm package Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Use the OS package for production/systemd installs. Choose the latest non-retracted stable tag, otherwise these commands are templates. ```text sudo dpkg -i usbip-go_X.Y.Z_linux_amd64.deb # or sudo rpm -i usbip-go_X.Y.Z_linux_amd64.rpm ``` -------------------------------- ### Install Lip Gloss v2 with go get Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Install the Lip Gloss v2 module with the Go package manager. Run this in your terminal to add the dependency. ```bash go get charm.land/lipgloss/v2 ``` -------------------------------- ### Install usbip-go with go install Source: https://github.com/abilisoft/usbip-go/blob/main/README.md Installs usbip-go from source using Go. Use an explicit supported tag rather than @latest. Building the current development branch requires Go 1.26.5 or newer. ```sh VERSION=vX.Y.Z # replace with a supported release tag go install "github.com/abilisoft/usbip-go/cmd/usbip-go@${VERSION}" ``` -------------------------------- ### Quick Start: Hello World with Ultraviolet Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/README.md This Go program initializes a terminal, enters the alternate screen, and renders 'Hello, World!' centered on the screen. It handles window resize events and quits on 'q' or 'ctrl+c'. ```go package main import ( "log" uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" ) func main() { t := uv.DefaultTerminal() scr := t.Screen() scr.EnterAltScreen() if err := t.Start(); err != nil { log.Fatalf("failed to start terminal: %v", err) } defer t.Stop() ctx := screen.NewContext(scr) text := "Hello, World!" textWidth := scr.StringWidth(text) display := func() { screen.Clear(scr) bounds := scr.Bounds() x := (bounds.Dx() - textWidth) / 2 y := bounds.Dy() / 2 ctx.DrawString(text, x, y) scr.Render() scr.Flush() } for ev := range t.Events() { switch ev := ev.(type) { case uv.WindowSizeEvent: scr.Resize(ev.Width, ev.Height) display() case uv.KeyPressEvent: if ev.MatchString("q", "ctrl+c") { return } } } } ``` -------------------------------- ### Install graphemes package Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/clipperhouse/uax29/v2/graphemes/README.md Install the graphemes package using the Go module system. ```bash go get github.com/clipperhouse/uax29/v2/graphemes ``` -------------------------------- ### Install usbip-go from release archive Source: https://github.com/abilisoft/usbip-go/blob/main/README.md Downloads and installs the usbip-go binary from a GitHub release archive. Replace VERSION with a supported release version. Archives are published for Linux amd64, arm64, and armv7. ```sh VERSION=X.Y.Z # replace with a supported release version curl -LO "https://github.com/abilisoft/usbip-go/releases/download/v${VERSION}/usbip-go_${VERSION}_linux_amd64.tar.gz" tar xzf "usbip-go_${VERSION}_linux_amd64.tar.gz" sudo install -m 0755 usbip-go /usr/local/bin/usbip-go ``` -------------------------------- ### Output of YAML example Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/gopkg.in/yaml.v3/README.md Expected output from the Go example, showing the unmarshalled struct and map, and their YAML dumps. ```text --- t: {Easy! {2 [3 4]}} --- t dump: a: Easy! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 3 - 4 ``` -------------------------------- ### Start and stop the terminal Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/TUTORIAL.md Starts the terminal, putting the console into raw mode, initializing the input event loop, and preparing the screen for rendering. Stop() restores the console, exits the alternate screen, and cleans up; it is safe to call multiple times and supports suspend/resume cycles. ```go if err := t.Start(); err != nil { log.Fatalf("failed to start terminal: %v", err) } defer t.Stop() ``` -------------------------------- ### FromString example Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/clipperhouse/uax29/v2/graphemes/README.md Example of using FromString to iterate over graphemes from a string. ```go text := "Hello, 世界. Nice dog! 👍🐶" g := graphemes.FromString(text) for g.Next() { // Next() returns true until end of data fmt.Println(g.Value()) // Do something with the current grapheme } ``` -------------------------------- ### Simple terminfo example (main.go) Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/xo/terminfo/README.md Complete Go program that loads terminfo from the environment, initializes the terminal, prints colored blocks, and restores the terminal on exit. It uses terminfo constants like CursorInvisible, EnterCaMode, ClearScreen, and CursorAddress, and handles SIGINT/SIGTERM signals. The termtitle function attempts to load the 'xterm+sl' terminfo for status line support when the terminal is xterm or COLORTERM is truecolor. ```go // _examples/simple/main.go package main import ( "bytes" "fmt" "log" "os" "os/signal" "strings" "sync" "syscall" "github.com/xo/terminfo" ) func main() { //r := rand.New(nil) // load terminfo ti, err := terminfo.LoadFromEnv() if err != nil { log.Fatal(err) } // cleanup defer func() { err := recover() termreset(ti) if err != nil { log.Fatal(err) } }() terminit(ti) termtitle(ti, "simple example!") termputs(ti, 3, 3, "Ctrl-C to exit") maxColors := termcolors(ti) if maxColors > 256 { maxColors = 256 } for i := 0; i < maxColors; i++ { termputs(ti, 5+i/16, 5+i%16, ti.Colorf(i, 0, "█")) } // wait for signal sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) <-sigs } // terminit initializes the special CA mode on the terminal, and makes the // cursor invisible. func terminit(ti *terminfo.Terminfo) { buf := new(bytes.Buffer) // set the cursor invisible ti.Fprintf(buf, terminfo.CursorInvisible) // enter special mode ti.Fprintf(buf, terminfo.EnterCaMode) // clear the screen ti.Fprintf(buf, terminfo.ClearScreen) os.Stdout.Write(buf.Bytes()) } // termreset is the inverse of terminit. func termreset(ti *terminfo.Terminfo) { buf := new(bytes.Buffer) ti.Fprintf(buf, terminfo.ExitCaMode) ti.Fprintf(buf, terminfo.CursorNormal) os.Stdout.Write(buf.Bytes()) } // termputs puts a string at row, col, interpolating v. func termputs(ti *terminfo.Terminfo, row, col int, s string, v ...interface{}) { buf := new(bytes.Buffer) ti.Fprintf(buf, terminfo.CursorAddress, row, col) fmt.Fprintf(buf, s, v...) os.Stdout.Write(buf.Bytes()) } // sl is the status line terminfo. var sl *terminfo.Terminfo // termtitle sets the window title. func termtitle(ti *terminfo.Terminfo, s string) { var once sync.Once once.Do(func() { if ti.Has(terminfo.HasStatusLine) { return } // load the sl xterm if terminal is an xterm or has COLORTERM if strings.Contains(strings.ToLower(os.Getenv("TERM")), "xterm") || os.Getenv("COLORTERM") == "truecolor" { sl, _ = terminfo.Load("xterm+sl") } }) if sl != nil { ti = sl } if !ti.Has(terminfo.HasStatusLine) { return } buf := new(bytes.Buffer) ti.Fprintf(buf, terminfo.ToStatusLine) fmt.Fprint(buf, s) ti.Fprintf(buf, terminfo.FromStatusLine) os.Stdout.Write(buf.Bytes()) } // termcolors returns the maximum colors available for the terminal. func termcolors(ti *terminfo.Terminfo) int { if colors := ti.Num(terminfo.MaxColors); colors > 0 { return colors } return int(terminfo.ColorLevelBasic) } ``` -------------------------------- ### Update lipgloss import path and install v2 Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Shows the old and new import paths for the lipgloss module and the command to install the v2 module. The import path changed from github.com/charmbracelet/lipgloss to charm.land/lipgloss/v2. ```go // v1 import "github.com/charmbracelet/lipgloss" // v2 import "charm.land/lipgloss/v2" ``` ```bash go get charm.land/lipgloss/v2 ``` -------------------------------- ### True Color (24-bit) profile examples Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Creates colors using the True Color (24-bit) profile with hex strings. Comments show the resulting color names. ```go lipgloss.Color("#0000FF") // good ol' 100% blue lipgloss.Color("#04B575") // a green lipgloss.Color("#3C3C3C") // a dark gray ``` -------------------------------- ### Drain and upgrade procedure with systemctl Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Stops the daemon gracefully by draining active sessions, installs the new binary, and restarts the service. Active sessions are disconnected; they do not migrate. ```text sudo usbip-go drain --status-socket /run/usbip-go/status.sock sudo install -m 0755 /tmp/new-usbip-go /usr/bin/usbip-go sudo systemctl start usbip-go ``` -------------------------------- ### Render text with style.Render Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Renders styled text using the Render method on a Style. The example prints "Hello, kitty." and "Hello, puppy.". ```go style := lipgloss.NewStyle().Bold(true).SetString("Hello,") lipgloss.Println(style.Render("kitty.")) // Hello, kitty. lipgloss.Println(style.Render("puppy.")) // Hello, puppy. ``` -------------------------------- ### Render text with Stringer interface Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Renders styled text using the Stringer interface. The example prints "你好,猫咪。". ```go var style = lipgloss.NewStyle().SetString("你好,猫咪。").Bold(true) lipgloss.Println(style) // 你好,猫咪。 ``` -------------------------------- ### Basic Lip Gloss style and render Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Shows the core Lip Gloss usage: create a style with bold, foreground/background colors, padding, and width, then render and print a string. Use this as the starting point for styling terminal output. ```go import "charm.land/lipgloss/v2" var style = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FAFAFA")). Background(lipgloss.Color("#7D56F4")). PaddingTop(2). PaddingLeft(4). Width(22) lipgloss.Println(style.Render("Hello, kitty")) ``` -------------------------------- ### Render a styled table with lipgloss table package Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Builds a styled table with the lipgloss table package: define rows, configure header/cell styles, add borders and a style function, then print it. The example also shows adding a row individually with t.Row. ```go import "charm.land/lipgloss/v2/table" ``` ```go rows := [][]string{ {"Chinese", "您好", "你好"}, {"Japanese", "こんにちは", "やあ"}, {"Arabic", "أهلين", "أهلا"}, {"Russian", "Здравствуйте", "Привет"}, {"Spanish", "Hola", "¿Qué tal?"}, } ``` ```go var ( purple = lipgloss.Color("99") gray = lipgloss.Color("245") lightGray = lipgloss.Color("241") headerStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center) cellStyle = lipgloss.NewStyle().Padding(0, 1).Width(14) oddRowStyle = cellStyle.Foreground(gray) evenRowStyle = cellStyle.Foreground(lightGray) ) t := table.New(). Border(lipgloss.NormalBorder()). BorderStyle(lipgloss.NewStyle().Foreground(purple)). StyleFunc(func(row, col int) lipgloss.Style { switch { case row == table.HeaderRow: return headerStyle case row%2 == 0: return evenRowStyle default: return oddRowStyle } }). Headers("LANGUAGE", "FORMAL", "INFORMAL"). Rows(rows...) // You can also add tables row-by-row t.Row("English", "You look absolutely fabulous.", "How's it going?") ``` ```go lipgloss.Println(t) ``` -------------------------------- ### Fast color conversion with LinearRgbToXyz and XyzToLab Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/lucasb-eyer/go-colorful/README.md Use the fast approximation path for color conversions in tight loops. The example converts a color to Lab space via LinearRgbToXyz and XyzToLab, which is roughly 5x faster than the standard conversion but only precise to about 0.5% and loses accuracy when input values are outside 0-1. ```go col := // Get your color somehow l, a, b := XyzToLab(LinearRgbToXyz(col.LinearRgb())) ``` -------------------------------- ### Invoke fang.Execute with a root Cobra command Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/fang/README.md Use this to start a Cobra application with Fang. It creates a root command and calls fang.Execute with a background context, exiting with status 1 on error. ```go package main import ( "context" "os" "github.com/charmbracelet/fang" "github.com/spf13/cobra" ) func main() { cmd := &cobra.Command{ Use: "example", Short: "A simple example program!", } if err := fang.Execute(context.Background(), cmd); err != nil { os.Exit(1) } } ``` -------------------------------- ### Export a local USB device manually Source: https://github.com/abilisoft/usbip-go/blob/main/README.md Manual foreground export flow on the machine owning the physical USB device. Requires root for modprobe and bind; serve listens on 0.0.0.0:3240 by default and the status socket is disabled because packaged/systemd installs create /run/usbip-go for it. Keep serve running while clients are attached. ```sh sudo modprobe usbip_core usbip_host usbip-go list sudo usbip-go bind 1-1.2 sudo usbip-go serve --status-socket= ``` -------------------------------- ### Check and load USB/IP kernel modules Source: https://github.com/abilisoft/usbip-go/blob/main/docs/troubleshooting.md Verify whether USB/IP modules are loaded, load them with modprobe, and confirm they are active. If modprobe reports 'module not found', the kernel lacks USB/IP support; install matching kernel modules or select a kernel with CONFIG_USBIP_CORE, CONFIG_USBIP_VHCI_HCD, and CONFIG_USBIP_HOST enabled. ```text $ lsmod | grep -E 'usbip|vhci' # No output — modules are not loaded. $ sudo modprobe usbip_core $ sudo modprobe vhci_hcd $ sudo modprobe usbip_host $ test -d /sys/module/usbip_core && echo usbip_core-loaded $ ls /sys/devices/platform/vhci_hcd.0/ ``` -------------------------------- ### ANSI 256 color profile examples Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Creates colors using the ANSI 256 (8-bit) color profile. The string argument is the ANSI color index; comments show the resulting color names. ```go lipgloss.Color("86") // aqua lipgloss.Color("201") // hot pink lipgloss.Color("202") // orange ``` -------------------------------- ### Run displaywidth benchmarks with go test -bench=. -benchmem Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/clipperhouse/displaywidth/README.md Run the benchmark suite from the comparison directory. The output shows performance comparisons across clipperhouse/displaywidth, mattn/go-runewidth, and rivo/uniseg for various string and rune operations. ```bash cd comparison go test -bench=. -benchmem ``` ```text goos: darwin goarch: arm64 pkg: github.com/clipperhouse/displaywidth/comparison cpu: Apple M2 BenchmarkString_Mixed/clipperhouse/displaywidth-8 5784 ns/op 291.69 MB/s 0 B/op 0 allocs/op BenchmarkString_Mixed/mattn/go-runewidth-8 14751 ns/op 114.36 MB/s 0 B/op 0 allocs/op BenchmarkString_Mixed/rivo/uniseg-8 19360 ns/op 87.14 MB/s 0 B/op 0 allocs/op BenchmarkString_ASCII/clipperhouse/displaywidth-8 54.60 ns/op 2344.32 MB/s 0 B/op 0 allocs/op BenchmarkString_ASCII/mattn/go-runewidth-8 1195 ns/op 107.08 MB/s 0 B/op 0 allocs/op BenchmarkString_ASCII/rivo/uniseg-8 1578 ns/op 81.13 MB/s 0 B/op 0 allocs/op BenchmarkString_EastAsian/clipperhouse/displaywidth-8 5837 ns/op 289.01 MB/s 0 B/op 0 allocs/op BenchmarkString_EastAsian/mattn/go-runewidth-8 24418 ns/op 69.09 MB/s 0 B/op 0 allocs/op BenchmarkString_EastAsian/rivo/uniseg-8 19339 ns/op 87.23 MB/s 0 B/op 0 allocs/op BenchmarkString_Emoji/clipperhouse/displaywidth-8 3225 ns/op 224.51 MB/s 0 B/op 0 allocs/op BenchmarkString_Emoji/mattn/go-runewidth-8 4851 ns/op 149.25 MB/s 0 B/op 0 allocs/op BenchmarkString_Emoji/rivo/uniseg-8 6591 ns/op 109.85 MB/s 0 B/op 0 allocs/op BenchmarkRune_Mixed/clipperhouse/displaywidth-8 3385 ns/op 498.34 MB/s 0 B/op 0 allocs/op BenchmarkRune_Mixed/mattn/go-runewidth-8 5354 ns/op 315.07 MB/s 0 B/op 0 allocs/op BenchmarkRune_EastAsian/clipperhouse/displaywidth-8 3397 ns/op 496.56 MB/s 0 B/op 0 allocs/op BenchmarkRune_EastAsian/mattn/go-runewidth-8 15673 ns/op 107.64 MB/s 0 B/op 0 allocs/op BenchmarkRune_ASCII/clipperhouse/displaywidth-8 255.7 ns/op 500.53 MB/s 0 B/op 0 allocs/op BenchmarkRune_ASCII/mattn/go-runewidth-8 261.5 ns/op 489.55 MB/s 0 B/op 0 allocs/op BenchmarkRune_Emoji/clipperhouse/displaywidth-8 1371 ns/op 528.22 MB/s 0 B/op 0 allocs/op BenchmarkRune_Emoji/mattn/go-runewidth-8 2267 ns/op 319.43 MB/s 0 B/op 0 allocs/op BenchmarkTruncateWithTail/clipperhouse/displaywidth-8 3229 ns/op 54.82 MB/s 192 B/op 14 allocs/op BenchmarkTruncateWithTail/mattn/go-runewidth-8 8408 ns/op 21.05 MB/s 192 B/op 14 allocs/op BenchmarkTruncateWithoutTail/clipperhouse/displaywidth-8 3554 ns/op 64.43 MB/s 0 B/op 0 allocs/op BenchmarkTruncateWithoutTail/mattn/go-runewidth-8 11189 ns/op 20.47 MB/s 0 B/op 0 allocs/op ``` -------------------------------- ### Create a new list with list.New Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Create a new list with three items. ```go l := list.New("A", "B", "C") ``` -------------------------------- ### Load kernel modules for exporter and importer roles Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Required for archive and source installs since packages install persistent module-loading config. Load role-specific modules before starting commands. ```text sudo modprobe usbip_core usbip_host # exporter/server sudo modprobe usbip_core vhci_hcd # importer/client ``` -------------------------------- ### Enable systemd socket activation Source: https://github.com/abilisoft/usbip-go/blob/main/README.md Enables the systemd socket unit for the packaged install. Socket activation starts usbip-go serve on the first inbound connection; see docs/ops.md for package install commands, status, readiness, health checks, logs, and graceful drain rollouts. ```sh sudo systemctl daemon-reload sudo systemctl enable --now usbip-go.socket ``` -------------------------------- ### Use shorthand Border function with ThickBorder and DoubleBorder Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Uses the shorthand Border function to add borders. The boolean arguments specify which sides get the border, in clockwise order starting from top. ```go // Add a thick border to the top and bottom lipgloss.NewStyle(). Border(lipgloss.ThickBorder(), true, false) // Add a double border to the top and left sides. Rules are set clockwise // from top. lipgloss.NewStyle(). Border(lipgloss.DoubleBorder(), true, false, false, true) ``` -------------------------------- ### Import lipgloss list package Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Import the list sub-package to use list rendering. ```go import "charm.land/lipgloss/v2/list" ``` -------------------------------- ### Create and render a roff document in Go Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/muesli/roff/README.md Import the roff package, then create a document and add headings, sections, text, fonts, indentation, and lists. Finally, fetch the document as a string with doc.String() and print it. ```go import "github.com/muesli/roff" ``` ```go doc := roff.NewDocument() doc.Heading(1, "Title", "A short description", time.Now()) // a section of text doc.Section("Introduction") doc.Text("Here is a quick introduction to writing roff documents with Go!") // fonts doc.Section("Fonts") doc.Text("This is a text with a bold font: ") doc.TextBold("I am bold!") doc.Paragraph() doc.Text("This is a text with an italic font: ") doc.TextItalic("I am italic!") // indentation doc.Section("Indentation") doc.Text("This block of text is left-aligned to the section.") doc.Indent(4) doc.Text("This block of text is totally indented.") doc.IndentEnd() doc.Text("... left-aligned again!") // lists doc.Section("Lists") doc.Text("A list:") doc.Paragraph() doc.Indent(4) doc.List("First list item") doc.List("Second list item") ``` ```go fmt.Println(doc.String()) ``` -------------------------------- ### Migrate CompleteColor to compat or Complete Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Shows three ways to define a complete color: v1 with CompleteColor, v2 using the compat package, and v2 using the recommended Complete helper. The Complete helper takes a color profile detected from the environment. ```go // v1 color := lipgloss.CompleteColor{TrueColor: "#ff00ff", ANSI256: "200", ANSI: "5"} // v2 — using compat color := compat.CompleteColor{ TrueColor: lipgloss.Color("#ff00ff"), ANSI256: lipgloss.Color("200"), ANSI: lipgloss.Color("5"), } // v2 — using Complete (recommended) profile := colorprofile.Detect(os.Stdout, os.Environ()) complete := lipgloss.Complete(profile) color := complete(lipgloss.Color("5"), lipgloss.Color("200"), lipgloss.Color("#ff00ff")) ``` -------------------------------- ### Install cobra-cli generator Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/spf13/cobra/README.md Use this command to install the cobra-cli command line program, which generates Cobra applications and command files. ```bash go install github.com/spf13/cobra-cli@latest ``` -------------------------------- ### Migrate from v1 with compat.AdaptiveColor Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Use the compat package to migrate from Lip Gloss v1. It provides AdaptiveColor, CompleteColor, and CompleteAdaptiveColor that look at stdin and stdout globally. Not recommended for new code because it removes purity and can cause resource competition. ```go import "charm.land/lipgloss/v2/compat" color := compat.AdaptiveColor{ Light: lipgloss.Color("#f1f1f1"), Dark: lipgloss.Color("#cccccc"), } ``` -------------------------------- ### Get the terminal screen Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/TUTORIAL.md Gets the terminal's screen, which is used for drawing content, managing the alternate screen buffer, and setting cells. ```go scr := t.Screen() ``` -------------------------------- ### Import the tree sub-package Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Import the tree sub-package to use tree rendering in Lip Gloss. ```go import "charm.land/lipgloss/v2/tree" ``` -------------------------------- ### Use compat package for adaptive colors and customize background detection Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Use the compat package to migrate adaptive colors to v2. The first block shows the v1-to-v2 replacement for AdaptiveColor. The second block customizes the compat package's global background detection and color profile detection, reading stdin/stdout globally like v1. ```go import "charm.land/lipgloss/v2/compat" // v1 color := lipgloss.AdaptiveColor{Light: "#f1f1f1", Dark: "#cccccc"} // v2 color := compat.AdaptiveColor{Light: lipgloss.Color("#f1f1f1"), Dark: lipgloss.Color("#cccccc")} ``` ```go import ( "charm.land/lipgloss/v2/compat" "github.com/charmbracelet/colorprofile" ) func init() { compat.HasDarkBackground = lipgloss.HasDarkBackground(os.Stdin, os.Stderr) compat.Profile = colorprofile.Detect(os.Stderr, os.Environ()) } ``` -------------------------------- ### Usage with flag: Generate man page from standard flag package Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/muesli/mango/README.md Shows how to use mango with Go's standard flag package. It defines two string flags, parses them, creates a man page with a long description and copyright section, and visits all flags to add them to the man page. The final man page is built and printed. ```go import ( "flag" "fmt" "github.com/muesli/mango" "github.com/muesli/mango/mflag" "github.com/muesli/roff" ) var ( one = flag.String("one", "", "first value") two = flag.String("two", "", "second value") ) func main() { flag.Parse() manPage := mango.NewManPage(1, "mango", "a man-page generator"). WithLongDescription("mango is a man-page generator for Go.\n"+ "Features:\n"+ "* User-friendly\n"+ "* Plugable"). WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+ "Released under MIT license.") flag.VisitAll(mflag.FlagVisitor(manPage)) fmt.Println(manPage.Build(roff.NewDocument())) } ``` -------------------------------- ### Run pflag tests Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/spf13/pflag/README.md Run the test suite for the pflag package to verify the installation. ```bash go test github.com/spf13/pflag ``` -------------------------------- ### Calculate monospace width with StringWidth Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/rivo/uniseg/README.md Uses uniseg.StringWidth to compute the monospace string width, yielding 5 for the flag and exclamation example. ```go width := uniseg.StringWidth("🇩🇪🏳️‍🌈!") fmt.Println(width) // 5 ``` -------------------------------- ### Create a default terminal Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/TUTORIAL.md Creates a terminal with default settings. Use this when you don't need to customize the console or options. ```go t := uv.DefaultTerminal() ``` -------------------------------- ### Verify no goroutine leaks in a test with VerifyNone Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/go.uber.org/goleak/README.md Call `defer goleak.VerifyNone(t)` at the start of a test to ensure no unexpected goroutines run at the end of the test. ```go func TestA(t *testing.T) { defer goleak.VerifyNone(t) // test logic here. } ``` -------------------------------- ### Usage with coral: Generate man page from coral command Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/muesli/mango/README.md Shows how to use mango with the coral package. It defines a root command, creates a man page from it, adds a copyright section, and prints the built man page. Errors are handled with panic. ```go import ( "fmt" mcoral "github.com/muesli/mango-coral" "github.com/muesli/roff" "github.com/muesli/coral" ) var ( rootCmd = &coral.Command{ Use: "mango", Short: "A man-page generator", } ) func main() { manPage, err := mcoral.NewManPage(1, rootCmd) if err != nil { panic(err) } manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+ "Released under MIT license.") fmt.Println(manPage.Build(roff.NewDocument())) } ``` -------------------------------- ### Enable systemd socket Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Commands to reload systemd and enable the socket unit, which starts the daemon on the first inbound connection rather than at boot. ```text sudo systemctl daemon-reload sudo systemctl enable --now usbip-go.socket ``` -------------------------------- ### Grant sysfs capabilities with setcap Source: https://github.com/abilisoft/usbip-go/blob/main/docs/security.md Grant the sysfs capabilities required by usbip-go to a dedicated user. Run this as root before starting the daemon under the usbip-go system user. ```text sudo setcap 'cap_sys_admin,cap_dac_override=+ep' /usr/bin/usbip-go ``` -------------------------------- ### Inherit unset rules with Style.Inherit Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Use Inherit to copy only unset rules from another style. In this example, styleB already sets its foreground, so only the background from styleA is inherited. ```go var styleA = lipgloss.NewStyle(). Foreground(lipgloss.Color("229")). Background(lipgloss.Color("63")) // Only the background color will be inherited here, because the foreground // color will have been already set: var styleB = lipgloss.NewStyle(). Foreground(lipgloss.Color("201")). Inherit(styleA) ``` -------------------------------- ### Create a nested list with list.New Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Create a nested list with sublists for each item. ```go l := list.New( "A", list.New("Artichoke"), "B", list.New("Baking Flour", "Bananas", "Barley", "Bean Sprouts"), "C", list.New("Cashew Apple", "Cashews", "Coconut Milk", "Curry Paste", "Currywurst"), "D", list.New("Dill", "Dragonfruit", "Dried Shrimp"), "E", list.New("Eggs"), "F", list.New("Fish Cake", "Furikake"), "J", list.New("Jicama"), "K", list.New("Kohlrabi"), "L", list.New("Leeks", "Lentils", "Licorice Root"), ) ``` -------------------------------- ### Print a list with lipgloss.Println Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Print the list and shows the default bullet output. ```go lipgloss.Println(l) // • A // • B // • C ``` -------------------------------- ### Measure text block dimensions with lipgloss.Width, Height, Size Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Measures the width and height of rendered text blocks. Uses lipgloss.Width, lipgloss.Height, and lipgloss.Size to get dimensions. ```go // Render a block of text. var style = lipgloss.NewStyle(). Width(40). Padding(2) var block string = style.Render(someLongString) // Get the actual, physical dimensions of the text block. width := lipgloss.Width(block) height := lipgloss.Height(block) // Here's a shorthand function. w, h := lipgloss.Size(block) ``` -------------------------------- ### Get flag value with GetInt Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/spf13/pflag/README.md Retrieve the integer value of a flag from a FlagSet using GetInt. The flag must exist and be of type int; otherwise GetInt will fail. ```go i, err := flagset.GetInt("flagname") ``` -------------------------------- ### Use lipgloss.Println for output Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Replace fmt.Println with lipgloss.Println to enable automatic color downsampling. If using Bubble Tea v2, this step is unnecessary because Bubble Tea handles it. ```go // v1 fmt.Println(s) // v2 lipgloss.Println(s) ``` -------------------------------- ### Background detection and adaptive colors (v1 vs v2) Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md In v2, background detection requires explicit input and output streams. Use the returned boolean with LightDark to pick foreground colors. ```go // v1 hasDark := lipgloss.HasDarkBackground() // v2 — specify the input and output hasDark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout) ``` ```go lightDark := lipgloss.LightDark(hasDark) fg := lightDark(lipgloss.Color("#333333"), lipgloss.Color("#f1f1f1")) s := lipgloss.NewStyle().Foreground(fg) ``` -------------------------------- ### GET / Source: https://github.com/abilisoft/usbip-go/blob/main/docs/json-schema.md Retrieves the daemon status as a JSON object. The response includes schema version, version, commit, uptime, listening state, bound devices, sessions, and kernel module status. ```APIDOC ## GET / ### Description Retrieves the daemon status as a JSON object. The response includes schema version, version, commit, uptime, listening state, bound devices, sessions, and kernel module status. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **schema** (string) - The schema version, e.g., "v1". - **version** (string) - The daemon version, e.g., "X.Y.Z". - **commit** (string) - The short commit SHA. - **uptime_sec** (integer) - Uptime in seconds. - **listening** (object) - Listening state details. - **addr** (string) - The listening address, e.g., "0.0.0.0:3240". - **activation** (boolean) - Indicates socket-activated startup vs plain --listen bind. - **accepting** (boolean) - True when the accept loop is armed, false when Serve returns. - **bound_devices** (array) - List of bound devices. - **busid** (string) - The bus ID of the device. - **vid** (string) - The vendor ID, e.g., "0x0951". - **pid** (string) - The product ID, e.g., "0x1666". - **bound_devices_error** (string, optional) - Diagnostic text when bound-device listing fails. Omitted on happy path. - **sessions** (array) - List of session objects. Each session uses the same field names and formats as session watch records: `id` is the canonical UUIDv7 form and `started_at` is RFC 3339 nano UTC. - **kernel_modules** (object) - Kernel module status. - **usbip_core** (string) - One of "loaded", "missing", "unknown". - **vhci_hcd** (string) - One of "loaded", "missing", "unknown". - **usbip_host** (string) - One of "loaded", "missing", "unknown". #### Response Example ```json { "schema": "v1", "version": "X.Y.Z", "commit": "", "uptime_sec": , "listening": { "addr": "0.0.0.0:3240", "activation": true, "accepting": true }, "bound_devices": [ { "busid": "1-1.2", "vid": "0x0951", "pid": "0x1666" } ], "bound_devices_error": "optional diagnostic text when bound-device listing fails", "sessions": [ sessionJSON ], "kernel_modules": { "usbip_core": "loaded", "vhci_hcd": "loaded", "usbip_host": "loaded" } } ``` ``` -------------------------------- ### displaywidth.Options Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/clipperhouse/displaywidth/README.md Options struct for configuring display width calculations, with methods for String, Bytes, and Rune. ```APIDOC ## displaywidth.Options ### Description Options struct for configuring display width calculations, with methods for String, Bytes, and Rune. ### Fields - **EastAsianWidth** (bool) - Optional - When true, East Asian Ambiguous characters are treated as width 2; when false (default), width 1. - **ControlSequences** (bool) - Optional - When true, ECMA-48 escape sequences are treated as a single zero-width unit; when false (default), treated as a series of characters. - **ControlSequences8Bit** (bool) - Optional - When true, 8-bit ECMA-48 escape sequences are treated as a single zero-width unit; when false (default), treated as a series of characters. Ignored by Truncate methods. ### Methods #### String Returns the display width of a string using the options. Signature: `func (o Options) String(s string) int` Parameters: - **s** (string) - Required - The string to measure. Return Value: - **int** - The display width. Example: ```go var myOptions = displaywidth.Options{ EastAsianWidth: true, ControlSequences: true, } width := myOptions.String("Hello, 世界!") ``` ``` -------------------------------- ### ANSI 16 color profile examples Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/README.md Creates colors using the ANSI 16 (4-bit) color profile. The string argument is the ANSI color number; comments show the resulting color names. ```go lipgloss.Color("5") // magenta lipgloss.Color("9") // red lipgloss.Color("12") // light blue ``` -------------------------------- ### Sessions list envelope (status socket) Source: https://github.com/abilisoft/usbip-go/blob/main/docs/json-schema.md Returned by the daemon status UDS via `GET /` over the path configured with `--status-socket`. The CLI does not have a `status` subcommand. Contains a `sessions` array of `sessionView` objects. ```json { "schema": "v1", "sessions": [ sessionView, ... ] } ``` -------------------------------- ### Migrate AdaptiveColor to compat or LightDark Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Shows three ways to define an adaptive color: v1 with AdaptiveColor, v2 using the compat package, and v2 using the recommended LightDark helper. Note that compat.AdaptiveColor and friends take color.Color values for their fields, not strings. ```go // v1 color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"} // v2 — using compat (quick path) color := compat.AdaptiveColor{ Light: lipgloss.Color("#0000ff"), Dark: lipgloss.Color("#000099"), } // v2 — using LightDark (recommended) hasDark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout) lightDark := lipgloss.LightDark(hasDark) color := lightDark(lipgloss.Color("#0000ff"), lipgloss.Color("#000099")) ``` -------------------------------- ### Create and push signed annotated release tag Source: https://github.com/abilisoft/usbip-go/blob/main/CONTRIBUTING.md Use to start a release from a clean, up-to-date default branch. Creates a signed annotated tag, verifies it, and pushes it to origin. The tag push triggers the Release workflow. ```sh git switch main git pull --ff-only git tag -s vX.Y.Z -m 'Release vX.Y.Z' git tag -v vX.Y.Z git push origin refs/tags/vX.Y.Z ``` -------------------------------- ### usbip-go.service unit file Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Systemd service unit that starts the usbip-go daemon, loads the required kernel modules via ExecStartPre, and specifies the runtime directory and security capabilities. The unit is intended to be customized via drop-ins. ```ini [Unit] Description=USB/IP (Go) daemon Requires=usbip-go.socket After=systemd-modules-load.service [Service] Type=simple ExecStartPre=-/sbin/modprobe usbip_core ExecStartPre=-/sbin/modprobe usbip_host ExecStart=/usr/bin/usbip-go serve Restart=on-failure RuntimeDirectory=usbip-go RuntimeDirectoryMode=0755 CapabilityBoundingSet=CAP_SYS_ADMIN CAP_DAC_OVERRIDE CAP_CHOWN [Install] WantedBy=multi-user.target ``` -------------------------------- ### Architecture layers diagram Source: https://github.com/abilisoft/usbip-go/blob/main/docs/architecture.md Shows the layered architecture of usbip-go, from command entrypoints down to adapter packages. Use it to understand the top-down dependency flow and which packages are allowed to import from internal/. ```text +-------------------------+ cmd/usbip-go, examples/* | Command entrypoints | +-----------+-------------+ | v +-------------------------+ pkg/usbip (stable public facade) | Public Go surface | pkg/domain (value objects, events, errors) +-----------+-------------+ | v +-------------------------+ internal/app (use-case services: | Application services | Importer, Exporter, watchers) +-----------+-------------+ Declares the adapter interfaces. | v +-------------------------+ internal/adapter/kernel (sysfs + netlink, Linux) | Adapter layer | internal/adapter/wire (USB/IP protocol codec) +-------------------------+ internal/adapter/transport (net.Dial / net.Listen) ``` -------------------------------- ### Underline style and color in v2 Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/charm.land/lipgloss/v2/UPGRADE_GUIDE_V2.md Shows the v1 and v2 usage of Underline and the new UnderlineStyle and UnderlineColor methods. Underline(true) is equivalent to UnderlineStyle(UnderlineSingle) and Underline(false) to UnderlineStyle(UnderlineNone). ```go // v1 s := lipgloss.NewStyle().Underline(true) // v2 — still works s := lipgloss.NewStyle().Underline(true) // v2 — new: specific styles s := lipgloss.NewStyle().UnderlineStyle(lipgloss.UnderlineCurly) // v2 — new: colored underlines s := lipgloss.NewStyle(). UnderlineStyle(lipgloss.UnderlineSingle). UnderlineColor(lipgloss.Color("#FF0000")) ``` -------------------------------- ### Reconcile exporter device after kernel session handoff Source: https://github.com/abilisoft/usbip-go/blob/main/docs/ops.md Writes the value -1 to the usbip_sockfd sysfs file for a specific bus ID to reconcile the kernel session. Necessary after a drain to release a claimed or used state before starting replacement traffic. ```text printf '%s' -1 | sudo tee /sys/bus/usb/devices/BUSID/usbip_sockfd ``` -------------------------------- ### Create a terminal with custom console and options Source: https://github.com/abilisoft/usbip-go/blob/main/vendor/github.com/charmbracelet/ultraviolet/TUTORIAL.md Creates a terminal with a custom console and options. The Logger field is optional and used for debugging I/O. ```go con := uv.NewConsole(os.Stdin, os.Stdout, os.Environ()) t := uv.NewTerminal(con, &uv.Options{ Logger: myLogger, // optional, for debugging I/O }) ```