Skip to main content

txtui

A terminal (TUI) reader for .txt novels written in Python, built on Textual.

Designed for Chinese text novels: it auto-detects UTF-8/GBK encoding, helps you match a two-level chapter outline with presets or custom regexes, and remembers your reading position and time spent in each book.

Features

  • Recent list — open txtui with no arguments to pick a book from your reading history, sorted by most recently closed
  • Chapter outline — outline on the left (25%) vs. content on the right (75%), with a collapsible, current-chapter-highlighting outline
  • Preset chapter matching — 章节体 (章/节), 卷章体 (卷/章), and single-level auto-detection
  • Custom regex matching — validate your own level-1 regex (and optional level-2), with validation feedback when it matches nothing
  • Encoding handling — auto-detects UTF-8 vs. GBK; for GBK it asks before converting the file in place to UTF-8
  • Reading state — per-book position (chapter + line), timestamps, accumulated reading time, and chapter config, persisted to JSON
  • Configurable location — config file path via TXTUI_CONFIG_FILE, or data directory via --data-dir

Requirements

  • Python 3.10+

Installation

uv sync

Run from the checkout:

uv run txtui /path/to/novel.txt

Or install into your environment and use the txtui command:

uv pip install -e .
txtui /path/to/novel.txt

Usage

txtui [-d/--data-dir PATH] [target.txt]
Argument Meaning
target.txt The novel to open. If omitted, the recent-list screen is shown.
-d, --data-dir PATH Directory where the state file lives (default ~/.local/share/txtui/).

Environment variables

Variable Meaning
TXTUI_CONFIG_FILE Full path to the state/config JSON file. Overrides the default ~/.local/share/txtui/state.json (takes precedence over --data-dir).

Example:

TXTUI_CONFIG_FILE=~/novels/txtui-state.json txtui my_novel.txt

First time opening a book

  1. Its encoding is checked (UTF-8 first, then GBK). If it is GBK you are asked whether to convert it to UTF-8 in place.
  2. A full-screen preview shows the text with line numbers. You can flip pages with space, scroll lines with j/k.
  3. Press Enter to set up the chapter outline: choose a preset, or type your own level-1 regex (and optional level-2 regex).
  4. If a valid outline already exists for the book (or you finish configuring), you land in the reader.

Keybindings

Recent list

Key Action
j / down Move down
k / up Move up
enter Open the selected book
q Quit

Chapter config screen

Key Action
space Page down
j / down Scroll down a line
k / up Scroll up a line
enter Set up the chapter outline
q Quit

Reader — content mode

Key Action
space Page down
j / down Scroll down a line
k / up Scroll up a line
home Jump to top of current chapter
end Jump to bottom of current chapter
h / left Previous chapter
l / right Next chapter
esc Focus the chapter outline
q Save reading state and quit

Reader — outline mode

Entered with esc. Press esc again to return to the content at your previous spot.

Key Action
j / k Move the selection up/down
space Collapse / expand a level-1 entry (only when it has children)
enter Jump to the selected chapter and return to the content (level-1 entries can be entered only when there is no second level); otherwise it collapses/expands
esc Back to the content view

Dialogs

Key Action
y / n Confirm / decline (e.g. the encoding-conversion prompt)
enter Confirm
esc Cancel

Data layout

By default state is stored in ~/.local/share/txtui/state.json and looks like:

{
  "records": {
    "/abs/path/novel.txt": {
      "path": "/abs/path/novel.txt",
      "title": "小说名",
      "encoding": "utf-8",
      "chapter_config": {
        "level1_pattern": "^\\s*第[一二三四五六七八九十百千\\d]+卷",
        "level2_pattern": "^\\s*第[一二三四五六七八九十百千\\d]+章",
        "preset_name": "卷章体"
      },
      "chapter_index": 2,
      "line": 48,
      "last_read": 1721800000.0,
      "total_reading_time": 3600.0
    }
  }
}

Override its location with TXTUI_CONFIG_FILE or the default directory with --data-dir.

Development

uv run pytest          # run the test suite
uv run python -m txtui # launch the app

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

txtui-0.1.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

txtui-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file txtui-0.1.0.tar.gz.

File metadata

  • Download URL: txtui-0.1.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for txtui-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f2495e45906d2d2bbf4899110fd979c6c77e0c954fa543740194102a1bb09117
MD5 a9ff57c71e802f042feeca967df01e6e
BLAKE2b-256 a58b2ed88add988046a197984a53b7bc24ff3ba32eba2b9631ff04e80f667287

See more details on using hashes here.

File details

Details for the file txtui-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: txtui-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for txtui-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f5f6d041c3aceb6757f6687d5dba0222063fa29bd20d86873d335be9a33272
MD5 3aa4fccc701d847cbfc20ff4b6246521
BLAKE2b-256 10a45cc32c7ac0a1655eca71269f627be398d15f061d2eb844eca496afeee24b

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page