Metadata-Version: 2.4
Name: rcloc
Version: 0.1.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Console :: Curses
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities
License-File: LICENSE
Summary: A fast Rust re-implementation of cloc (count lines of code) with an ncdu-like interactive tree browser
Keywords: cloc,sloc,loc,lines of code,tui
License-Expression: GPL-3.0-or-later
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/renefritze/rcloc-gui
Project-URL: Issues, https://github.com/renefritze/rcloc-gui/issues

# rcloc

`rcloc` is a re-implementation of [cloc](https://github.com/AlDanial/cloc)
("count lines of code") in Rust. It accepts the same command line, reads the
same options file and language-definition files, and prints cloc's report
formats. It adds two things on top:

* **Interactive mode** (`rcloc --tui`): an [ncdu](https://dev.yorhel.nl/ncdu)-style
  browser for the source tree, showing recursive blank/comment/code counts for
  every directory, with a per-language breakdown of the selected entry.
* **Version-control awareness by default**: if an input directory is inside a
  git, Mercurial or Subversion checkout, rcloc counts only files under version
  control, the same as `cloc --vcs=git`. Use `--no-vcs` (or `--vcs=none`) to
  walk the directory tree like plain cloc does.

It is also much faster than cloc: it counts the 112 MB cargo registry
(about 6,000 files) in 0.4 s, where cloc takes 6.4 s.

## Installation

Binary wheels are published on PyPI, so no Rust toolchain is needed:

```bash
pip install rcloc
```

`pipx install rcloc` and `uv tool install rcloc` work as well. To build
from source:

```bash
cargo install --git https://github.com/renefritze/rcloc-gui
```

## Usage

Anything you would pass to cloc works:

```bash
rcloc .
```

```bash
rcloc --by-file --json src/ include/
```

```bash
rcloc --exclude-dir=vendor,third_party --include-lang=Rust,Python .
```

```bash
rcloc --diff v1.0/ v2.0/
```

```text
$ rcloc --hide-rate --exclude-dir=fixtures .
github.com/renefritze/rcloc-gui v 0.1.0
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Rust                            14            338            196           8280
JSON                             1              0              0           7720
YAML                             2             13              8            176
Markdown                         1             40              0            141
TOML                             2              6              0             52
Python                           1              9              7             45
-------------------------------------------------------------------------------
SUM:                            21            406            211          16414
-------------------------------------------------------------------------------
```

The command-line parser behaves like Perl's Getopt::Long as configured by
cloc: `--opt=value`, `--opt value`, single-dash long options (`-by-file`),
underscore spellings (`--exclude_dir`) and unique abbreviations
(`--by-file-by`) are all accepted. `rcloc --help` lists every option.

### Interactive mode

```bash
rcloc --tui            # current directory
```

```bash
rcloc --tui ~/src/project --exclude-lang=JSON
```

All filtering options apply in interactive mode too.

| Key | Action |
| --- | --- |
| `↑`/`↓`, `k`/`j`, PgUp/PgDn, Home/End | move |
| `→`, `l`, Enter | open directory |
| `←`, `h`, Backspace | parent directory |
| `c` / `m` / `b` / `t` / `f` / `n` | sort by code / comment / blank / total / files / name (press again to reverse) |
| `d` | directories first |
| `L` | filter all counts by one language (Esc clears) |
| `i` | toggle the language panel |
| `r` | rescan |
| `?` | help |
| `q` | quit |

### Version control detection

For each input directory, rcloc looks for `.git`, `.hg` or `.svn` in that
directory and its parents. If it finds one, it lists files with
`git ls-files`, `hg files` or `svn list -R`. If a git checkout is found but
the `git` executable is missing, rcloc falls back to a walk that honours
`.gitignore`. Files named explicitly on the command line are always counted.

* `--vcs=git|svn|hg` forces a VCS.
* `--vcs='<command>'` uses any command that prints one file per line.
* `--no-vcs` / `--vcs=none` disables detection.

`--vcs=auto` is the default.

### Configuration files

* **Options file:** `~/.config/cloc/options.txt` is read (or the file given
  with `--config`). It holds one option per line, with or without leading
  `--`. Options given on the command line take precedence, exactly as in
  cloc, so an existing cloc setup works unchanged.
* **Language definitions:** `--read-lang-def` (merge), `--force-lang-def`
  (replace) and `--write-lang-def` use cloc's file format.

### Compatibility with cloc

The built-in language table (extensions, file names, shebang interpreters,
comment filters, 3rd-generation scale factors) was extracted from cloc 2.13,
and every comment filter was ported, including the Regexp::Common comment
regexes and the heuristics that tell apart languages sharing an extension
(`.m`, `.pl`, `.h`, `.inc`, `.ts`, `.v`, …). Duplicate detection (MD5),
binary-file detection and the report layouts follow cloc as well.

Results were compared with cloc 1.98 on real code trees: the cargo
registry, `/usr/include`, the Python standard library and site-packages,
and Perl's library directories. rcloc gives exactly the same per-file
results for every language whose definition did not change between cloc
1.98 and 2.13. For Perl and Python, cloc 2.13 changed the filters (POD
handling and the order of docstring removal), and rcloc follows 2.13.
`--diff` output is byte-identical to cloc's on the version pairs tested.
`scripts/compare_with_cloc.py` repeats the comparison against any
installed cloc.

Differences:

* The report header names rcloc (`github.com/renefritze/rcloc-gui v <version>`).
* Counting runs in parallel; `--processes=N` sets the number of threads.
* VCS detection is on by default (see above).
* Not implemented yet: counting inside archives (tar/zip inputs), git
  commit or tag inputs and `--git-diff-*`, `--sum-reports`, `--sql`,
  `--html`, `--fmt`, `--use-sloccount`, `--unicode`, `--file-encoding`.

## Development

```bash
cargo test
```

```bash
python3 scripts/compare_with_cloc.py /some/source/tree --ignore-langs Perl,Python
```

The comparison script needs an installed cloc and a release build
(`cargo build --release`).

### Releasing to PyPI

`.github/workflows/release.yml` builds wheels with
[maturin](https://www.maturin.rs/) for Linux (manylinux and musllinux:
x86_64, x86, aarch64, armv7, ppc64le, s390x), macOS (x86_64, arm64) and
Windows (x64, x86, arm64), plus an sdist. It runs on every pull request that
touches the packaging files, and it publishes to PyPI when a `v*` tag
matching the crate version is pushed. Publishing uses
[trusted publishing](https://docs.pypi.org/trusted-publishers/): register
this repository, the workflow `release.yml` and the environment `pypi` as a
trusted publisher for the `rcloc` project on PyPI once.

## License

GPL-3.0-or-later. The language definitions in `data/languages.json` are
derived from cloc, which is © Al Danial and licensed under the GPL (version 2
or later).

