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

Experience of internship opportunity at LetsGrowMore

On-Premises Disaster Site Recovery Strategy with Azure VM

Automating Instance Initialization with Terraform on Oracle Cloud Infrastructure: Part 2

Flutter vs. React Native vs. Xamarin- which one is best?

Azure Kubernetes Service Case Study : Carbon

Importance of Agile Development Methodology

Provisioning AWS Infrastructure Using Terraform (VPC, Private subnet, ALB, ASG)

CS373 Spring 2021 — Maria “Fina” Sierra

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

iTerm2 integrated with tmux

My vim configuration.

Neovim with LSP

Create A Vim Plugin For Your Next Programming Language, Indentation and Autocomplete