-- Showcase of the tui terminal-control functions and markup action tags: -- inline redraws, the alternate screen, absolute cursor addressing, scroll -- regions. Needs a real terminal — piped, everything degrades to no-ops. -- -- Run with: cargo run -- lua/tui_term.lua tui.setTitle("tui terminal demo") ---------------------------------------------------------------------- -- 1. Inline progress: redraw one line with the action tag ---------------------------------------------------------------------- for i = 1, 30 do tui.raw(tui.styled(("working %d/30 %s"):format(i, ("#"):rep(i)))) os.sleep(0.03) end tui.raw(tui.styled("")) tui.success("progress loop finished") ---------------------------------------------------------------------- -- 2. Full-screen: alternate screen + absolute cursor addressing ---------------------------------------------------------------------- tui.altScreen(true) tui.clearScreen() tui.showCursor(false) local info = tui.screenInfo() local w, h = info.width or 80, info.height or 24 tui.moveTo(2, 3) tui.raw(tui.styled(("alternate screen — %dx%d cells"):format(w, h))) -- A little box drawn with moveTo. for row = 4, 8 do tui.moveTo(row, 3) if row == 4 or row == 8 then tui.raw("+" .. ("-"):rep(20) .. "+") else tui.raw("|" .. (" "):rep(20) .. "|") end end tui.moveTo(6, 6) tui.raw(tui.styled("boxed content")) tui.moveTo(10, 3) tui.raw("where is the cursor? ") local row, col = tui.cursorPos() tui.raw(tui.styled(("at row %s, col %s"):format(tostring(row), tostring(col)))) tui.moveTo(12, 3) tui.raw("back to the normal screen in 2 seconds...") os.sleep(2) tui.altScreen(false) tui.showCursor(true) print("back — scrollback intact.") ---------------------------------------------------------------------- -- 3. Scroll region: log lines scrolling under a fixed header ---------------------------------------------------------------------- print() print(tui.styled("FIXED HEADER (lines below scroll, this one stays)")) local top = select(1, tui.cursorPos()) if top then tui.scrollRegion(top, top + 5) for i = 1, 15 do tui.moveTo(top + 5, 1) tui.raw(("\nlog line %d"):format(i)) os.sleep(0.1) end tui.scrollRegion() tui.moveTo(top + 6, 1) end print("scroll region reset.") -- Deliberately no title restore: the runtime pops the pushed title (and -- would also leave the alt screen / re-show the cursor) on exit.