Install hexhog
mainYou can install hexhog using cargo, yay (AUR), or brew (Homebrew).
# Using cargo
cargo install hexhog
# Using AUR (Arch Linux)
yay -S hexhog
# Using Homebrew (macOS)
brew install hexhogrepository·main·Indexed 42 days ago
https://github.com/dvdtsb/hexhogA configurable hex viewer and editor version 0.1.3 that allows users to edit, delete, insert, and copy/paste bytes within files. It features a TUI powered by ratatui and supports custom color themes and charsets via a config.toml file.
You can install hexhog using cargo, yay (AUR), or brew (Homebrew).
# Using cargo
cargo install hexhog
# Using AUR (Arch Linux)
yay -S hexhog
# Using Homebrew (macOS)
brew install hexhogHexhog is configured via a config.toml file. The configuration allows you to customize the color theme (using color names, ANSI codes, or RGB arrays) and the characters used to represent different byte types in the ASCII view.
/home/user/.config/hexhog/config.tomlC:\Users\user\AppData\Roaming\hexhog\config.toml/Users/user/Library/Application Support/hexhog/config.toml[theme]
null = "dark_gray"
ascii_printable = "blue"
ascii_whitespace = [67, 205, 128] # rgb
ascii_other = 162 # ansi
non_ascii = "red"
accent = "blue"
primary = "green"
background = "black"
border = "cyan"
[charset]
null = "."
ascii_whitespace = "·"
ascii_other = "°"
non_ascii = "×"Hexhog uses a TOML configuration file to customize the visual appearance (theme) and the character representation (charset) of bytes.
The [theme] section allows you to define colors for different byte types. Colors can be specified in three formats:
"Blue", "Red").0 and 255 (e.g., 16).[r, g, b] where each value is between 0 and 255 (e.g., [255, 0, 0]).Available theme keys:
nullascii_printableascii_whitespaceascii_othernon_asciiaccentprimaryborderselectbackgroundThe [charset] section allows you to define which characters are used to represent specific byte types when they are not printable ASCII. Each value must be a single character string.
Available charset keys:
null: Character for null bytes.ascii_whitespace: Character for non-space whitespace.ascii_other: Character for other non-printable ASCII.non_ascii: Character for non-ASCII bytes.[theme]
null = "DarkGray"
primary = [255, 255, 255]
accent = 12
[charset]
null = '.'
ascii_whitespace = '·'
ascii_other = '°'
non_ascii = '×'To open and edit a file with hexhog, pass the file path as an argument to the command.
hexhog <file>To start the application's main execution loop, call App::run. This method takes ownership of the App instance and a DefaultTerminal (from the ratatui crate). It enters a loop that handles rendering, event processing, and state updates until the application is no longer running.
app.run(terminal)?;The Byte struct wraps a u8 value and provides methods to categorize the byte, retrieve its hexadecimal representation, and resolve its character or visual style based on a provided Config object.
Key methods:
new(value: u8) -> Byte: Creates a new Byte instance.value() -> u8: Returns the underlying raw byte value.get_bytetype() -> ByteType: Returns the classification of the byte.get_hex() -> String: Returns the byte as a two-digit uppercase hexadecimal string (e.g., 0A, FF).get_char(&Config) -> char: Resolves the byte to a character using the provided Config's charset.get_style(&Config) -> Style: Resolves the byte to a ratatui::style::Style using the provided Config's colorscheme.use crate::byte::{Byte, ByteType};
use crate::config::Config;
let byte = Byte::new(0x41);
assert_eq!(byte.value(), 65);
assert_eq!(byte.get_hex(), "41");
// Categorization
match byte.get_bytetype() {
ByteType::AsciiPrintable => println!("It's printable!"),
_ => println!("Other type"),
}
// Integration with Config
// Note: Requires a valid Config instance
let character = byte.get_char(&config);
let style = byte.get_style(&config);To programmatically initialize the application state, use App::new. This function requires an Args struct (containing the target file path) and a Config object. It attempts to read the file contents into memory if the file exists.
Returns a Result<App>.
let app = App::new(args, config)?;Use the read_config function to load a configuration from a TOML file path. If the file does not exist, the function returns the Config::default() values instead of an error.
Returns: Result<Config, String>
Ok(Config): The loaded configuration or default configuration.Err(String): An error message if the TOML is malformed or if color/charset values are invalid (e.g., a color index out of range or a charset field containing more than one character).let config = read_config("path/to/config.toml").unwrap_or_else(|e| panic!("Failed to load config: {}", e));The ByteType enum is used to categorize bytes into one of five types based on their ASCII properties and value:
Null: The byte value is 0.AsciiPrintable: The byte is an ASCII graphic character (e.g., letters, numbers, punctuation).AsciiWhitespace: The byte is an ASCII whitespace character (e.g., space, tab, newline).AsciiOther: The byte is an ASCII character that is neither graphic nor whitespace.NonAscii: The byte is not a valid ASCII character.pub enum ByteType {
Null,
AsciiPrintable,
AsciiWhitespace,
AsciiOther,
NonAscii,
}If no configuration file is provided or if specific fields are missing, hexhog uses the following default settings:
Default ColorScheme:
null: Color::DarkGrayascii_printable: Color::Blueascii_whitespace: Color::Cyanascii_other: Color::Yellownon_ascii: Color::Greenaccent: Color::Blueselect: Color::DarkGrayborder: Color::Whiteprimary: Color::Whitebackground: Color::ResetDefault Charset:
null: '.'ascii_whitespace: '·'ascii_other: '°'non_ascii: '×'The hexhog application is invoked via the command line. It requires a single positional argument specifying the path to the file you wish to edit.
hexhog <file>hexhog <file>The hexhog application is a CLI tool that uses a terminal user interface (TUI) powered by ratatui. When executed, it automatically attempts to load a configuration file from the standard system configuration directory at [config_dir]/hexhog/config.toml. If the configuration file is missing or invalid, it falls back to the default configuration.
To run the application, use the standard binary execution method. The application expects command-line arguments defined by the Args struct (provided via clap).
# Example of running the binary (assuming it is compiled)
./hexhog