lat/README.md

136 lines
5.7 KiB
Markdown
Raw Normal View History

2023-04-20 14:33:28 +00:00
# lat
> lat | lazy cat - a cat clone with some quality-of-life embellishments
2023-04-20 17:44:56 +00:00
[![Build](https://github.com/secondary-smiles/lat/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/secondary-smiles/lat/actions/workflows/c-cpp.yml)
2023-05-01 22:39:27 +00:00
![lat demo](social/render/lat_demo.gif)
2023-04-20 14:33:28 +00:00
## About
`lat` is a solution to a problem that doesn't exist. It's the awkward middle child in-between `cat` and `bat`. It was created because the author didn't want to have to configure `bat` just to get decent file printing, but wanted a little more control than `cat` offered.
`lat` does not expect to be used. `lat` expects to be forgotten and shunted into a corner because it does not belong in the slightest.
2023-05-01 22:39:27 +00:00
`lat` is fast. Here are the hyperfine results comparing `cat`, `lat`, and `bat` on a `lat`'s `main.c` source file:
2023-04-20 14:33:28 +00:00
2023-05-01 22:39:27 +00:00
```text
hyperfine "./build/lat src/main.c" "cat src/main.c" "bat src/main.c" -N --warmup 200
Benchmark 1: ./build/lat src/main.c
Time (mean ± σ): 0.2 ms ± 0.0 ms [User: 0.1 ms, System: 0.0 ms]
Range (min … max): 0.1 ms … 0.7 ms 19651 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 2: cat src/main.c
Time (mean ± σ): 0.2 ms ± 0.0 ms [User: 0.2 ms, System: 0.0 ms]
Range (min … max): 0.2 ms … 0.4 ms 13717 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 3: bat src/main.c
Time (mean ± σ): 1.4 ms ± 0.7 ms [User: 1.1 ms, System: 0.3 ms]
Range (min … max): 1.1 ms … 6.5 ms 1057 runs
Warning: The first benchmarking run for this command was significantly slower than the rest (2.8 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using the '--warmup' option which helps to fill these caches before the actual benchmark. You can either try to increase the warmup count further or re-run this benchmark on a quiet system in case it was a random outlier. Alternatively, consider using the '--prepare' option to clear the caches before each timing run.
Summary
'./build/lat src/main.c' ran
1.29 ± 0.28 times faster than 'cat src/main.c'
9.14 ± 4.56 times faster than 'bat src/main.c'
2023-04-20 14:33:28 +00:00
```
2023-05-01 22:39:27 +00:00
~~as you can see, the extra features do take their toll on performance, but overall, `lat` is generally nearly on-par with `cat`, and *far* faster than `bat`.~~
2023-04-20 14:33:28 +00:00
2023-05-02 13:38:25 +00:00
**As of v0.12.2 `lat` is the new fastest of the three!** (on my machine and with reasonably sized files)
2023-04-20 14:33:28 +00:00
2023-04-20 17:44:56 +00:00
## Install
`lat` is not yet at a stable version (`v1.0.0`), so it is not on any package managers.
```bash
git clone https://github.com/secondary-smiles/lat.git
cd lat
make prep
make
./build/lat -V
# now add lat to your $PATH/do whatever you want with the binary
```
2023-04-20 14:33:28 +00:00
## Use
2023-04-22 19:33:08 +00:00
`lat` can, for the most part, be a direct drop in for `cat`. However it really shines when embedded into another program. For example, in `fzf`, `lat` makes an excellent viewer with the command `fzf --command lat -r {}`.
2023-04-20 14:33:28 +00:00
![Using lat in fzf](social/render/fzf_embed.gif)
Soon, I plan to add the ability to live-write to `lat`. That means that `lat` can become yet another output stream.
For example, this should be possible in a future version of `lat`
```c
int main(void) {
2023-04-22 19:33:08 +00:00
FILE *st = popen("lat -r", "w");
2023-04-20 14:33:28 +00:00
if (st == NULL)
exit(1);
fprintf(st, "look ma, i'm formatted!")
pclose(st);
}
```
2023-04-20 17:44:56 +00:00
> UPDATE: this feature is possible, however the data is only printed upon `pclose`.
2023-04-20 14:33:28 +00:00
### Features and Flags
2023-04-22 19:33:08 +00:00
#### `-c` color
2023-04-20 14:33:28 +00:00
Completely disables or enables all colored output from `lat`.
2023-04-22 19:33:08 +00:00
#### `-l` line numbers
2023-04-20 14:33:28 +00:00
Print numbers for each line of the file.
2023-04-22 19:33:08 +00:00
#### `-t` file title
2023-04-20 14:33:28 +00:00
Shows or hides formatted file data headers.
2023-04-22 19:33:08 +00:00
#### `-b` binary mode
2023-04-20 14:33:28 +00:00
By default, `lat` will attempt to detect if the file is printable or not. If the file isn't (e.g. you ran `lat file.pdf`) then lat will enter *`binary mode`*. In *`binary mode`*, `lat` will skip a lot of processing in favor of speed.
You can force *`binary mode`* to be `on` or `off` with the flags `-b` and `-bb` respectively.
2023-04-22 19:33:08 +00:00
#### `-r` raw output
`lat` is smart enough to print all non-file characters to a separate filestream. That way, the output of `lat` can be used to con**cat**enate files, the way it was originally meant to be (with `>` or `|`).
2023-04-20 14:33:28 +00:00
However, sometimes you want those extra symbols.
2023-04-22 19:33:08 +00:00
`-r` prints everything out to the primary filestream (usually `stdout`)
2023-04-20 14:33:28 +00:00
2023-04-22 19:33:08 +00:00
#### `-p` pager
2023-04-20 14:33:28 +00:00
`lat` comes with out-of-the-box support for paging in `less`. If you don't want your file messing up your terminal, just `-p` it.
2023-04-22 19:33:08 +00:00
### `-n` name
`lat` allows you to customize the name of the file shown. This can be useful in demonstrations or when `lat` is embedded in another program.
2023-04-20 14:33:28 +00:00
#### If there is a feature you'd like to see, feel free to make an issue (1x points). If you're feeling especially savvy, make a PR with the feature (10x points).
## Helptext
2023-04-22 19:33:08 +00:00
> `lat -h`
2023-04-20 14:33:28 +00:00
```text
lat | lazy cat - a cat clone with some quality-of-life embellishments
2023-05-01 22:39:27 +00:00
usage: lat [-cltbrpneVh] [file...]
2023-04-20 14:33:28 +00:00
options:
2023-05-01 22:39:27 +00:00
-c toggle color
-l toggle line numbers
-t toggle file info headers
-b set binary mode, -b forces binary and -bb forces NOT binary
-r print everything (headers, line numbers, etc.) to stdout (or equivalent)
-p print file with the pager (uses less)
-n <name> manually set the name of the file shown in the title
-e <program> link extension to lat
-V show program version
-h display this help text
2023-04-20 14:33:28 +00:00
environment:
2023-05-01 22:39:27 +00:00
NO_COLOR, see https://no-color.org/
2023-04-20 14:33:28 +00:00
```