Skip to content

Reading Files

xnano reads a file and shows it in the way that suits its kind. You use it from the command line, or from a program.

Read a file from the command line

Give the xnano command the path of a file.

xnano README.md

On a terminal, the file opens in a viewer. In a pipe or in a file, xnano prints the document as plain text.

xnano data.json | head
Kind of file What you see
Markdown Headings, lists, quotes, code, tables, links and images, laid out.
JSON Indented data, with a color for each kind of value.
.csv and .tsv A table. Its header stays in view while you scroll.
PDF The text of each page. This needs pip install "xnano[pdf]".
A picture The picture. This needs pip install "xnano[image]".
A sound Its length and sample rate, and space plays it. This needs pip install "xnano[audio]".
Other text The text with line numbers.
Other data The bytes, up to 16 in each line.

If xnano cannot show an image or play a sound, it names the image or the sound in text. The rest of the document stays readable.

These options change what the command does:

Option What it does
-p, --print Prints the document and leaves, also on a terminal.
-w CELLS, --width CELLS Sets the width of the printed document.
-t NAME, --theme NAME Chooses the colors. See Themes.

Use the viewer

The last line of the viewer shows its keys. Each key on that line is also a button for the mouse.

Key What it does
↑ ↓, j k Scroll one line.
space, page down, b, page up Scroll one page. For a sound, space plays or stops it.
g, G Go to the start or the end.
/ Find text. n and N go to the next and the previous match.
o List the headings. enter goes to the chosen heading.
r Show the source of the document, or the laid out document.
backspace Go back to the file that you came from.
q Leave.

The wheel scrolls, and a drag on the document or on the bar at the right edge scrolls too. A click on a link to a heading goes to the heading. A click on a link to another file opens that file.

Read a file from a program

xnano.view() does what the command does.

import xnano

xnano.view('README.md', theme='xnano-night')

When the program has no terminal, view() prints the document. To print on a terminal too, pass interactive=False.

Write Markdown on a canvas

xnano.from_markdown() lays Markdown out as styled text. Write it on a canvas like any other text.

import xnano

with xnano.new(width=40, height=6) as canvas:
    canvas.write(xnano.from_markdown('# Notes\n\nA **bold** word.', width=40))
    print(canvas.render())

Themes

A theme sets the colors of the document. Without a theme, the document uses the colors of your terminal, so it follows the theme that you chose there. A theme draws its own colors.

The same names work for any canvas: xnano.open(theme='dracula') colors the text, the borders and the widgets of a program. See Styling.

Theme Colors by
xnano-day, xnano-night xnano. Birch and dark oak wood, with a warm key light and a cool fill light after Complementary Shaders by EminGT.
zed-dark, zed-light Zed Industries: One Dark and One Light of the Zed editor.
one-dark-pro Binaryify: One Dark Pro.
one-dark, one-light GitHub: One Dark and One Light of the Atom editor.
dracula Zeno Rocha and the Dracula Theme contributors.
monokai Wimer Hazenberg.
github-dark, github-light GitHub: GitHub Dark Default and GitHub Light Default.
anthropic-dark, anthropic-light The brand colors of Anthropic.
openai-dark, openai-light The colors of OpenAI's Apps SDK UI.

The names and the colors of these themes belong to their authors. xnano is not affiliated with any of them.