Skip to content

Instantly share code, notes, and snippets.

@aslafy-z
Last active February 27, 2026 16:15
Show Gist options
  • Select an option

  • Save aslafy-z/30fa373e2dd8b46959616f658d8eaf5a to your computer and use it in GitHub Desktop.

Select an option

Save aslafy-z/30fa373e2dd8b46959616f658d8eaf5a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
echo "=== tcell iLO keyboard test (Debian, pinned tcell v2.9.0) ==="
# ---- apt helpers (skip update errors) ----
apt_update() {
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update || true
fi
}
apt_install() {
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get install -y --no-install-recommends "$@"
fi
}
echo "[*] Installing base dependencies..."
apt_update
apt_install git curl ca-certificates
# ---- ensure Go >= 1.22 (Debian may ship 1.19) ----
need_go="1.22.0"
go_install_dir="${HOME}/.local/go"
go_root="${go_install_dir}/go"
ver_ge() {
# returns 0 if $1 >= $2
[ "$(printf '%s\n%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ]
}
current_go_ver="0.0.0"
if command -v go >/dev/null 2>&1; then
current_go_ver="$(go version | awk '{print $3}' | sed 's/^go//')"
fi
if ! command -v go >/dev/null 2>&1 || ! ver_ge "${current_go_ver}" "${need_go}"; then
arch="$(uname -m)"
case "${arch}" in
x86_64|amd64) go_arch="amd64" ;;
aarch64|arm64) go_arch="arm64" ;;
*)
echo "[!] Unsupported arch: ${arch}"
exit 1
;;
esac
# Pin a known good >= 1.22 toolchain
go_version="1.22.6"
go_tgz="go${go_version}.linux-${go_arch}.tar.gz"
go_url="https://go.dev/dl/${go_tgz}"
echo "[*] Installing Go ${go_version}..."
rm -rf "${go_root}"
mkdir -p "${go_install_dir}"
curl -fsSL "${go_url}" -o "${go_install_dir}/${go_tgz}"
tar -C "${go_install_dir}" -xzf "${go_install_dir}/${go_tgz}"
rm -f "${go_install_dir}/${go_tgz}"
fi
# ---- PATH overrides (force using ~/.local/go/go/bin) ----
export GOROOT="${go_root}"
export PATH="${GOROOT}/bin:${PATH}"
echo "[*] Using Go: $(go version)"
echo "[*] GOROOT=${GOROOT}"
# ---- workspace ----
WORKDIR="$(mktemp -d)"
cd "$WORKDIR"
echo "[*] Working directory: $WORKDIR"
# ---- create Go module (pin tcell v2.9.0) ----
cat <<'EOF' > go.mod
module tcell-test
go 1.22
require github.com/gdamore/tcell/v2 v2.9.0
EOF
# ---- test program ----
cat <<'EOF' > main.go
package main
import (
"fmt"
"os"
"github.com/gdamore/tcell/v2"
)
func main() {
screen, err := tcell.NewScreen()
if err != nil {
fmt.Println("screen error:", err)
os.Exit(1)
}
if err := screen.Init(); err != nil {
fmt.Println("init error:", err)
os.Exit(1)
}
defer screen.Fini()
style := tcell.StyleDefault
drawLine := func(text string) {
w, _ := screen.Size()
screen.Clear()
for i, r := range text {
if i >= w {
break
}
screen.SetContent(i, 0, r, nil, style)
}
screen.Show()
}
drawLine("tcell v2.9.0 - Press F1-F12 in iLO. Press q to quit.")
for {
ev := screen.PollEvent()
switch e := ev.(type) {
case *tcell.EventKey:
if e.Key() == tcell.KeyRune && e.Rune() == 'q' {
return
}
line := fmt.Sprintf("Key=%v Name=%s Rune=%q Mod=%v", e.Key(), e.Name(), e.Rune(), e.Modifiers())
drawLine(line)
case *tcell.EventResize:
screen.Sync()
}
}
}
EOF
echo "[*] Fetching deps (pinned tcell v2.9.0)..."
go mod tidy
echo "[*] Building..."
go build -o tcell-test
echo "[*] Verifying tcell version in module graph..."
# This prints the exact resolved version of tcell/v2 (should be v2.9.0).
go list -m all | awk '$1=="github.com/gdamore/tcell/v2"{print "[*] Using",$1,$2}'
echo "[*] Launching test..."
sleep 1
./tcell-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment