<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz" -->

---
title: How TUI Navigation Works on the Inside | daily.dev
description: A hands-on walkthrough of how TUI (terminal user interface) navigation works internally, written in Go. Covers setting the terminal to raw mode using...
canonical: https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How TUI Navigation Works on the Inside | daily.dev
og:description: A hands-on walkthrough of how TUI (terminal user interface) navigation works internally, written in Go. Covers setting the terminal to raw mode using...
og:url: https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz
og:image: https://api.daily.dev/og/posts/emytAweSz.png
og:image:alt: How TUI Navigation Works on the Inside
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How TUI Navigation Works on the Inside

**[Medium](https://daily.dev/sources/medium_js)** · 8 min read · 0 upvotes · 0 comments

## Summary

A hands-on walkthrough of how TUI (terminal user interface) navigation works internally, written in Go. Covers setting the terminal to raw mode using golang.org/x/term to capture individual keystrokes, rendering menu options using ANSI escape sequences, implementing a cursor with bracket notation, and handling horizontal navigation with vim-style hjkl keybindings. Explains key mechanics like carriage return for in-place redraw, line-clearing escape sequences, and bounds-checked cursor movement — all without relying on a TUI framework.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@cheezecake/how-tui-navigation-works-on-the-inside-f2369154e02d>

## Questions this post answers

### How do I read individual keystrokes in Go without waiting for Enter to be pressed?

Put the terminal into raw mode using term.MakeRaw from golang.org/x/term, passing os.Stdin.Fd() (usually 0 on Unix systems). This disables the terminal's normal line buffering so each keypress is sent immediately. Read a single byte at a time into a 1-byte slice with os.Stdin.Read, and restore the original terminal state with term.Restore when done, typically via defer.

_daily.dev surfaces Go terminal-handling techniques for developers building their own TUI tools._

### How do I redraw a terminal menu in place instead of printing a new line every time the cursor moves?

Use the carriage return escape character \r to move the cursor back to the start of the line before reprinting, and \033[K to clear from the cursor to the end of the line so leftover characters from a shorter previous render don't remain visible. Terminals only write forward from the current position, so without these two steps every update prints a new line instead of overwriting the old one.

_developers refining terminal rendering logic can find more Go ANSI escape sequence tricks on daily.dev._

## Similar posts on daily.dev

- [TUIgo: A terminal UI framework for Go that refuses to be a React port](https://daily.dev/posts/tuigo-a-terminal-ui-framework-for-go-that-refuses-to-be-a-react-port-t3aeslbbk) · Medium · 1 upvotes · 0 comments
- [The text mode lie: why modern TUIs are a nightmare for accessibility](https://daily.dev/posts/the-text-mode-lie-why-modern-tuis-are-a-nightmare-for-accessibility-dajyzn838) · Lobsters · 1 upvotes · 0 comments
- [I Made a Terminal Pager](https://daily.dev/posts/i-made-a-terminal-pager-lytkbuklb) · Hacker News · 21 upvotes · 0 comments
- [ZeroTUI Code Editor: Build Real Terminal Software, Not Just Terminal Screens](https://daily.dev/posts/zerotui-code-editor-build-real-terminal-software-not-just-terminal-screens-sahkt5wif) · Medium · 1 upvotes · 0 comments

---

Tags: [#golang](https://daily.dev/tags/golang), [#cli](https://daily.dev/tags/cli)

[View this post on daily.dev](https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How TUI Navigation Works on the Inside","url":"https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz"},"datePublished":"2026-07-21T07:35:26.757Z","dateModified":"2026-09-14T09:09:37.161Z","description":"A hands-on walkthrough of how TUI (terminal user interface) navigation works internally, written in Go. Covers setting the terminal to raw mode using...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d6ab0a9a223ee01bc82d647f54feb2d2?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d6ab0a9a223ee01bc82d647f54feb2d2?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"golang,cli","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"How TUI Navigation Works on the Inside"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-tui-navigation-works-on-the-inside-emytawesz#faq","mainEntity":[{"@type":"Question","name":"How do I read individual keystrokes in Go without waiting for Enter to be pressed?","acceptedAnswer":{"@type":"Answer","text":"Put the terminal into raw mode using term.MakeRaw from golang.org/x/term, passing os.Stdin.Fd() (usually 0 on Unix systems). This disables the terminal's normal line buffering so each keypress is sent immediately. Read a single byte at a time into a 1-byte slice with os.Stdin.Read, and restore the original terminal state with term.Restore when done, typically via defer. daily.dev surfaces Go terminal-handling techniques for developers building their own TUI tools."}},{"@type":"Question","name":"How do I redraw a terminal menu in place instead of printing a new line every time the cursor moves?","acceptedAnswer":{"@type":"Answer","text":"Use the carriage return escape character \\r to move the cursor back to the start of the line before reprinting, and \\033[K to clear from the cursor to the end of the line so leftover characters from a shorter previous render don't remain visible. Terminals only write forward from the current position, so without these two steps every update prints a new line instead of overwriting the old one. developers refining terminal rendering logic can find more Go ANSI escape sequence tricks on daily.dev."}}]}
```

