The internal of go-prompt: How to control the rich terminal UI (Part I).
  • Part I A brief history of terminals. What is VT-100 escape sequences? How do we get the window size of terminal emulators?
  • Part II What is raw-mode. How to emulate the buffer information of the Terminal. (still not published)
  • Part III Re-thinking the design of components of go-prompt for v1.0.0. (still not published)

A brief history of the terminal.

Image refers from
  • Carriage Return(CR): Reset the printhead to the beginning of a line.
  • Line Feed (LF): Turned the wheel to move the paper to change the line.
Image refers from

VT100 escape sequences

Change the terminal color
  • \x1b[ : control sequence introducer
  • 4;30;46 : parameters which separated by a semi-colon. 4 means underline, 30 means set foreground color Black and 46 means set background color Cyan.
  • m : a final character (which is always one character).

How to get a window size of the Terminal emulator.

type winsize struct {
Row uint16
Col uint16
X uint16
Y uint16

func getWinSize(fd int) (row, col uint16, err error) {
var ws *winsize
retCode, _, errno := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd),
if int(retCode) == -1 {
return ws.Row, ws.Col, nil
Spread the progress bar with the window column size.
This program has a problem that it doesn’t follow the changes of window size.
Follow the changes of window size

What you’ll learn next?





Creator of go-prompt and kube-prompt. Optuna committer. Kubeflow/Katib reviewer. GitHub: c-bata

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Open Source Startup: Part 1 — The idea

This Is The Best Go (Golang) Cheat Sheet!

UIKit No Storyboard: 3 ‘BASIC’ Techniques for Adapting Layouts and Designs

The Essential Guide to SEO for Web Developers

Laptop displaying a home page

How to Run Apache Airflow using WSL without Docker on Windows

How to Set Up Apache Mesos on Ubuntu Server AWS EC2

Rollback lambda + API gateway in 5 minutes

Welcome musketeers!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Creator of go-prompt and kube-prompt. Optuna committer. Kubeflow/Katib reviewer. GitHub: c-bata

More from Medium

Improve terminal workflow with aliases on macOS

Command Shortcuts — Simple Productivity booster for Linux

Auto-completion for Bash CLI

Install Docker and Docker Compose on Linux