Crate phetch

source ·
Expand description

phetch is a terminal Gopher client designed to help you quickly navigate the Gophersphere securely. It includes support for browsing via TLS or Tor proxy, but can also be used the old fashioned way. The menu-based interface is driven entirely by your keyboard, and emphasis has been put on swiftness of navigation. Both “jump to link” and incremental search options are available.

We don’t use any ncurses-style library for drawing but instead do it manually, mainly in UI. This is the application class that prints to the screen and manages the loaded Gopher “views”. Meanwhile, the bulk of the menu system, responding to user input, and rendering of the colored interface itself takes place in the Menu view. The two work hand-in-hand.

This crate includes its own Gopher parsing and fetching library, which may eventually get extracted. It seems that most existing Gopher libraries in Rust allow you to parse menu lines individually into items, but phetch needs to know about the links’ relationships to each other for its navigation/numbering/cursor system to work. So phetch parses all the lines in a Menu as a whole and knows which link is which.

Finally, a note on the code itself: this is not my first Rust program, but you probably wouldn’t know that by looking at it! Suggestions and improvements are more than welcome.


args::parse() is used to parse command line arguments into a Config structure.
Bookmarks are enabled if you create a ~/.config/phetch/ directory manually. They are stored as a simple Gophermap, BOOKMARKS_FILE, in that directory.
phetch will load ~/.config/phetch/phetch.conf or a file you specify with the --config command line option when it starts.
phetch’s Gopher library contains a few phetch-specific features: the ability to make requests or downloads over TLS or Tor, cleaning Unicode control characters from Gopher responses, and URL parsing that recognizes different protocols like telnet and IPv6 addresses.
The help module manages all internal Gopher pages, from the help system itself to the Start and “About Phetch” pages.
phetch will append every URL visited to a Gophermap if a HISTORY_FILE in ~/.config/phetch/ exists. This file must be manually created by the user for history tracking to engage.
The Menu is a View representing a Gopher menu. It renders the colorful representation, manages the cursor and selection state, and responds to input like the UP and DOWN arrows or other key combinations.
The phetchdir is DIR, or ~/.config/phetch by default. There is currently no way to change it. Bookmarks, user history, and the phetch.conf all live in this directory in a fully loaded installation of phetch.
The terminal module mostly provides terminal escape sequences for things like clearing the screen or going into alternate mode, as well as raw mode borrowed from crossterm.
A View representing a Gopher text entry. Responds to user input by producing an Action which is then handed to the main UI to perform.
Terminal color scheme. Provides the Theme struct and functions/macros for making use of it.
The UI is what drives the interactive phetch application: it spawns threads to fetch Gopher pages and download binary files, it manages the opened pages (Views), it asks the focused View to respond to user input, and it performs actions based on what the View returns - like opening a telnet client, or displaying an error on the status line.
Helper functions and macros.


Is the NO_COLOR env variable set?


Where to file issues. We try to catch and display all errors nicely, but if we have to crash we will try to show this.
Date when this release was built.
Git SHA of current build.
Current OS. Used to check for updates.
Whether we compiled with TLS support.
Whether we compiled with Tor support.
Current version of phetch.