Crate ricat

source ·
Expand description

§ricat: A Rust-Based cat Command Implementation

This project is a Rust-based reimagining of the classic Unix cat command, drawing inspiration from its original implementation in GNU Core Utilities. It demonstrates the power and flexibility of Rust for system utilities development.

A key design principle of ricat is extensibility. By utilizing a trait, LineTextFeature, the application makes it straightforward to introduce new functionalities. Developers can add custom features by implementing the apply_feature() method for each line of text. The core logic of ricat seamlessly integrates these features without requiring additional modifications.

§Features

  • Modular Design: Easy to extend with new line-based text processing features.
  • Trait-Based Feature Implementation: Implement the LineTextFeature trait to create new features.
  • Line Numbering: Display line numbers for each line of the input.
  • Dollar Symbol at End: Append a $ symbol at the end of each line.
  • Replace Tab Spaces: Replace tab spaces in the text with ^I.
  • Compress Empty Lines: Compress multiple consecutive empty lines into a single empty line.
  • Search Text: Search for lines containing a specific text or regular expression pattern. Prefix the search text with ‘reg:’ to treat it as a regular expression, e.g., ‘reg:\d+’ to search for digits.
  • Case-Insensitive Search: Perform case-insensitive search for lines containing a specific text.
  • Base64 Encoding: Encode the input text using Base64.
  • Base64 Decoding: Decode Base64 encoded text.
  • Pagination: Display the output in a paginated manner, allowing user to navigate through pages.
  • Configuration File: Load preset features from a configuration file (ricat_cfg.toml) located in the user’s configuration directory ($HOME/.config/ricat).

§Usage

ricat supports various command-line options to enable different features and customize the output. Here are some common usage examples:

§Read a File directly

ricat my_file.txt

§Read a File With Line Numbering Enabled

ricat -n my_file.txt

§Read a File with $ at End of Each Line

ricat -d my_file.txt

§Replace Tab Spaces with ^I

ricat -t my_file.txt

§Compress Empty Lines

ricat -s my_file.txt

§Search for Lines Containing a Specific Text

ricat --search --text "search_text" my_file.txt

§Search for Lines Matching a Regular Expression

ricat --search --text "reg:\\d+" my_file.txt
ricat --search --text "search_text" -i my_file.txt

§Encode Input Text Using Base64

ricat --encode-base64 my_file.txt

§Decode Base64 Encoded Text

ricat --decode-base64 my_encoded_file.txt

§Enable Pagination

ricat --pages my_large_file.txt

§Configuration File

ricat supports loading preset features from a configuration file (ricat_cfg.toml) located in the user’s configuration directory ($HOME/.config/ricat). The configuration file is automatically created during the installation process using cargo install.

The configuration file allows users to enable or disable specific features by setting the corresponding fields to true or false. Here’s an example of the ricat_cfg.toml file:

number_feature = true
dollar_sign_feature = false
tabs_feature = false
compress_empty_line_feature = false

When ricat is executed, it reads the configuration file and enables the specified features accordingly. This provides a convenient way for users to customize the behavior of ricat without having to specify the options every time they run the command.

§Benchmarks

Added a benchmarking module to test the performance of the application. The benchmarks covers only the direct file read(without features). To run the benchmarks, use the following command: in src/

./benchmark_plot.sh

The script will run the benchmarks and generate a plot using matplotlib Be sure to install the required dependencies before running the script. Dependency: matplotlib

§Extending ricat

Adding a new feature to ricat is as simple as implementing the LineTextFeature trait for any struct. This modular approach encourages experimentation and customization.

For example, to add a feature that highlights TODO comments in your text files, define a struct implementing LineTextFeature that scans each line for the pattern and applies the desired formatting.

§Testing

ricat includes a comprehensive test suite to ensure the correctness and reliability of its functionality. The tests cover various scenarios and edge cases, including:

  • Basic functionality of each feature
  • Interaction between multiple features
  • Handling of empty input
  • Proper resetting of state between input sources
  • Encoding and decoding of text using Base64
  • Case-insensitive search functionality
  • Loading and applying configuration from the ricat_cfg.toml file

To run the tests, clone the repo and use the cargo test command.

§Contributing

Contributions to ricat are welcome! If you have an idea for a new feature or improvement, please open an issue or submit a pull request on the project’s GitHub repository.

When contributing, please ensure that your changes are well-tested and adhere to the project’s coding style and conventions.

§License

ricat is open-source software licensed under the MIT License.

Re-exports§

  • pub use encoding_decoding_feature::Base64;
  • pub use encoding_decoding_feature::DataEncoding as _;

Modules§

Structs§

Traits§

  • Trait defining a text feature that can be applied to lines of input.

Functions§