1 home
liquibyte edited this page 2026-11-19 16:23:31 -06:00

Hanshi Documentation

The user manual of Hanshi, a terminal for X11. This page says what Hanshi is, how to build and install it, how to start it, and what happens the first time it runs. Then it takes you on a short tour, and lists the other pages of the manual.

What Hanshi is

Hanshi is a terminal: one window with your shell in it, tabs when you want more than one shell, and a Preferences dialog for everything you can change. The terminal itself is Hosho, a terminal library that is built into Hanshi. Hosho keeps the screen that a program expects, and its widget draws that screen with Xtk, the toolkit that also draws the window, the menus and the dialogs. Hanshi is the window around the widget, the settings and the command line.

  • A complete terminal. Hosho answers as a DEC VT420 with color and has the control sequences of xterm, the keyboard protocol and the graphics protocol of kitty, the inline images of iTerm2, sixel pictures, hyperlinks, and right-to-left text. Terminal Features lists each feature and the terminal or the specification it follows.
  • It knows your shell. With shell integration, which needs no change to your own files for bash, zsh, fish, ksh93, mksh, OpenBSD's ksh, dash and sh, each prompt gets a mark in the color of its command's result. You can jump from prompt to prompt, select or hide the output of one command, and get a notification when a long command ends while you work in another window.
  • Tabs that tell you what happens in them. The label of a tab you cannot see turns blue while a command runs in it, and green or red when the command ends.
  • Every setting is live. A change in Preferences shows at once, and a terminal theme file you edit is read again as soon as you save it.
  • Pictures in a jail. What a program prints can come from anyone, so every picture file, sixel picture and compressed picture a program sends is taken apart in a separate process that can read, write and reach nothing (Safety).

Building Hanshi

Hanshi is built from source with make. Hosho and the parts of Xtk that Hanshi uses are already in the source tree (the folders hosho/ and xtk/) and are compiled straight into the program, so there are no other projects to install first.

You need a C compiler that understands -std=gnu17 (GCC or Clang), make, pkg-config, and the development files of these X11 libraries: X11, Xrender, Xft, fontconfig, freetype, Xcursor, Xext and Xpm. On Debian and Ubuntu, for example:

sudo apt install build-essential pkg-config libx11-dev libxrender-dev libxft-dev \
    libfontconfig-dev libfreetype-dev libxcursor-dev libxext-dev libxpm-dev

Then, in the source folder:

Command What it does
make Builds the program ./hanshi. The build treats every warning as an error.
make install Installs the program to /usr/bin/hanshi and its files to /usr/share/hanshi (see below). Use PREFIX=/usr/local to install elsewhere, and DESTDIR=... to stage the install for a package.
make clean Removes the build folder and the program.

Installing and running

You can run Hanshi straight from the source folder with ./hanshi, or install it with make install. Hanshi looks for its files beside the program, then one folder up, then in <prefix>/share/hanshi. make install puts these folders there:

Folder What is in it
shell/ The shell integration files, one for each kind of shell (Shell Integration). Without this folder, shell integration is off.
themes/ The four built-in terminal themes as files, to copy from when you write your own (Themes). Hanshi does not read them from here: the built-in themes are part of the program.
icons/ The icon of the question that Hanshi asks before it closes a terminal with a running program.

make install also adds Hanshi to your desktop's application menu: it puts hanshi.desktop in /usr/share/applications, and the icon in each of its sizes (16 to 256 pixels) and as an SVG in the hicolor icon theme (/usr/share/icons/hicolor) as hanshi. With another PREFIX, these go under that prefix's share folder. When you run Hanshi from the source folder, copy hanshi.desktop to ~/.local/share/applications/ to have it in the menu. The window carries its own icon, so a window manager or task bar shows it either way.

The command line

hanshi [-r rows] [-c columns] [-d directory] [-e] [program [argument...]]
Option What it does
-r rows The number of lines of text, in place of the number in Preferences. A number below 1 is ignored.
-c columns The number of characters in a line, in place of the number in Preferences. A number below 2 is ignored.
-d directory The folder the program starts in. A new tab also starts there when the folder of the tab you were in is not known. When the folder cannot be used, the program starts in the current folder.
-e The last option, as in xterm (xterm -e program): everything after it is the program and its arguments, also words that start with -, so hanshi -e -weird-name runs a program of that name. -e must be a word of its own, and a program must follow it; otherwise Hanshi prints the options and ends with the status 2.
-v Prints the version of Hanshi and of Hosho, for example Hanshi 1.4 (Hosho 1.3), and ends.
-h Prints the options, where the settings are kept, and the keys of the tabs, and ends.

The first word that is not an option is the program to run, and everything after it is that program's own, so hanshi vim -c 'set number' file.c gives -c to vim, not to Hanshi. With no program, Hanshi runs the command of Preferences > Programs, or your shell when that is empty (Preferences). Your shell is the one $SHELL names (when it is a full path), then the one of your entry in the password database, then /bin/sh.

  • A size given with -r or -c is for this window only: it is not remembered, even when "Remember the window's size" is on.
  • The window closes when its last program ends. Hanshi then ends with that program's exit status, so hanshi make can be used in a script. A program that was ended by a signal gives the status 0.
  • When the program is not found or cannot be run, the window closes at once and Hanshi ends with the status 127, as a shell does. When the terminal itself cannot be made, Hanshi prints why and ends with the status 1. When the display cannot be opened, it prints "can't open the display" and ends with the status 1. An unknown option prints the options and ends with the status 2.
  • Each start of Hanshi is one window. To have more terminals in one window, use tabs (The Window and Tabs).

The first run

Hanshi keeps its files in ~/.config/hanshi (or in $XDG_CONFIG_HOME/hanshi when that variable is a full path):

In ~/.config/hanshi What it is
hanshi.conf Your settings. Hanshi writes it when Preferences closes with OK, and when it ends while "Remember the window's size" is on and the size changed. Until then the file does not exist and every setting has its default (Preferences).
themes/ The window themes: the colors of the scrollbar, the menu, the tabs and the dialogs. At every start, Hanshi writes each of its 14 built-in window themes that is missing from this folder, so a built-in theme you delete comes back (Themes).
Your terminal themes A terminal theme file you name in Preferences with no folder in its name is looked for here.

The first window has 24 rows and 80 columns, the Dark window theme and the Hosho Dark terminal theme, with shell integration and tabs on.

A short tour

  1. Start Hanshi. Your shell starts in the window. When shell integration works, a small grey mark appears in the margin at the left of the prompt.
  2. Type true and press Return: the mark of that prompt turns green. Type false: it turns red. Press Ctrl+Shift+Up to go back from prompt to prompt.
  3. Run ls -l /usr/bin, then click the mark of its prompt: the command's output is selected. Double-click the mark: the output is hidden, and the prompt's line says how many lines it hides. Double-click again to show it.
  4. Press Ctrl+Shift+F and type a word: the matches in the scrollback are marked. Enter goes to the older match, Shift+Enter to the newer one, and Escape closes the search.
  5. Press Ctrl+Shift+T for a second tab; it starts in the folder of the first. Run sleep 10 in it, and go back to the first tab with Ctrl+Page Up: the label of the second tab is blue, then green when the command ends.
  6. Click the right mouse button for the terminal's menu, and choose Preferences (or press Ctrl+Shift+P). Choose another terminal theme on the Appearance page and click Apply.

Keyboard and Mouse lists every key and every use of the mouse.

The parts of Hanshi

The parts of Hanshi and the manual page for each: the Hanshi process with the window and its tabs, the terminal, the keys, Preferences, themes, shell integration and the terminal's features, the programs it runs on a pseudoterminal, and the jailed worker that takes pictures apart

Each box with a page links to it. The box with a red border runs in a jail: Hanshi hands it the bytes of a picture and checks the pixels it gets back before it shows them.

The pages of the manual

  • The Window and Tabs

    The window, its title and its size; tabs, their labels and their colors; closing a tab or the window; the terminal's menu; the bell, notifications and links.

  • Using the Terminal

    Selecting, copying and pasting; the scrollback and the search; links; prompt marks and command output; the font size; pictures, emoji and right-to-left text; what a program can show you.

  • Keyboard and Mouse

    Every key of Hanshi and of the terminal, every use of the mouse, and the keys a program receives: the keyboards Hanshi can imitate, Alt and modifiers, the kitty keyboard protocol.

  • Preferences

    Every page of the Preferences dialog, each control on it, and its key in hanshi.conf.

  • Themes

    The window themes and the terminal themes, the four built-in terminal themes, and how to write a terminal theme file: colors, the palette, attribute styles and rules.

  • Shell Integration

    What the prompt marks do, how Hanshi loads the integration for each shell, what each shell can tell the terminal, and how to use the files in another terminal.

  • Terminal Features

    Feature by feature: the control sequences, modes, reports, colors, keyboard and mouse protocols, pictures, hyperlinks and the clipboard, with the terminal or specification each one follows.

  • Safety

    The jail that takes pictures apart, what a program in the terminal may and may not do, the paste question, and what a program gets from Hanshi when it starts.