├── .dockerignore ├── .editorconfig ├── .github ├── CODEOWNERS ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── bors.toml ├── dependabot.yml └── workflows │ ├── audit.yml │ ├── cd.yml │ ├── ci.yml │ └── docker.yml ├── .gitignore ├── CHANGELOG.md ├── CNAME ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── README.md ├── RELEASE.md ├── _config.yml ├── build.rs ├── codecov.yml ├── example ├── Makefile └── lkm_example.c ├── rustfmt.toml └── src ├── app.rs ├── args.rs ├── event.rs ├── kernel ├── cmd.rs ├── info.rs ├── lkm.rs ├── log.rs └── mod.rs ├── lib.rs ├── main.rs ├── style.rs ├── util.rs └── widgets.rs /.dockerignore: -------------------------------------------------------------------------------- 1 | # Examples 2 | /example/ 3 | 4 | # GitHub files 5 | /.github/ 6 | 7 | # Snap files 8 | /snap/ 9 | 10 | # Docker 11 | Dockerfile 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # 4 space indentation 7 | [*.{c,rs}] 8 | indent_style = tab 9 | indent_size = 4 10 | 11 | # Tab indentation (no size specified) 12 | [Makefile] 13 | indent_style = tab -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/about-codeowners/ 2 | # for more info about CODEOWNERS file 3 | 4 | # It uses the same pattern rule for gitignore file 5 | # https://git-scm.com/docs/gitignore#_pattern_format 6 | 7 | # Core 8 | * @orhun -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: orhun 2 | patreon: orhunp 3 | buy_me_a_coffee: orhun 4 | open_collective: kmon 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'bug' 6 | assignees: 'orhun' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Run with '...' parameters 16 | 2. Use the '....' feature 17 | 3. Select the '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots/Logs** 24 | If applicable, add screenshots or logs to help explain your problem. 25 | 26 | **System (please complete the following information):** 27 | - OS Information: [e.g. Arch GNU/Linux x86_64 5.4.8-arch1-1] 28 | - Rust Version: [e.g. 1.40.0] 29 | - Project Version: [e.g. 0.1.0] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: 'orhun' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | 4 | ## Motivation and Context 5 | 6 | 7 | 8 | ## How Has This Been Tested? 9 | 10 | 11 | 12 | 13 | ## Screenshots / Output (if appropriate): 14 | 15 | ## Types of changes 16 | 17 | - [ ] Bug fix (non-breaking change which fixes an issue) 18 | - [ ] New feature (non-breaking change which adds functionality) 19 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 20 | - [ ] Documentation (no code change) 21 | - [ ] Refactor (refactoring production code) 22 | - [ ] Other 23 | 24 | ## Checklist: 25 | 26 | 27 | - [ ] My code follows the code style of this project. 28 | - [ ] I have updated the [documentation](https://github.com/orhun/kmon/blob/master/README.md) and [changelog](https://github.com/orhun/kmon/blob/master/CHANGELOG.md) accordingly. 29 | - [ ] I have added tests to cover my changes. 30 | - [ ] All new and existing tests passed. 31 | - [ ] [Rustfmt](https://github.com/rust-lang/rustfmt) and [Rust-clippy](https://github.com/rust-lang/rust-clippy) passed. 32 | -------------------------------------------------------------------------------- /.github/bors.toml: -------------------------------------------------------------------------------- 1 | status = [ 2 | "Build for x86_64-unknown-linux-gnu using Rust stable (on ubuntu-22.04)", 3 | "Build for x86_64-unknown-linux-musl using Rust stable (on ubuntu-22.04)", 4 | "Build for x86_64-unknown-linux-gnu using Rust nightly (on ubuntu-22.04)", 5 | "Build for x86_64-unknown-linux-musl using Rust nightly (on ubuntu-22.04)", 6 | ] 7 | delete_merged_branches = true 8 | update_base_for_deletes = true 9 | cut_body_after = "
" 10 | commit_title = "chore: Merge ${PR_REFS}" 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Maintain dependencies for Cargo 4 | - package-ecosystem: cargo 5 | directory: "/" 6 | schedule: 7 | interval: daily 8 | open-pull-requests-limit: 10 9 | 10 | # Maintain dependencies for GitHub Actions 11 | - package-ecosystem: github-actions 12 | directory: "/" 13 | schedule: 14 | interval: daily 15 | open-pull-requests-limit: 10 16 | -------------------------------------------------------------------------------- /.github/workflows/audit.yml: -------------------------------------------------------------------------------- 1 | name: Security Audit 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * 0" 6 | 7 | jobs: 8 | audit: 9 | name: Audit 10 | runs-on: ubuntu-20.04 11 | steps: 12 | - name: Checkout the repository 13 | uses: actions/checkout@master 14 | - name: Install Rust 15 | uses: actions-rs/toolchain@v1 16 | with: 17 | toolchain: stable 18 | profile: minimal 19 | override: true 20 | - name: Run cargo-audit 21 | uses: actions-rs/audit-check@v1 22 | with: 23 | token: ${{ secrets.GITHUB_TOKEN }} 24 | -------------------------------------------------------------------------------- /.github/workflows/cd.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Deployment 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*.*.*" 7 | 8 | jobs: 9 | publish-github: 10 | name: Publish on GitHub 11 | runs-on: ubuntu-22.04 12 | strategy: 13 | matrix: 14 | TARGET: [ x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl ] 15 | steps: 16 | - name: Checkout repository 17 | uses: actions/checkout@master 18 | - name: Set the release version 19 | run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV 20 | - name: Install X11 dependencies 21 | run: | 22 | sudo apt-get update 23 | sudo apt-get install --allow-unauthenticated -y -qq \ 24 | libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev musl-tools 25 | - name: Install Rust toolchain 26 | uses: actions-rs/toolchain@v1 27 | with: 28 | toolchain: stable 29 | target: ${{matrix.TARGET}} 30 | override: true 31 | - name: Build 32 | run: cargo build --release --locked --target ${{ matrix.TARGET }} 33 | - name: Prepare assets 34 | run: | 35 | mkdir assets 36 | cp -t assets/ target/${{matrix.TARGET}}/release/kmon && strip -s assets/kmon 37 | cp -t assets/ LICENSE README.md CHANGELOG.md 38 | mv target/${{matrix.TARGET}}/man . 39 | cp -t assets/ --parents man/kmon.8 40 | mv target/${{matrix.TARGET}}/completions . 41 | cp -t assets/ --parents completions/* 42 | mv assets/ kmon-${{env.RELEASE_VERSION}}/ 43 | tar -czvf kmon-${{env.RELEASE_VERSION}}-${{matrix.TARGET}}.tar.gz \ 44 | kmon-${{env.RELEASE_VERSION}}/ 45 | sha512sum kmon-${{env.RELEASE_VERSION}}-${{matrix.TARGET}}.tar.gz \ 46 | > kmon-${{env.RELEASE_VERSION}}-${{matrix.TARGET}}.tar.gz.sha512 47 | echo "${{ secrets.GPG_RELEASE_KEY }}" | base64 --decode > private.key 48 | echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --pinentry-mode=loopback \ 49 | --passphrase-fd 0 --import private.key 50 | echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --pinentry-mode=loopback \ 51 | --passphrase-fd 0 --detach-sign \ 52 | kmon-${{env.RELEASE_VERSION}}-${{matrix.TARGET}}.tar.gz 53 | - name: Upload assets 54 | uses: svenstaro/upload-release-action@v2 55 | with: 56 | repo_token: ${{ secrets.GITHUB_TOKEN }} 57 | file: kmon-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.tar.gz* 58 | file_glob: true 59 | overwrite: true 60 | tag: ${{ github.ref }} 61 | body: | 62 | 63 | See [**changelog**](CHANGELOG.md) for release notes. 64 | 65 | publish-crates-io: 66 | name: Publish on crates.io 67 | needs: publish-github 68 | runs-on: ubuntu-22.04 69 | steps: 70 | - name: Checkout repository 71 | uses: actions/checkout@master 72 | - name: Install X11 dependencies 73 | run: | 74 | sudo apt-get update 75 | sudo apt-get install --allow-unauthenticated -y -qq \ 76 | libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev 77 | - name: Publish 78 | uses: actions-rs/cargo@v1 79 | with: 80 | command: publish 81 | args: --locked --token ${{ secrets.CARGO_TOKEN }} 82 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - staging # for bors 8 | - trying # for bors 9 | pull_request: 10 | branches: 11 | - master 12 | schedule: 13 | - cron: "0 0 * * 0" 14 | 15 | jobs: 16 | build: 17 | name: Build for ${{ matrix.TARGET }} using Rust ${{ matrix.TOOLCHAIN }} (on ${{ matrix.OS }}) 18 | runs-on: ${{ matrix.OS }} 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | OS: [ ubuntu-22.04 ] 23 | TOOLCHAIN: [ stable, nightly ] 24 | TARGET: 25 | - x86_64-unknown-linux-gnu 26 | - x86_64-unknown-linux-musl 27 | 28 | steps: 29 | - name: Checkout the repository 30 | uses: actions/checkout@master 31 | 32 | - name: Install dependencies 33 | run: | 34 | sudo apt-get update 35 | sudo apt-get install --allow-unauthenticated -y -qq \ 36 | libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev musl-tools 37 | 38 | - name: Install Rust 39 | uses: actions-rs/toolchain@v1 40 | with: 41 | toolchain: ${{ matrix.TOOLCHAIN }} 42 | target: ${{ matrix.TARGET }} 43 | override: true 44 | components: rustfmt, clippy 45 | 46 | - name: Build 47 | uses: actions-rs/cargo@v1 48 | with: 49 | command: build 50 | args: --target ${{ matrix.TARGET }} 51 | 52 | - name: Check formatting 53 | uses: actions-rs/cargo@v1 54 | with: 55 | command: fmt 56 | args: --all -- --check 57 | 58 | - name: Check lints 59 | if: matrix.TOOLCHAIN == 'stable' 60 | uses: actions-rs/cargo@v1 61 | with: 62 | command: clippy 63 | args: -- -D warnings 64 | 65 | - name: Setup cargo-tarpaulin 66 | if: matrix.TARGET == 'x86_64-unknown-linux-gnu' 67 | run: | 68 | curl -s https://api.github.com/repos/xd009642/tarpaulin/releases/latest | \ 69 | grep "browser_download_url.*x86_64-unknown-linux-musl.tar.gz" | cut -d : -f 2,3 | tr -d \" | wget -qi - 70 | tar -xzf cargo-tarpaulin-*.tar.gz 71 | mv cargo-tarpaulin ~/.cargo/bin/ 72 | 73 | - name: Run tests 74 | if: matrix.TARGET == 'x86_64-unknown-linux-gnu' 75 | run: cargo tarpaulin --out Xml --verbose --target ${{ matrix.TARGET }} 76 | 77 | - name: Upload reports to codecov.io 78 | if: github.event_name != 'pull_request' && matrix.TOOLCHAIN == 'stable' && matrix.TARGET == 'x86_64-unknown-linux-gnu' 79 | uses: codecov/codecov-action@v4.0.1 80 | with: 81 | token: ${{ secrets.CODECOV_TOKEN }} 82 | file: cobertura.xml 83 | flags: unittests 84 | name: code-coverage-report 85 | fail_ci_if_error: true 86 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker Automated Builds 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - "v*.*.*" 9 | pull_request: 10 | branches: 11 | - master 12 | schedule: 13 | - cron: "0 0 * * 0" 14 | 15 | jobs: 16 | docker: 17 | name: Docker Build and Push 18 | runs-on: ubuntu-22.04 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@master 22 | 23 | - name: Docker meta 24 | id: meta 25 | uses: docker/metadata-action@v5 26 | with: 27 | images: | 28 | orhunp/kmon 29 | ghcr.io/${{ github.repository_owner }}/kmon/kmon 30 | tags: | 31 | type=schedule 32 | type=ref,event=branch 33 | type=ref,event=pr 34 | type=sha 35 | type=raw,value=latest 36 | type=semver,pattern={{version}} 37 | 38 | - name: Set up QEMU 39 | uses: docker/setup-qemu-action@v3 40 | with: 41 | platforms: arm64 42 | 43 | - name: Set up Docker Buildx 44 | id: buildx 45 | uses: docker/setup-buildx-action@v3 46 | 47 | - name: Cache Docker layers 48 | uses: actions/cache@v4 49 | with: 50 | path: /tmp/.buildx-cache 51 | key: ${{ runner.os }}-buildx-${{ github.sha }} 52 | restore-keys: | 53 | ${{ runner.os }}-buildx- 54 | 55 | - name: Login to Docker Hub 56 | if: github.event_name != 'pull_request' 57 | uses: docker/login-action@v3 58 | with: 59 | username: orhunp 60 | password: ${{ secrets.DOCKER_TOKEN }} 61 | 62 | - name: Login to GHCR 63 | if: github.event_name != 'pull_request' 64 | uses: docker/login-action@v3 65 | with: 66 | registry: ghcr.io 67 | username: ${{ github.repository_owner }} 68 | password: ${{ secrets.GITHUB_TOKEN }} 69 | 70 | - name: Build and push 71 | id: docker_build 72 | uses: docker/build-push-action@v5 73 | with: 74 | context: ./ 75 | file: ./Dockerfile 76 | platforms: linux/amd64,linux/arm64 77 | builder: ${{ steps.buildx.outputs.name }} 78 | push: ${{ github.event_name != 'pull_request' }} 79 | tags: ${{ steps.meta.outputs.tags }} 80 | sbom: true 81 | provenance: true 82 | labels: ${{ steps.meta.outputs.labels }} 83 | cache-from: type=local,src=/tmp/.buildx-cache 84 | cache-to: type=local,dest=/tmp/.buildx-cache 85 | 86 | - name: Scan the image 87 | uses: anchore/sbom-action@v0 88 | with: 89 | image: ghcr.io/${{ github.repository_owner }}/kmon/kmon 90 | 91 | - name: Image digest 92 | run: echo ${{ steps.docker_build.outputs.digest }} 93 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files and executables 2 | /target/ 3 | 4 | # Backup files generated by rustfmt 5 | **/*.rs.bk 6 | 7 | # Object files 8 | *.o 9 | *.ko 10 | *.obj 11 | *.elf 12 | 13 | # Snap package files 14 | *.snap 15 | 16 | # Kernel module compilation files 17 | *.mod* 18 | *.cmd 19 | .tmp_versions/ 20 | modules.order 21 | Module.symvers 22 | Mkfile.old 23 | dkms.conf 24 | 25 | # Editor configurations 26 | .vscode 27 | *.code-workspace 28 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [1.7.1] - 2024-12-15 9 | 10 | ### Fixed 11 | - Use the smaller regex-lite crate by @omnivagant in [#180](https://github.com/orhun/kmon/pull/180) 12 | - Allow '?' as search query by @orhun 13 | 14 | ### Changed 15 | - Update Cargo.lock by @orhun 16 | - Update Cargo.lock format version by @orhun 17 | 18 | ## New Contributors 19 | 20 | * @omnivagant made their first contribution in [#180](https://github.com/orhun/kmon/pull/180) 21 | 22 | ## [1.7.0] - 2024-12-12 23 | 24 | ### Added 25 | - Add support for searching kernel modules by regex by @Integral-Tech in [#178](https://github.com/orhun/kmon/pull/178) 26 | 27 | ### Changed 28 | - Use binary units for size instead of decimal units by @Integral-Tech in [#177](https://github.com/orhun/kmon/pull/177) 29 | - Replace make with $(MAKE) in example Makefile by @Integral-Tech in [#175](https://github.com/orhun/kmon/pull/175) 30 | - Replace format! with other macros/methods when unnecessary by @Integral-Tech in [#176](https://github.com/orhun/kmon/pull/176) 31 | - Use the conventional comment syntax by @Muhammad-Owais-Warsi in [#174](https://github.com/orhun/kmon/pull/174) 32 | - Run cargo fmt for formatting by @orhun 33 | - Update formatting for Rust nightly by @orhun 34 | - Apply clippy suggestions by @orhun 35 | - Update Twitter handle by @orhun 36 | - Update Arch Linux package link by @orhun 37 | - Update tui reference by @orhun 38 | - Update table of contents by @orhun 39 | - Update MSRV to 1.74.1 by @orhun 40 | - Upgrade dependencies by @orhun 41 | 42 | ## New Contributors 43 | 44 | * @Integral-Tech made their first contribution in [#178](https://github.com/orhun/kmon/pull/178) 45 | * @Muhammad-Owais-Warsi made their first contribution in [#174](https://github.com/orhun/kmon/pull/174) 46 | 47 | [1.7.0]: https://github.com/orhun/kmon/compare/v1.6.5..1.7.0 48 | 49 | ## [1.6.5] - 2024-04-12 50 | ### Added 51 | - Add a panic hook to reset terminal upon panic by @eld4niz in [#141](https://github.com/orhun/kmon/pull/141) 52 | 53 | ### Changed 54 | - Upgrade dependencies by @orhun 55 | - Bump the Rust version in Dockerfile by @orhun 56 | - Update funding options 57 | - Update license copyright years 58 | - Prepare for the release v1.6.5 59 | 60 | ### Fixed 61 | - Do not panic when /proc/modules does not exist by @eld4niz in [#139](https://github.com/orhun/kmon/pull/139) 62 | 63 | ### New Contributors 64 | * @eld4niz made their first contribution in [#139](https://github.com/orhun/kmon/pull/139) 65 | 66 | ## [1.6.4] - 2023-10-27 67 | ### Changed 68 | - Bump dependencies 69 | 70 | ### Fixed 71 | - Fix all new clippy errors with 'rustc:1.73.0' 72 | 73 | ## [1.6.3] - 2023-04-06 74 | ### Added 75 | - Build Docker image for arm64 76 | - Generate SBOM/provenance for the Docker image 77 | 78 | ### Changed 79 | - Update README.md about manual installation (#37) 80 | - Apply clippy suggestions 81 | - Switch to `ratatui` (#40) 82 | - Integrate dependabot 83 | - Bump dependencies 84 | 85 | ### Fixed 86 | - Fix typos (#38) 87 | - Remove target directory from .dockerignore for proper caching 88 | 89 | ## [1.6.2] - 2022-10-02 90 | ### Added 91 | - Add build script for generating manpage and completions ([#34](https://github.com/orhun/kmon/pull/34)) 92 | - Enable [GitHub Sponsors](https://github.com/sponsors/orhun) for funding 93 | - Consider supporting me for my open-source efforts 💖 94 | 95 | ### Changed 96 | - Update the project structure to be used as library 97 | - Apply clippy suggestions 98 | - Bump dependencies 99 | 100 | ### Fixed 101 | - Switch to [copypasta-ext](https://gitlab.com/timvisee/copypasta-ext) crate for fixing [RUSTSEC-2022-0056](https://rustsec.org/advisories/RUSTSEC-2022-0056) 102 | 103 | ## [1.6.1] - 2022-10-02 104 | 105 | ## [1.6.0] - 2021-11-05 106 | 107 | ### Added 108 | - Add [options menu](https://github.com/orhun/kmon#options-menu) for managing the kernel modules. Press `m` to show: 109 | 110 | 111 | 112 | ### Changed 113 | 114 | - Migrate to Rust 2021 edition 115 | - Bump the dependencies 116 | - Optimize CI/CD workflows 117 | 118 | ## [1.5.5] - 2021-08-11 119 | 120 | ### Changed 121 | - Center the title of kernel information block 122 | - Update dependencies to the latest version 123 | - Update the upload step in CD workflow 124 | 125 | ## [1.5.4] - 2021-07-16 126 | 127 | This release contains major code refactoring for bumping [tui-rs](https://github.com/fdehau/tui-rs/) to the latest version. Please [report](https://github.com/orhun/kmon/issues/new/choose) if you come across any unexpected behaviour. 128 | 129 | ### Changed 130 | - Update dependencies to the latest version 131 | - Update README.md about social media links and AUR installation 132 | - Update RELEASE.md to mention the release signing key 133 | 134 | ### Fixed 135 | - Make the help text copyable via `c` key press 136 | - Apply clippy suggestions 137 | 138 | ## [1.5.3] - 2020-12-15 139 | ### Fixed 140 | - Install X11 dependencies for crates.io release 141 | 142 | ## [1.5.2] - 2020-12-15 143 | ### Added 144 | - Add codecov.yml 145 | - Add strategy to CD workflow for different targets 146 | 147 | ### Changed 148 | - Update kmon.8 to include string "kmod" ([#24](https://github.com/orhun/kmon/issues/24)) 149 | - Update Cargo.toml about project details 150 | - Update Dockerfile about image and dependency versions 151 | 152 | ### Removed 153 | - Remove snapcraft.yaml 154 | 155 | ## [1.5.1] - 2020-10-09 156 | ### Fixed 157 | - Fix test failing when giving arguments to the test binary 158 | 159 | ## [1.5.0] - 2020-08-27 160 | ### Added 161 | - Add alt-e/s keys for expanding/shrinking the selected block 162 | - Add ctrl-x key for changing the position of a block 163 | 164 | ### Changed 165 | - Update the AUR installation step in README.md 166 | 167 | ### Fixed 168 | - Fix the percentage overflow in kernel module table 169 | - Use the default colors if the accent color is not provided 170 | 171 | ### Removed 172 | - Remove the AUR binary package publish step from CD workflow 173 | 174 | ## [1.4.0] - 2020-08-05 175 | ### Added 176 | - Add accent color option to set default text color 177 | 178 | ### Changed 179 | - Update README.md about accent color option 180 | - Update manual page about accent color option 181 | 182 | ## [1.3.5] - 2020-07-30 183 | ### Changed 184 | - Update README.md about Arch Linux packages 185 | - Update the release steps of AUR packages in CD workflow 186 | - Update a link in release instructions about AUR packages 187 | 188 | ### Fixed 189 | - Continue to run the CD workflow if crates.io publish fails (for re-running the workflow) 190 | 191 | ## [1.3.4] - 2020-07-30 192 | ### Fixed 193 | - Update CD workflow about AUR releases 194 | 195 | ## [1.3.3] - 2020-07-30 196 | ### Changed 197 | - Update the release instructions about git tag command 198 | 199 | ### Fixed 200 | - Update the repository secrets for fixing the CD workflow 201 | 202 | ## [1.3.2] - 2020-07-29 203 | ### Fixed 204 | - Update the publishing order in CD workflow 205 | 206 | ## [1.3.1] - 2020-07-29 207 | ### Added 208 | - Add CNAME record and theme config for the project page 209 | - Add PGP keys to CD workflow for signing the releases 210 | 211 | ### Changed 212 | - Update README.md about Copr package 213 | 214 | ## [1.3.0] - 2020-07-22 215 | ### Added 216 | - Support insmod/rmmod for low-level module handling 217 | 218 | ### Fixed 219 | - Use codecov action for uploading reports to codecov.io 220 | 221 | ### Changed 222 | - Update Cargo dependencies to the latest version 223 | - Update README.md about load/unload/reload commands 224 | - Update the CI workflow about clippy arguments 225 | 226 | ## [1.2.0] - 2020-05-03 227 | ### Added 228 | - Add `ctrl-r, alt-r` key actions for reloading a module 229 | - Add `d, alt-d` key actions for showing the dependent modules 230 | 231 | ### Fixed 232 | - Use Box instead of failure::Error 233 | 234 | ### Changed 235 | - Update the date in the manual page 236 | - Update .gitignore about Visual Studio Code 237 | - Update README.md about key binding changes 238 | 239 | ### Removed 240 | - Remove the deprecated failure crate 241 | 242 | ## [1.1.0] - 2020-04-09 243 | ### Added 244 | - Add `-d, --dependent` flag for sorting modules by their dependent modules 245 | - Add information about `-d, --dependent` flag to README.md 246 | - Add a section to README.md about installation from nixpkgs 247 | 248 | ### Fixed 249 | - Fix the CI workflow about Docker builds 250 | 251 | ### Changed 252 | - Update README.md about sorting/reversing GIFs 253 | - Improve the test cases of sort type flags 254 | 255 | ## [1.0.1] - 2020-04-05 256 | ### Added 257 | - Add Copr package instructions to README.md 258 | 259 | ### Fixed 260 | - Fix the broken manpage link in README.md 261 | 262 | ## [1.0.0] - 2020-04-01 263 | ### Added 264 | - Add roadmap, ToC, funding information and new images to README.md 265 | - Add FUNDING.yml 266 | 267 | ## [0.3.3] - 2020-03-23 268 | ### Fixed 269 | - Update the AUR (git) release step in CD workflow 270 | 271 | ## [0.3.2] - 2020-03-23 272 | ### Added 273 | - Add snapcraft.yml for the snap package 274 | 275 | ### Fixed 276 | - Fix the AUR publish actions in CD workflow according to the package guidelines 277 | 278 | ### Changed 279 | - Update .gitignore and .dockerignore files about snap package files 280 | - Update README.md about the main usage gif 281 | 282 | ## [0.3.1] - 2020-03-19 283 | ### Fixed 284 | - Fix stylize function about adding colors to the text 285 | 286 | ### Changed 287 | - Update README.md about usage information, features and images 288 | - Update descriptions of the module management commands 289 | - Update the module blacklisting command 290 | 291 | ## [0.3.0] - 2020-03-10 292 | ### Added 293 | - Add horizontal scrolling feature to kernel activities block 294 | - Add debug derive to enum types 295 | 296 | ### Fixed 297 | - Use the case insensitive alt-key combinations 298 | 299 | ### Changed 300 | - Update the runtime key bindings 301 | - Update README.md about key bindings and sections 302 | - Update the manual page about key bindings 303 | 304 | ## [0.2.2] - 2020-03-01 305 | ### Added 306 | - Update README.md about man page and project description 307 | 308 | ### Changed 309 | - Move man page file to man/ directory 310 | - Update the CD workflow about the new location of man page 311 | 312 | ## [0.2.1] - 2020-02-28 313 | ### Added 314 | - Add project installation, usage, key bindings and resources to README 315 | - Add manual page for the project 316 | - Add test for the `ctrl-l` key action 317 | 318 | ### Changed 319 | - Update the CD workflow for adding the manual page to the final binary package 320 | 321 | ## [0.2.0] - 2020-02-23 322 | ### Added 323 | - Add key bindings for clearing the kernel ring buffer 324 | - Add `--ctime` parameter to `dmesg` command for human readable date format 325 | 326 | ## [0.1.1] - 2020-02-23 327 | ### Added 328 | - Add contribution guidelines, release instructions and changelog 329 | 330 | ### Fixed 331 | - Improve the CI/CD workflows 332 | 333 | ### Changed 334 | - Update the documentation 335 | 336 | ## [0.1.0] - 2020-02-06 337 | ### Added 338 | 339 | - Add CI/CD workflows to the project for automation 340 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | kmon.cli.rs -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project owner at orhunparmaksiz@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for considering to contribute to [kmon](https://github.com/orhun/kmon/)! 4 | 5 | When contributing, please first discuss the change you wish to make via [issue](https://github.com/orhun/kmon/issues), 6 | [email](mailto:orhunparmaksiz@gmail.com), or any other method with the owners of this repository before making a change. 7 | 8 | Please note we have a [code of conduct](https://github.com/orhun/kmon/blob/master/.github/CODE_OF_CONDUCT.md), please follow it in all your interactions with the project. 9 | 10 | ## Setup 11 | 12 | 1. Fork this repository and create your branch from `master`. 13 | ``` 14 | git clone https://github.com/[username]/kmon && cd kmon 15 | ``` 16 | 17 | 2. Build the project for installing the dependencies. 18 | ``` 19 | cargo build 20 | ``` 21 | 22 | 3. Use `cargo run` command for starting the terminal interface while development. 23 | 24 | 4. Add your tests or update the existing tests according to the changes. 25 | ``` 26 | cargo test --all 27 | ``` 28 | 29 | 5. Make sure [rustfmt](https://github.com/rust-lang/rustfmt) and [clippy](https://github.com/rust-lang/rust-clippy) are passed before creating a pull request. 30 | ``` 31 | cargo fmt --all -- --check 32 | cargo clippy -- -D warnings 33 | ``` 34 | 35 | ## Create a Pull Request 36 | 37 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 38 | 39 | 2. Update the [README.md](https://github.com/orhun/kmon/blob/master/README.md) and [CHANGELOG.md](https://github.com/orhun/kmon/blob/master/CHANGELOG.md) with details of changes to the terminal user interface including new environment variables, command line arguments and container parameters. 40 | 41 | 3. Increase the version number in [Cargo.toml](https://github.com/orhun/kmon/blob/master/Cargo.toml) to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 42 | 43 | 4. You may merge the Pull Request in once you have the sign-off of the two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 44 | 45 | # License 46 | By contributing, you agree that your contributions will be licensed under [GNU General Public License 3.0](https://github.com/orhun/kmon/blob/master/LICENSE). -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.8.11" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" 10 | dependencies = [ 11 | "cfg-if", 12 | "once_cell", 13 | "version_check", 14 | "zerocopy", 15 | ] 16 | 17 | [[package]] 18 | name = "allocator-api2" 19 | version = "0.2.16" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" 22 | 23 | [[package]] 24 | name = "anstream" 25 | version = "0.6.18" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 28 | dependencies = [ 29 | "anstyle", 30 | "anstyle-parse", 31 | "anstyle-query", 32 | "anstyle-wincon", 33 | "colorchoice", 34 | "is_terminal_polyfill", 35 | "utf8parse", 36 | ] 37 | 38 | [[package]] 39 | name = "anstyle" 40 | version = "1.0.10" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 43 | 44 | [[package]] 45 | name = "anstyle-parse" 46 | version = "0.2.6" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" 49 | dependencies = [ 50 | "utf8parse", 51 | ] 52 | 53 | [[package]] 54 | name = "anstyle-query" 55 | version = "1.1.2" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" 58 | dependencies = [ 59 | "windows-sys 0.59.0", 60 | ] 61 | 62 | [[package]] 63 | name = "anstyle-wincon" 64 | version = "3.0.6" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" 67 | dependencies = [ 68 | "anstyle", 69 | "windows-sys 0.59.0", 70 | ] 71 | 72 | [[package]] 73 | name = "autocfg" 74 | version = "1.2.0" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" 77 | 78 | [[package]] 79 | name = "bitflags" 80 | version = "1.3.2" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 83 | 84 | [[package]] 85 | name = "bitflags" 86 | version = "2.6.0" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 89 | 90 | [[package]] 91 | name = "block" 92 | version = "0.1.6" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" 95 | 96 | [[package]] 97 | name = "bytesize" 98 | version = "2.0.1" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "a3c8f83209414aacf0eeae3cf730b18d6981697fba62f200fcfb92b9f082acba" 101 | 102 | [[package]] 103 | name = "cassowary" 104 | version = "0.3.0" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" 107 | 108 | [[package]] 109 | name = "castaway" 110 | version = "0.2.3" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" 113 | dependencies = [ 114 | "rustversion", 115 | ] 116 | 117 | [[package]] 118 | name = "cfg-if" 119 | version = "1.0.0" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 122 | 123 | [[package]] 124 | name = "clap" 125 | version = "4.5.23" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" 128 | dependencies = [ 129 | "clap_builder", 130 | ] 131 | 132 | [[package]] 133 | name = "clap_builder" 134 | version = "4.5.23" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" 137 | dependencies = [ 138 | "anstream", 139 | "anstyle", 140 | "clap_lex", 141 | "strsim", 142 | ] 143 | 144 | [[package]] 145 | name = "clap_complete" 146 | version = "4.5.38" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "d9647a559c112175f17cf724dc72d3645680a883c58481332779192b0d8e7a01" 149 | dependencies = [ 150 | "clap", 151 | ] 152 | 153 | [[package]] 154 | name = "clap_lex" 155 | version = "0.7.4" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 158 | 159 | [[package]] 160 | name = "clap_mangen" 161 | version = "0.2.24" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "fbae9cbfdc5d4fa8711c09bd7b83f644cb48281ac35bf97af3e47b0675864bdf" 164 | dependencies = [ 165 | "clap", 166 | "roff", 167 | ] 168 | 169 | [[package]] 170 | name = "clipboard-win" 171 | version = "3.1.1" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342" 174 | dependencies = [ 175 | "lazy-bytes-cast", 176 | "winapi", 177 | ] 178 | 179 | [[package]] 180 | name = "colorchoice" 181 | version = "1.0.3" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" 184 | 185 | [[package]] 186 | name = "colorsys" 187 | version = "0.6.7" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "54261aba646433cb567ec89844be4c4825ca92a4f8afba52fc4dd88436e31bbd" 190 | 191 | [[package]] 192 | name = "compact_str" 193 | version = "0.8.0" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" 196 | dependencies = [ 197 | "castaway", 198 | "cfg-if", 199 | "itoa", 200 | "rustversion", 201 | "ryu", 202 | "static_assertions", 203 | ] 204 | 205 | [[package]] 206 | name = "copypasta" 207 | version = "0.8.2" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "133fc8675ee3a4ec9aa513584deda9aa0faeda3586b87f7f0f2ba082c66fb172" 210 | dependencies = [ 211 | "clipboard-win", 212 | "objc", 213 | "objc-foundation", 214 | "objc_id", 215 | "smithay-clipboard", 216 | "x11-clipboard", 217 | ] 218 | 219 | [[package]] 220 | name = "copypasta-ext" 221 | version = "0.4.4" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "9455f470ea0c7d50c3fe3d22389c3a482f38a9f5fbab1c8ee368121356c56718" 224 | dependencies = [ 225 | "copypasta", 226 | "libc", 227 | "which", 228 | "x11-clipboard", 229 | ] 230 | 231 | [[package]] 232 | name = "darling" 233 | version = "0.20.10" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" 236 | dependencies = [ 237 | "darling_core", 238 | "darling_macro", 239 | ] 240 | 241 | [[package]] 242 | name = "darling_core" 243 | version = "0.20.10" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" 246 | dependencies = [ 247 | "fnv", 248 | "ident_case", 249 | "proc-macro2", 250 | "quote", 251 | "strsim", 252 | "syn", 253 | ] 254 | 255 | [[package]] 256 | name = "darling_macro" 257 | version = "0.20.10" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" 260 | dependencies = [ 261 | "darling_core", 262 | "quote", 263 | "syn", 264 | ] 265 | 266 | [[package]] 267 | name = "diff" 268 | version = "0.1.13" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" 271 | 272 | [[package]] 273 | name = "dlib" 274 | version = "0.5.2" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" 277 | dependencies = [ 278 | "libloading", 279 | ] 280 | 281 | [[package]] 282 | name = "downcast-rs" 283 | version = "1.2.1" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" 286 | 287 | [[package]] 288 | name = "either" 289 | version = "1.10.0" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" 292 | 293 | [[package]] 294 | name = "enum-iterator" 295 | version = "2.1.0" 296 | source = "registry+https://github.com/rust-lang/crates.io-index" 297 | checksum = "c280b9e6b3ae19e152d8e31cf47f18389781e119d4013a2a2bb0180e5facc635" 298 | dependencies = [ 299 | "enum-iterator-derive", 300 | ] 301 | 302 | [[package]] 303 | name = "enum-iterator-derive" 304 | version = "1.4.0" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" 307 | dependencies = [ 308 | "proc-macro2", 309 | "quote", 310 | "syn", 311 | ] 312 | 313 | [[package]] 314 | name = "errno" 315 | version = "0.3.8" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" 318 | dependencies = [ 319 | "libc", 320 | "windows-sys 0.52.0", 321 | ] 322 | 323 | [[package]] 324 | name = "fnv" 325 | version = "1.0.7" 326 | source = "registry+https://github.com/rust-lang/crates.io-index" 327 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 328 | 329 | [[package]] 330 | name = "gethostname" 331 | version = "0.2.3" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" 334 | dependencies = [ 335 | "libc", 336 | "winapi", 337 | ] 338 | 339 | [[package]] 340 | name = "hashbrown" 341 | version = "0.14.3" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" 344 | dependencies = [ 345 | "ahash", 346 | "allocator-api2", 347 | ] 348 | 349 | [[package]] 350 | name = "heck" 351 | version = "0.5.0" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 354 | 355 | [[package]] 356 | name = "home" 357 | version = "0.5.9" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" 360 | dependencies = [ 361 | "windows-sys 0.52.0", 362 | ] 363 | 364 | [[package]] 365 | name = "ident_case" 366 | version = "1.0.1" 367 | source = "registry+https://github.com/rust-lang/crates.io-index" 368 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 369 | 370 | [[package]] 371 | name = "indoc" 372 | version = "2.0.5" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" 375 | 376 | [[package]] 377 | name = "instability" 378 | version = "0.3.3" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "b829f37dead9dc39df40c2d3376c179fdfd2ac771f53f55d3c30dc096a3c0c6e" 381 | dependencies = [ 382 | "darling", 383 | "indoc", 384 | "pretty_assertions", 385 | "proc-macro2", 386 | "quote", 387 | "syn", 388 | ] 389 | 390 | [[package]] 391 | name = "is_terminal_polyfill" 392 | version = "1.70.1" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 395 | 396 | [[package]] 397 | name = "itertools" 398 | version = "0.12.1" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" 401 | dependencies = [ 402 | "either", 403 | ] 404 | 405 | [[package]] 406 | name = "itertools" 407 | version = "0.13.0" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" 410 | dependencies = [ 411 | "either", 412 | ] 413 | 414 | [[package]] 415 | name = "itoa" 416 | version = "1.0.11" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" 419 | 420 | [[package]] 421 | name = "kmon" 422 | version = "1.7.1" 423 | dependencies = [ 424 | "bytesize", 425 | "clap", 426 | "clap_complete", 427 | "clap_mangen", 428 | "colorsys", 429 | "copypasta-ext", 430 | "enum-iterator", 431 | "ratatui", 432 | "regex-lite", 433 | "termion", 434 | "unicode-width 0.1.14", 435 | ] 436 | 437 | [[package]] 438 | name = "lazy-bytes-cast" 439 | version = "5.0.1" 440 | source = "registry+https://github.com/rust-lang/crates.io-index" 441 | checksum = "10257499f089cd156ad82d0a9cd57d9501fa2c989068992a97eb3c27836f206b" 442 | 443 | [[package]] 444 | name = "lazy_static" 445 | version = "1.4.0" 446 | source = "registry+https://github.com/rust-lang/crates.io-index" 447 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 448 | 449 | [[package]] 450 | name = "libc" 451 | version = "0.2.168" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" 454 | 455 | [[package]] 456 | name = "libloading" 457 | version = "0.8.3" 458 | source = "registry+https://github.com/rust-lang/crates.io-index" 459 | checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" 460 | dependencies = [ 461 | "cfg-if", 462 | "windows-targets", 463 | ] 464 | 465 | [[package]] 466 | name = "libredox" 467 | version = "0.1.3" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" 470 | dependencies = [ 471 | "bitflags 2.6.0", 472 | "libc", 473 | "redox_syscall", 474 | ] 475 | 476 | [[package]] 477 | name = "linux-raw-sys" 478 | version = "0.4.13" 479 | source = "registry+https://github.com/rust-lang/crates.io-index" 480 | checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" 481 | 482 | [[package]] 483 | name = "log" 484 | version = "0.4.21" 485 | source = "registry+https://github.com/rust-lang/crates.io-index" 486 | checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" 487 | 488 | [[package]] 489 | name = "lru" 490 | version = "0.12.3" 491 | source = "registry+https://github.com/rust-lang/crates.io-index" 492 | checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" 493 | dependencies = [ 494 | "hashbrown", 495 | ] 496 | 497 | [[package]] 498 | name = "malloc_buf" 499 | version = "0.0.6" 500 | source = "registry+https://github.com/rust-lang/crates.io-index" 501 | checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" 502 | dependencies = [ 503 | "libc", 504 | ] 505 | 506 | [[package]] 507 | name = "memmap2" 508 | version = "0.5.10" 509 | source = "registry+https://github.com/rust-lang/crates.io-index" 510 | checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" 511 | dependencies = [ 512 | "libc", 513 | ] 514 | 515 | [[package]] 516 | name = "memoffset" 517 | version = "0.6.5" 518 | source = "registry+https://github.com/rust-lang/crates.io-index" 519 | checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" 520 | dependencies = [ 521 | "autocfg", 522 | ] 523 | 524 | [[package]] 525 | name = "nix" 526 | version = "0.24.3" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" 529 | dependencies = [ 530 | "bitflags 1.3.2", 531 | "cfg-if", 532 | "libc", 533 | "memoffset", 534 | ] 535 | 536 | [[package]] 537 | name = "numtoa" 538 | version = "0.2.4" 539 | source = "registry+https://github.com/rust-lang/crates.io-index" 540 | checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f" 541 | 542 | [[package]] 543 | name = "objc" 544 | version = "0.2.7" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" 547 | dependencies = [ 548 | "malloc_buf", 549 | ] 550 | 551 | [[package]] 552 | name = "objc-foundation" 553 | version = "0.1.1" 554 | source = "registry+https://github.com/rust-lang/crates.io-index" 555 | checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" 556 | dependencies = [ 557 | "block", 558 | "objc", 559 | "objc_id", 560 | ] 561 | 562 | [[package]] 563 | name = "objc_id" 564 | version = "0.1.1" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" 567 | dependencies = [ 568 | "objc", 569 | ] 570 | 571 | [[package]] 572 | name = "once_cell" 573 | version = "1.19.0" 574 | source = "registry+https://github.com/rust-lang/crates.io-index" 575 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 576 | 577 | [[package]] 578 | name = "paste" 579 | version = "1.0.14" 580 | source = "registry+https://github.com/rust-lang/crates.io-index" 581 | checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" 582 | 583 | [[package]] 584 | name = "pkg-config" 585 | version = "0.3.30" 586 | source = "registry+https://github.com/rust-lang/crates.io-index" 587 | checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" 588 | 589 | [[package]] 590 | name = "pretty_assertions" 591 | version = "1.4.1" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" 594 | dependencies = [ 595 | "diff", 596 | "yansi", 597 | ] 598 | 599 | [[package]] 600 | name = "proc-macro2" 601 | version = "1.0.92" 602 | source = "registry+https://github.com/rust-lang/crates.io-index" 603 | checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" 604 | dependencies = [ 605 | "unicode-ident", 606 | ] 607 | 608 | [[package]] 609 | name = "quote" 610 | version = "1.0.37" 611 | source = "registry+https://github.com/rust-lang/crates.io-index" 612 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 613 | dependencies = [ 614 | "proc-macro2", 615 | ] 616 | 617 | [[package]] 618 | name = "ratatui" 619 | version = "0.29.0" 620 | source = "registry+https://github.com/rust-lang/crates.io-index" 621 | checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b" 622 | dependencies = [ 623 | "bitflags 2.6.0", 624 | "cassowary", 625 | "compact_str", 626 | "indoc", 627 | "instability", 628 | "itertools 0.13.0", 629 | "lru", 630 | "paste", 631 | "strum", 632 | "termion", 633 | "unicode-segmentation", 634 | "unicode-truncate", 635 | "unicode-width 0.2.0", 636 | ] 637 | 638 | [[package]] 639 | name = "redox_syscall" 640 | version = "0.5.8" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" 643 | dependencies = [ 644 | "bitflags 2.6.0", 645 | ] 646 | 647 | [[package]] 648 | name = "redox_termios" 649 | version = "0.1.3" 650 | source = "registry+https://github.com/rust-lang/crates.io-index" 651 | checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" 652 | 653 | [[package]] 654 | name = "regex-lite" 655 | version = "0.1.6" 656 | source = "registry+https://github.com/rust-lang/crates.io-index" 657 | checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" 658 | 659 | [[package]] 660 | name = "roff" 661 | version = "0.2.2" 662 | source = "registry+https://github.com/rust-lang/crates.io-index" 663 | checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" 664 | 665 | [[package]] 666 | name = "rustix" 667 | version = "0.38.32" 668 | source = "registry+https://github.com/rust-lang/crates.io-index" 669 | checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" 670 | dependencies = [ 671 | "bitflags 2.6.0", 672 | "errno", 673 | "libc", 674 | "linux-raw-sys", 675 | "windows-sys 0.52.0", 676 | ] 677 | 678 | [[package]] 679 | name = "rustversion" 680 | version = "1.0.15" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" 683 | 684 | [[package]] 685 | name = "ryu" 686 | version = "1.0.17" 687 | source = "registry+https://github.com/rust-lang/crates.io-index" 688 | checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" 689 | 690 | [[package]] 691 | name = "scoped-tls" 692 | version = "1.0.1" 693 | source = "registry+https://github.com/rust-lang/crates.io-index" 694 | checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" 695 | 696 | [[package]] 697 | name = "smallvec" 698 | version = "1.13.2" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 701 | 702 | [[package]] 703 | name = "smithay-client-toolkit" 704 | version = "0.16.1" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" 707 | dependencies = [ 708 | "bitflags 1.3.2", 709 | "dlib", 710 | "lazy_static", 711 | "log", 712 | "memmap2", 713 | "nix", 714 | "pkg-config", 715 | "wayland-client", 716 | "wayland-cursor", 717 | "wayland-protocols", 718 | ] 719 | 720 | [[package]] 721 | name = "smithay-clipboard" 722 | version = "0.6.6" 723 | source = "registry+https://github.com/rust-lang/crates.io-index" 724 | checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" 725 | dependencies = [ 726 | "smithay-client-toolkit", 727 | "wayland-client", 728 | ] 729 | 730 | [[package]] 731 | name = "static_assertions" 732 | version = "1.1.0" 733 | source = "registry+https://github.com/rust-lang/crates.io-index" 734 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 735 | 736 | [[package]] 737 | name = "strsim" 738 | version = "0.11.1" 739 | source = "registry+https://github.com/rust-lang/crates.io-index" 740 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 741 | 742 | [[package]] 743 | name = "strum" 744 | version = "0.26.3" 745 | source = "registry+https://github.com/rust-lang/crates.io-index" 746 | checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" 747 | dependencies = [ 748 | "strum_macros", 749 | ] 750 | 751 | [[package]] 752 | name = "strum_macros" 753 | version = "0.26.4" 754 | source = "registry+https://github.com/rust-lang/crates.io-index" 755 | checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" 756 | dependencies = [ 757 | "heck", 758 | "proc-macro2", 759 | "quote", 760 | "rustversion", 761 | "syn", 762 | ] 763 | 764 | [[package]] 765 | name = "syn" 766 | version = "2.0.90" 767 | source = "registry+https://github.com/rust-lang/crates.io-index" 768 | checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" 769 | dependencies = [ 770 | "proc-macro2", 771 | "quote", 772 | "unicode-ident", 773 | ] 774 | 775 | [[package]] 776 | name = "termion" 777 | version = "4.0.3" 778 | source = "registry+https://github.com/rust-lang/crates.io-index" 779 | checksum = "7eaa98560e51a2cf4f0bb884d8b2098a9ea11ecf3b7078e9c68242c74cc923a7" 780 | dependencies = [ 781 | "libc", 782 | "libredox", 783 | "numtoa", 784 | "redox_termios", 785 | ] 786 | 787 | [[package]] 788 | name = "unicode-ident" 789 | version = "1.0.14" 790 | source = "registry+https://github.com/rust-lang/crates.io-index" 791 | checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 792 | 793 | [[package]] 794 | name = "unicode-segmentation" 795 | version = "1.11.0" 796 | source = "registry+https://github.com/rust-lang/crates.io-index" 797 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" 798 | 799 | [[package]] 800 | name = "unicode-truncate" 801 | version = "1.0.0" 802 | source = "registry+https://github.com/rust-lang/crates.io-index" 803 | checksum = "5a5fbabedabe362c618c714dbefda9927b5afc8e2a8102f47f081089a9019226" 804 | dependencies = [ 805 | "itertools 0.12.1", 806 | "unicode-width 0.1.14", 807 | ] 808 | 809 | [[package]] 810 | name = "unicode-width" 811 | version = "0.1.14" 812 | source = "registry+https://github.com/rust-lang/crates.io-index" 813 | checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" 814 | 815 | [[package]] 816 | name = "unicode-width" 817 | version = "0.2.0" 818 | source = "registry+https://github.com/rust-lang/crates.io-index" 819 | checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" 820 | 821 | [[package]] 822 | name = "utf8parse" 823 | version = "0.2.2" 824 | source = "registry+https://github.com/rust-lang/crates.io-index" 825 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 826 | 827 | [[package]] 828 | name = "version_check" 829 | version = "0.9.4" 830 | source = "registry+https://github.com/rust-lang/crates.io-index" 831 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 832 | 833 | [[package]] 834 | name = "wayland-client" 835 | version = "0.29.5" 836 | source = "registry+https://github.com/rust-lang/crates.io-index" 837 | checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" 838 | dependencies = [ 839 | "bitflags 1.3.2", 840 | "downcast-rs", 841 | "libc", 842 | "nix", 843 | "scoped-tls", 844 | "wayland-commons", 845 | "wayland-scanner", 846 | "wayland-sys", 847 | ] 848 | 849 | [[package]] 850 | name = "wayland-commons" 851 | version = "0.29.5" 852 | source = "registry+https://github.com/rust-lang/crates.io-index" 853 | checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" 854 | dependencies = [ 855 | "nix", 856 | "once_cell", 857 | "smallvec", 858 | "wayland-sys", 859 | ] 860 | 861 | [[package]] 862 | name = "wayland-cursor" 863 | version = "0.29.5" 864 | source = "registry+https://github.com/rust-lang/crates.io-index" 865 | checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" 866 | dependencies = [ 867 | "nix", 868 | "wayland-client", 869 | "xcursor", 870 | ] 871 | 872 | [[package]] 873 | name = "wayland-protocols" 874 | version = "0.29.5" 875 | source = "registry+https://github.com/rust-lang/crates.io-index" 876 | checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" 877 | dependencies = [ 878 | "bitflags 1.3.2", 879 | "wayland-client", 880 | "wayland-commons", 881 | "wayland-scanner", 882 | ] 883 | 884 | [[package]] 885 | name = "wayland-scanner" 886 | version = "0.29.5" 887 | source = "registry+https://github.com/rust-lang/crates.io-index" 888 | checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" 889 | dependencies = [ 890 | "proc-macro2", 891 | "quote", 892 | "xml-rs", 893 | ] 894 | 895 | [[package]] 896 | name = "wayland-sys" 897 | version = "0.29.5" 898 | source = "registry+https://github.com/rust-lang/crates.io-index" 899 | checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" 900 | dependencies = [ 901 | "dlib", 902 | "lazy_static", 903 | "pkg-config", 904 | ] 905 | 906 | [[package]] 907 | name = "which" 908 | version = "4.4.2" 909 | source = "registry+https://github.com/rust-lang/crates.io-index" 910 | checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" 911 | dependencies = [ 912 | "either", 913 | "home", 914 | "once_cell", 915 | "rustix", 916 | ] 917 | 918 | [[package]] 919 | name = "winapi" 920 | version = "0.3.9" 921 | source = "registry+https://github.com/rust-lang/crates.io-index" 922 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 923 | dependencies = [ 924 | "winapi-i686-pc-windows-gnu", 925 | "winapi-x86_64-pc-windows-gnu", 926 | ] 927 | 928 | [[package]] 929 | name = "winapi-i686-pc-windows-gnu" 930 | version = "0.4.0" 931 | source = "registry+https://github.com/rust-lang/crates.io-index" 932 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 933 | 934 | [[package]] 935 | name = "winapi-wsapoll" 936 | version = "0.1.2" 937 | source = "registry+https://github.com/rust-lang/crates.io-index" 938 | checksum = "1eafc5f679c576995526e81635d0cf9695841736712b4e892f87abbe6fed3f28" 939 | dependencies = [ 940 | "winapi", 941 | ] 942 | 943 | [[package]] 944 | name = "winapi-x86_64-pc-windows-gnu" 945 | version = "0.4.0" 946 | source = "registry+https://github.com/rust-lang/crates.io-index" 947 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 948 | 949 | [[package]] 950 | name = "windows-sys" 951 | version = "0.52.0" 952 | source = "registry+https://github.com/rust-lang/crates.io-index" 953 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 954 | dependencies = [ 955 | "windows-targets", 956 | ] 957 | 958 | [[package]] 959 | name = "windows-sys" 960 | version = "0.59.0" 961 | source = "registry+https://github.com/rust-lang/crates.io-index" 962 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 963 | dependencies = [ 964 | "windows-targets", 965 | ] 966 | 967 | [[package]] 968 | name = "windows-targets" 969 | version = "0.52.6" 970 | source = "registry+https://github.com/rust-lang/crates.io-index" 971 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 972 | dependencies = [ 973 | "windows_aarch64_gnullvm", 974 | "windows_aarch64_msvc", 975 | "windows_i686_gnu", 976 | "windows_i686_gnullvm", 977 | "windows_i686_msvc", 978 | "windows_x86_64_gnu", 979 | "windows_x86_64_gnullvm", 980 | "windows_x86_64_msvc", 981 | ] 982 | 983 | [[package]] 984 | name = "windows_aarch64_gnullvm" 985 | version = "0.52.6" 986 | source = "registry+https://github.com/rust-lang/crates.io-index" 987 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 988 | 989 | [[package]] 990 | name = "windows_aarch64_msvc" 991 | version = "0.52.6" 992 | source = "registry+https://github.com/rust-lang/crates.io-index" 993 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 994 | 995 | [[package]] 996 | name = "windows_i686_gnu" 997 | version = "0.52.6" 998 | source = "registry+https://github.com/rust-lang/crates.io-index" 999 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 1000 | 1001 | [[package]] 1002 | name = "windows_i686_gnullvm" 1003 | version = "0.52.6" 1004 | source = "registry+https://github.com/rust-lang/crates.io-index" 1005 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 1006 | 1007 | [[package]] 1008 | name = "windows_i686_msvc" 1009 | version = "0.52.6" 1010 | source = "registry+https://github.com/rust-lang/crates.io-index" 1011 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 1012 | 1013 | [[package]] 1014 | name = "windows_x86_64_gnu" 1015 | version = "0.52.6" 1016 | source = "registry+https://github.com/rust-lang/crates.io-index" 1017 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 1018 | 1019 | [[package]] 1020 | name = "windows_x86_64_gnullvm" 1021 | version = "0.52.6" 1022 | source = "registry+https://github.com/rust-lang/crates.io-index" 1023 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 1024 | 1025 | [[package]] 1026 | name = "windows_x86_64_msvc" 1027 | version = "0.52.6" 1028 | source = "registry+https://github.com/rust-lang/crates.io-index" 1029 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 1030 | 1031 | [[package]] 1032 | name = "x11-clipboard" 1033 | version = "0.7.1" 1034 | source = "registry+https://github.com/rust-lang/crates.io-index" 1035 | checksum = "980b9aa9226c3b7de8e2adb11bf20124327c054e0e5812d2aac0b5b5a87e7464" 1036 | dependencies = [ 1037 | "x11rb", 1038 | ] 1039 | 1040 | [[package]] 1041 | name = "x11rb" 1042 | version = "0.10.1" 1043 | source = "registry+https://github.com/rust-lang/crates.io-index" 1044 | checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" 1045 | dependencies = [ 1046 | "gethostname", 1047 | "nix", 1048 | "winapi", 1049 | "winapi-wsapoll", 1050 | "x11rb-protocol", 1051 | ] 1052 | 1053 | [[package]] 1054 | name = "x11rb-protocol" 1055 | version = "0.10.0" 1056 | source = "registry+https://github.com/rust-lang/crates.io-index" 1057 | checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" 1058 | dependencies = [ 1059 | "nix", 1060 | ] 1061 | 1062 | [[package]] 1063 | name = "xcursor" 1064 | version = "0.3.5" 1065 | source = "registry+https://github.com/rust-lang/crates.io-index" 1066 | checksum = "6a0ccd7b4a5345edfcd0c3535718a4e9ff7798ffc536bb5b5a0e26ff84732911" 1067 | 1068 | [[package]] 1069 | name = "xml-rs" 1070 | version = "0.8.20" 1071 | source = "registry+https://github.com/rust-lang/crates.io-index" 1072 | checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" 1073 | 1074 | [[package]] 1075 | name = "yansi" 1076 | version = "1.0.1" 1077 | source = "registry+https://github.com/rust-lang/crates.io-index" 1078 | checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" 1079 | 1080 | [[package]] 1081 | name = "zerocopy" 1082 | version = "0.7.32" 1083 | source = "registry+https://github.com/rust-lang/crates.io-index" 1084 | checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" 1085 | dependencies = [ 1086 | "zerocopy-derive", 1087 | ] 1088 | 1089 | [[package]] 1090 | name = "zerocopy-derive" 1091 | version = "0.7.32" 1092 | source = "registry+https://github.com/rust-lang/crates.io-index" 1093 | checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" 1094 | dependencies = [ 1095 | "proc-macro2", 1096 | "quote", 1097 | "syn", 1098 | ] 1099 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kmon" 3 | version = "1.7.1" 4 | description = "Linux kernel manager and activity monitor" 5 | authors = ["Orhun Parmaksız "] 6 | license = "GPL-3.0" 7 | readme = "README.md" 8 | documentation = "https://github.com/orhun/kmon/blob/master/README.md" 9 | homepage = "https://kmon.cli.rs" 10 | repository = "https://github.com/orhun/kmon" 11 | keywords = ["linux", "kernel", "module", "activity", "monitor"] 12 | categories = ["command-line-utilities", "os"] 13 | include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md"] 14 | edition = "2021" 15 | 16 | [dependencies] 17 | ratatui = { version = "0.29.0", default-features = false, features = [ 18 | "termion", 19 | ] } 20 | termion = "4.0.3" 21 | bytesize = "2.0.1" 22 | unicode-width = "0.1.14" 23 | colorsys = "0.6.7" 24 | enum-iterator = "2.1.0" 25 | clap = "4.5.23" 26 | copypasta-ext = "0.4.4" 27 | regex-lite = "0.1.6" 28 | 29 | [build-dependencies] 30 | clap_mangen = "0.2.24" 31 | clap_complete = "4.5.38" 32 | clap = "4.5.23" 33 | 34 | [profile.dev] 35 | opt-level = 0 36 | debug = true 37 | panic = "abort" 38 | 39 | [profile.test] 40 | opt-level = 0 41 | debug = true 42 | 43 | [profile.release] 44 | opt-level = 3 45 | debug = false 46 | panic = "abort" 47 | lto = true 48 | codegen-units = 1 49 | 50 | [profile.bench] 51 | opt-level = 3 52 | debug = false 53 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Builder 2 | FROM rust:1.77.2-slim-buster as builder 3 | RUN apt-get update && \ 4 | apt-get install -y --no-install-recommends \ 5 | --allow-unauthenticated \ 6 | libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev \ 7 | && apt-get clean && rm -rf /var/lib/apt/lists/* 8 | WORKDIR /app/ 9 | COPY Cargo.toml Cargo.toml 10 | RUN mkdir src/ && echo "fn main() {println!(\"failed to build\")}" > src/main.rs 11 | RUN cargo build --release --verbose 12 | RUN rm -f target/release/deps/kmon* 13 | COPY . . 14 | RUN cargo build --locked --release --verbose 15 | RUN mkdir -p build-out && cp target/release/kmon build-out/ 16 | 17 | # Runtime 18 | FROM debian:buster-slim as runtime-image 19 | RUN apt-get update && \ 20 | apt-get install -y --no-install-recommends \ 21 | --allow-unauthenticated \ 22 | kmod \ 23 | libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev \ 24 | && apt-get clean && rm -rf /var/lib/apt/lists/* 25 | WORKDIR /root/ 26 | COPY --from=builder /app/build-out/kmon . 27 | CMD ["./kmon"] 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |
5 | Linux Kernel Manager and Activity Monitor 🐧💻 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |

34 | 35 | **The kernel** is the part of the operating system that facilitates interactions between _hardware_ and _software_ components. On most systems, it is loaded on startup after the _bootloader_ and handles I/O requests as well as peripherals like keyboards, monitors, network adapters, and speakers. Typically, the kernel is responsible for **memory management**, **process management**, **device management**, **system calls**, and **security**. 36 | Applications use the **system call** mechanism for requesting a service from the operating system and most of the time, this request is passed to the kernel using a library provided by the operating system to invoke the related kernel function. While the kernel performs these low-level tasks, it's resident on a separate part of memory named **protected kernel space** which is not accessible by applications and other parts of the system. In contrast, applications like browsers, text editors, window managers or audio/video players use a different separate area of the memory, **user space**. This separation prevents user data and kernel data from interfering with each other and causing instability and slowness, as well as preventing malfunctioning application programs from crashing the entire operating system. 37 | There are different kernel designs due to the different ways of managing system calls and resources. For example, while **monolithic kernels** run all the operating system instructions in the same address space _for speed_, **microkernels** use different spaces for user and kernel services _for modularity_. Apart from those, there are **hybrid kernels**, **nanokernels**, and, **exokernels**. The hybrid kernel architecture is based on combining aspects of microkernel and monolithic kernels. 38 | 39 | **The Linux kernel** is the open-source, monolithic and, Unix-like operating system kernel that used in the Linux distributions, various embedded systems such as routers and as well as in the all Android-based systems. **Linus Torvalds** conceived and created the Linux kernel in 1991 and it's still being developed by thousands of developers today. It's a prominent example of **free and open source software** and it's used in other free software projects, notably the **GNU operating system**. 40 | Although the Linux-based operating systems dominate the most of computing, it still carries some of the design flaws which were quite a bit of debate in the early days of Linux. For example, it has the **largest footprint** and **the most complexity** over the other types of kernels. But it's a design feature that monolithic kernels inherent to have. These kind of design issues led developers to add new features and mechanisms to the Linux kernel which other kernels don't have. 41 | 42 | Unlike the standard monolithic kernels, the Linux kernel is also **modular**, accepting **loadable kernel modules (LKM)** that typically used to add support for new _hardware_ (as device drivers) and/or _filesystems_, or for adding _system calls_. Since LKMs could be loaded and unloaded to the system _at runtime_, they have the advantage of extending the kernel without rebooting and re-compiling. Thus, the kernel functionalities provided by modules would not reside in memory without being used and the related module can be unloaded in order to free memory and other resources. 43 | Loadable kernel modules are located in `/lib/modules` with the `.ko` (_kernel object_) extension in Linux. While the [lsmod](https://linux.die.net/man/8/lsmod) command could be used for listing the loaded kernel modules, [modprobe](https://linux.die.net/man/8/modprobe) or [insmod](https://linux.die.net/man/8/insmod)/[rmmod](https://linux.die.net/man/8/rmmod) is used for loading or unloading a kernel module. insmod/rmmod are used for modules independent of modprobe and without requiring an installation to `/lib/modules/$(uname -r)`. 44 | 45 | Here's a simple example of a Linux kernel module that prints a message when it's loaded and unloaded. The build and installation steps of the [module](https://github.com/orhun/kmon/blob/master/example/lkm_example.c) using a [Makefile](https://github.com/orhun/kmon/blob/master/example/Makefile) are shown below. 46 | 47 | ``` 48 | make # build 49 | sudo make install # install 50 | sudo modprobe lkm_example # load 51 | sudo modprobe -r lkm_example # unload 52 | ``` 53 | 54 | The [dmesg](https://linux.die.net/man/8/dmesg) command is used below to retrieve the message buffer of the kernel. 55 | 56 | ``` 57 | [16994.295552] [+] Example kernel module loaded. 58 | [16996.325674] [-] Example kernel module unloaded. 59 | ``` 60 | 61 | **kmon** provides a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface) for managing the Linux kernel modules and monitoring the kernel activities. By managing, it means loading, unloading, blacklisting and showing the information of a module. These updates in the kernel modules, logs about the hardware and other kernel messages can be tracked with the real-time activity monitor in kmon. Since the usage of different tools like [dmesg](https://en.wikipedia.org/wiki/Dmesg) and [kmod](https://www.linux.org/docs/man8/kmod.html) are required for these tasks in Linux, kmon aims to gather them in a single terminal window and facilitate the usage as much as possible while keeping the functionality. 62 | 63 | kmon is written in [Rust](https://www.rust-lang.org/) and uses [Ratatui](https://ratatui.rs) & [termion](https://github.com/redox-os/termion) libraries for its text-based user interface. 64 | 65 | ### Table of Contents 66 | 67 | 68 | 69 | - [Installation](#installation) 70 | - [Cargo](#cargo) 71 | - [Arch Linux](#arch-linux) 72 | - [Nixpkgs](#nixpkgs) 73 | - [Alpine Linux](#alpine-linux) 74 | - [Docker](#docker) 75 | - [Build](#build) 76 | - [Run](#run) 77 | - [Manual](#manual) 78 | - [Note](#note) 79 | - [Usage](#usage) 80 | - [Options](#options) 81 | - [Commands](#commands) 82 | - [Sort](#sort) 83 | - [Key Bindings](#key-bindings) 84 | - [Features](#features) 85 | - [Help](#help) 86 | - [Navigating & Scrolling](#navigating--scrolling) 87 | - [Scrolling Kernel Activities](#scrolling-kernel-activities) 88 | - [Smooth Scrolling](#smooth-scrolling) 89 | - [Options Menu](#options-menu) 90 | - [Block Sizes](#block-sizes) 91 | - [Block Positions](#block-positions) 92 | - [Kernel Information](#kernel-information) 93 | - [Module Information](#module-information) 94 | - [Displaying the dependent modules](#displaying-the-dependent-modules) 95 | - [Jumping to dependent modules](#jumping-to-dependent-modules) 96 | - [Searching a module](#searching-a-module) 97 | - [Loading a module](#loading-a-module) 98 | - [Unloading a module](#unloading-a-module) 99 | - [Blacklisting a module](#blacklisting-a-module) 100 | - [Reloading a module](#reloading-a-module) 101 | - [Clearing the ring buffer](#clearing-the-ring-buffer) 102 | - [Copy & Paste](#copy--paste) 103 | - [Sorting/reversing the kernel modules](#sortingreversing-the-kernel-modules) 104 | - [Customizing the colors](#customizing-the-colors) 105 | - [Supported colors](#supported-colors) 106 | - [Using a custom color](#using-a-custom-color) 107 | - [Changing the accent color](#changing-the-accent-color) 108 | - [Unicode symbols](#unicode-symbols) 109 | - [Setting the terminal tick rate](#setting-the-terminal-tick-rate) 110 | - [Searching modules by regular expression](#searching-modules-by-regular-expression) 111 | - [Roadmap](#roadmap) 112 | - [Accessibility](#accessibility) 113 | - [Dependencies](#dependencies) 114 | - [Features](#features-1) 115 | - [Testing](#testing) 116 | - [Resources](#resources) 117 | - [About the project](#about-the-project) 118 | - [Articles](#articles) 119 | - [In the media](#in-the-media) 120 | - [Gallery](#gallery) 121 | - [Social Media](#social-media) 122 | - [Funding](#funding) 123 | - [GitHub](#github) 124 | - [Patreon](#patreon) 125 | - [Open Collective](#open-collective) 126 | - [License](#license) 127 | - [Copyright](#copyright) 128 | 129 | 130 | 131 | ## Installation 132 | 133 | [![Packaging status](https://repology.org/badge/vertical-allrepos/kmon.svg)](https://repology.org/project/kmon/versions) 134 | 135 | ### Cargo 136 | 137 | **kmon** can be installed from [crates.io](https://crates.io/crates/kmon/) using Cargo if [Rust](https://www.rust-lang.org/tools/install) is installed. 138 | 139 | ``` 140 | cargo install kmon 141 | ``` 142 | 143 | The minimum supported Rust version (MSRV) is `1.74.1`. 144 | 145 | ### Arch Linux 146 | 147 | **kmon** can be installed from the Arch Linux [official repository](https://www.archlinux.org/packages/extra/x86_64/kmon/). 148 | 149 | ``` 150 | pacman -S kmon 151 | ``` 152 | 153 | There is also a development package on the [AUR](https://aur.archlinux.org/packages/kmon-git/). Use your favorite [AUR helper](https://wiki.archlinux.org/index.php/AUR_helpers) to install. For example, 154 | 155 | ``` 156 | paru -S kmon-git 157 | ``` 158 | 159 | ### Nixpkgs 160 | 161 | **kmon** can be installed using [Nix package manager](https://nixos.org/nix/) from `nixpkgs-unstable` channel. 162 | 163 | ``` 164 | nix-channel --add https://nixos.org/channels/nixpkgs-unstable 165 | nix-channel --update nixpkgs 166 | nix-env -iA nixpkgs.kmon 167 | ``` 168 | 169 | On [NixOS](https://nixos.org/nixos/): 170 | 171 | ``` 172 | nix-channel --add https://nixos.org/channels/nixos-unstable 173 | nix-channel --update nixos 174 | nix-env -iA nixos.kmon 175 | ``` 176 | 177 | ### Alpine Linux 178 | 179 | **kmon** is available for [Alpine Edge](https://pkgs.alpinelinux.org/packages?name=kmon&branch=edge). It can be installed via [apk](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper) after enabling the [community repository](https://wiki.alpinelinux.org/wiki/Repositories). 180 | 181 | ``` 182 | apk add kmon 183 | ``` 184 | 185 | ### Docker 186 | 187 | [![Docker Hub Build Status](https://img.shields.io/github/actions/workflow/status/orhun/kmon/docker.yml?color=000000&label=docker%20hub&style=flat-square)](https://hub.docker.com/r/orhunp/kmon) 188 | 189 | ``` 190 | docker run -it --cap-add syslog orhunp/kmon:tagname 191 | ``` 192 | 193 | #### Build 194 | 195 | ``` 196 | docker build -t kmon . 197 | ``` 198 | 199 | #### Run 200 | 201 | ``` 202 | docker run -it --cap-add syslog kmon 203 | ``` 204 | 205 | ### Manual 206 | 207 | 1. Download the latest binary from [releases](https://github.com/orhun/kmon/releases) section and pick between [glibc](https://en.wikipedia.org/wiki/Glibc) or [musl-libc](https://musl.libc.org/) binary. 208 | 2. To download the package compiled with [glibc](https://en.wikipedia.org/wiki/Glibc) run: 209 | 210 | ``` 211 | wget https://github.com/orhun/kmon/releases/download/v[VERSION]/kmon-[VERSION]-x86_64-unknown-linux-gnu.tar.gz 212 | ``` 213 | 214 | 3. To download the package compiled with [musl-libc](https://musl.libc.org/) run: 215 | 216 | ``` 217 | wget https://github.com/orhun/kmon/releases/download/v[VERSION]/kmon-[VERSION]-x86_64-unknown-linux-musl.tar.gz 218 | ``` 219 | 220 | 3. Extract the files. 221 | 222 | ``` 223 | tar -xvzf kmon-*.tar.gz 224 | ``` 225 | 226 | 4. Enter in the new folder. 227 | 228 | ``` 229 | cd kmon-[VERSION] 230 | ``` 231 | 232 | 5. Run the binary. 233 | 234 | ``` 235 | ./kmon 236 | ``` 237 | 238 | 6. Move binary to `/usr/local/bin/` for running it from the terminal using `kmon` command. 239 | 240 | 7. Man page and shell completions are generated at build time in `target` directory. 241 | 242 | #### Note 243 | 244 | [libxcb](https://xcb.freedesktop.org/) should be installed for using the copy/paste commands of X11. 245 | 246 | e.g: Install `libxcb1-dev` package for Debian/Ubuntu[\*](https://github.com/orhun/kmon/issues/2) and `libxcb-devel` package for Fedora/openSUSE/Void Linux. 247 | 248 | ## Usage 249 | 250 | ``` 251 | kmon [OPTIONS] [COMMAND] 252 | ``` 253 | 254 | ### Options 255 | 256 | ``` 257 | -a, --accent-color Set the accent color using hex or color name [default: white] 258 | -c, --color Set the main color using hex or color name [default: darkgray] 259 | -t, --tickrate Set the refresh rate of the terminal [default: 250] 260 | -r, --reverse Reverse the kernel module list 261 | -u, --unicode Show Unicode symbols for the block titles 262 | -E, --regex Interpret the module search query as a regular expression 263 | -h, --help Print help information 264 | -V, --version Print version information 265 | ``` 266 | 267 | ### Commands 268 | 269 | ``` 270 | sort Sort kernel modules 271 | ``` 272 | 273 | #### Sort 274 | 275 | ``` 276 | kmon sort [OPTIONS] 277 | ``` 278 | 279 | **Options:** 280 | 281 | ``` 282 | -s, --size Sort modules by their sizes 283 | -n, --name Sort modules by their names 284 | -d, --dependent Sort modules by their dependent modules 285 | -h, --help Print help information 286 | ``` 287 | 288 | ## Key Bindings 289 | 290 | | | | 291 | | ----------------------- | ------------------------------------- | 292 | | `[?], F1` | Help | 293 | | `right/left, h/l` | Switch between blocks | 294 | | `up/down, k/j, alt-k/j` | Scroll up/down [selected block] | 295 | | `pgup/pgdown` | Scroll up/down [kernel activities] | 296 | | `` | Scroll up/down [module information] | 297 | | `alt-h/l` | Scroll right/left [kernel activities] | 298 | | `ctrl-t/b, home/end` | Scroll to top/bottom [module list] | 299 | | `alt-e/s` | Expand/shrink the selected block | 300 | | `ctrl-x` | Change the block position | 301 | | `ctrl-l/u, alt-c` | Clear the kernel ring buffer | 302 | | `[d], alt-d` | Show the dependent modules | 303 | | `[1]..[9]` | Jump to the dependent module | 304 | | `[\], tab, backtab` | Show the next kernel information | 305 | | `[/], s, enter` | Search a kernel module | 306 | | `[+], i, insert` | Load a kernel module | 307 | | `[-], u, backspace` | Unload the kernel module | 308 | | `[x], b, delete` | Blacklist the kernel module | 309 | | `ctrl-r, alt-r` | Reload the kernel module | 310 | | `m, o` | Show the options menu | 311 | | `y/n` | Execute/cancel the command | 312 | | `c/v` | Copy/paste | 313 | | `r, F5` | Refresh | 314 | | `q, ctrl-c/d, ESC` | Quit | 315 | 316 | ## Features 317 | 318 | ### Help 319 | 320 | Press '`?`' while running the terminal UI to see key bindings. 321 | 322 | ![Help](https://user-images.githubusercontent.com/24392180/76685660-8d155f80-6626-11ea-9aa6-f3eb26a3869f.gif) 323 | 324 | ### Navigating & Scrolling 325 | 326 | `Arrow keys` are used for navigating between blocks and scrolling. 327 | 328 | ![Navigating & Scrolling](https://user-images.githubusercontent.com/24392180/76685750-26447600-6627-11ea-99fd-157449c9529f.gif) 329 | 330 | #### Scrolling Kernel Activities 331 | 332 | Some kernel messages might be long enough for not fitting into the kernel activities block since they are not wrapped. In this situation, kernel activities can be scrolled horizontally with `alt-h & alt-l` keys. Vertical scrolling mechanism is the same as other blocks. 333 | 334 | ![Scrolling Kernel Activities](https://user-images.githubusercontent.com/24392180/76685862-fe094700-6627-11ea-9996-4ff1d177baf3.gif) 335 | 336 | #### Smooth Scrolling 337 | 338 | `alt-j & alt-k` keys can be used to scroll kernel activity and module information blocks slowly. 339 | 340 | ![Smooth Scrolling](https://user-images.githubusercontent.com/24392180/76685907-4aed1d80-6628-11ea-96b7-a5bc0597455b.gif) 341 | 342 | ### Options Menu 343 | 344 | `m` and `o` keys can be used as a shortcut for kernel management operations. When pressed, an options menu will be provided for managing the currently selected kernel module. 345 | 346 | ![Options Menu](https://user-images.githubusercontent.com/24392180/140408275-5c400e39-c1e6-4484-85fe-f39160a842a0.gif) 347 | 348 | ### Block Sizes 349 | 350 | `alt-e & alt-s` keys can be used for expanding/shrinking the selected block. 351 | 352 | ![Block Sizes](https://user-images.githubusercontent.com/24392180/89716231-f8841300-d9b3-11ea-9cea-ee9816174336.gif) 353 | 354 | ### Block Positions 355 | 356 | `ctrl-x` key can be used for changing the positions of blocks. 357 | 358 | ![Block Positions](https://user-images.githubusercontent.com/24392180/90258934-e68dee80-de51-11ea-951a-ec5a301608a6.gif) 359 | 360 | ### Kernel Information 361 | 362 | Use one of the `\, tab, backtab` keys to switch between kernel release, version and platform information. 363 | 364 | ![Kernel Information](https://user-images.githubusercontent.com/24392180/76686943-9f949680-6630-11ea-9045-a8f83313faa1.gif) 365 | 366 | ### Module Information 367 | 368 | The status of a kernel module is shown on selection. 369 | 370 | ![Module Information](https://user-images.githubusercontent.com/24392180/76685957-b931e000-6628-11ea-8657-76047deee681.gif) 371 | 372 | #### Displaying the dependent modules 373 | 374 | Use one of the `d, alt-d` keys to show all the dependent modules of the selected module. 375 | 376 | ![Displaying the dependent modules](https://user-images.githubusercontent.com/24392180/80925098-d6b43800-8d95-11ea-8b41-da7d93fd12f8.gif) 377 | 378 | #### Jumping to dependent modules 379 | 380 | For jumping to a dependent kernel module from its parent module, `number keys` (1-9) can be used for specifying the index of the module on the _Used By_ column. 381 | 382 | ![Dependency Information](https://user-images.githubusercontent.com/24392180/76685972-eaaaab80-6628-11ea-94dd-630e07827949.gif) 383 | 384 | ### Searching a module 385 | 386 | Switch to the search area with arrow keys or using one of the `/, s, enter` and provide a search query for the module name. 387 | 388 | ![Searching a module](https://user-images.githubusercontent.com/24392180/76686001-23e31b80-6629-11ea-9e9a-ff92c6a05cdd.gif) 389 | 390 | ### Loading a module 391 | 392 | For adding a module to the Linux kernel, switch to load mode with one of the `+, i, insert` keys and provide the name of the module to load. Then confirm/cancel the execution of the load command with `y/n`. 393 | 394 | ![Loading a module](https://user-images.githubusercontent.com/24392180/76686027-64429980-6629-11ea-852f-1316ff08ec80.gif) 395 | 396 | The command that used for loading a module: 397 | 398 | ``` 399 | modprobe || insmod .ko 400 | ``` 401 | 402 | ### Unloading a module 403 | 404 | Use one of the `-, u, backspace` keys to remove the selected module from the Linux kernel. 405 | 406 | ![Unloading a module](https://user-images.githubusercontent.com/24392180/76686045-8b996680-6629-11ea-9d8c-c0f5b367e269.gif) 407 | 408 | The command that used for removing a module: 409 | 410 | ``` 411 | modprobe -r || rmmod 412 | ``` 413 | 414 | ### Blacklisting a module 415 | 416 | [Blacklisting](https://wiki.archlinux.org/index.php/Kernel_module#Blacklisting) is a mechanism to prevent the kernel module from loading. To blacklist the selected module, use one of the `x, b, delete` keys and confirm the execution. 417 | 418 | ![Blacklisting a module](https://user-images.githubusercontent.com/24392180/77003935-48176300-696f-11ea-9047-41f6a934be6e.gif) 419 | 420 | The command that used for blacklisting a module: 421 | 422 | ``` 423 | if ! grep -q /etc/modprobe.d/blacklist.conf; then 424 | echo 'blacklist ' >> /etc/modprobe.d/blacklist.conf 425 | echo 'install /bin/false' >> /etc/modprobe.d/blacklist.conf 426 | fi 427 | ``` 428 | 429 | ### Reloading a module 430 | 431 | Use `ctrl-r` or `alt-r` key for reloading the selected module. 432 | 433 | ![Reloading a module](https://user-images.githubusercontent.com/24392180/80925109-f3507000-8d95-11ea-9004-4063907f0cfc.gif) 434 | 435 | The command that used for reloading a module: 436 | 437 | ``` 438 | modprobe -r || rmmod && modprobe || insmod .ko 439 | ``` 440 | 441 | ### Clearing the ring buffer 442 | 443 | The kernel ring buffer can be cleared with using one of the `ctrl-l/u, alt-c` keys. 444 | 445 | ![Clearing the ring buffer](https://user-images.githubusercontent.com/24392180/76686162-87217d80-662a-11ea-9ced-36bb1e7a942b.gif) 446 | 447 | ``` 448 | dmesg --clear 449 | ``` 450 | 451 | ### Copy & Paste 452 | 453 | `c/v` keys are set for copy/paste operations. 454 | 455 | ![Copy & Paste](https://user-images.githubusercontent.com/24392180/76686463-986b8980-662c-11ea-9762-9137b32c5cca.gif) 456 | 457 | Use `ctrl-c/ctrl-v` for copying and pasting while in input mode. 458 | 459 | ### Sorting/reversing the kernel modules 460 | 461 | `sort` subcommand can be used for sorting the kernel modules by their names, sizes or dependent modules. 462 | 463 | ``` 464 | kmon sort --name 465 | kmon sort --size 466 | kmon sort --dependent 467 | ``` 468 | 469 | ![Sorting the kernel modules](https://user-images.githubusercontent.com/24392180/78900376-70324780-7a7f-11ea-813e-78972fc3c880.gif) 470 | 471 | Also the `-r, --reverse` flag is used for reversing the kernel module list. 472 | 473 | ``` 474 | kmon --reverse 475 | ``` 476 | 477 | ![Reversing the kernel modules](https://user-images.githubusercontent.com/24392180/78901094-812f8880-7a80-11ea-85cf-2a0c6ac6354a.gif) 478 | 479 | ### Customizing the colors 480 | 481 | kmon uses the colors of the terminal as default but the highlighting color could be specified with `-c, --color` option. Alternatively, default text color can be set via `-a, --accent-color` option. 482 | 483 | #### Supported colors 484 | 485 | Supported terminal colors are `black, red, green, yellow, blue, magenta, cyan, gray, darkgray, lightred, lightgreen, lightyellow, lightblue, lightmagenta, lightcyan, white`. 486 | 487 | ``` 488 | kmon --color red 489 | ``` 490 | 491 | ![Supported Colors](https://user-images.githubusercontent.com/24392180/76773518-a697e200-67b3-11ea-838b-6816193b88c5.gif) 492 | 493 | #### Using a custom color 494 | 495 | Provide a hexadecimal value for the color to use. 496 | 497 | ``` 498 | kmon --color 19683a 499 | ``` 500 | 501 | ![Using a custom color](https://user-images.githubusercontent.com/24392180/76772858-a0edcc80-67b2-11ea-86ea-9b138a0b937b.gif) 502 | 503 | #### Changing the accent color 504 | 505 | Default text color might cause readability issues on some themes that have transparency. `-a, --accent-color` option can be used similarly to the `-c, --color` option for overcoming this issue. 506 | 507 | ``` 508 | kmon --color 6f849c --accent-color e35760 509 | ``` 510 | 511 | ![Changing the accent color](https://user-images.githubusercontent.com/24392180/89355576-61be0a80-d6c4-11ea-9693-f152edf5be38.gif) 512 | 513 | ### Unicode symbols 514 | 515 | Use `-u, --unicode` flag for showing Unicode symbols for the block titles. 516 | 517 | ``` 518 | kmon --unicode 519 | ``` 520 | 521 | ![Unicode symbols](https://user-images.githubusercontent.com/24392180/76711734-74d73a80-6723-11ea-8eae-180e69a5395c.gif) 522 | 523 | ### Setting the terminal tick rate 524 | 525 | `-t, --tickrate` option can be used for setting the refresh interval of the terminal UI in milliseconds. 526 | 527 | ![Setting the terminal tick rate](https://user-images.githubusercontent.com/24392180/76807925-1aa7a980-67f7-11ea-9af5-bb80849f5629.gif) 528 | 529 | ### Searching modules by regular expression 530 | 531 | `-E, --regex` option can be used for searching modules by regular expression. 532 | 533 | ## Roadmap 534 | 535 | kmon aims to be a standard tool for Linux kernel management while supporting most of the Linux distributions. 536 | 537 | ### Accessibility 538 | 539 | For achieving this goal, kmon should be accessible from different package managers such as [Snap](https://snapcraft.io/)[\*](https://forum.snapcraft.io/t/unable-to-load-modules-to-kernel-and-get-module-information/16151) and [RPM](https://rpm.org/). 540 | 541 | ### Dependencies 542 | 543 | It is required to have the essential tools like [dmesg](https://en.wikipedia.org/wiki/Dmesg) and [kmod](https://www.linux.org/docs/man8/kmod.html) on the system for kmon to work as expected. Thus the next step would be using just the system resources for these functions. 544 | 545 | ### Features 546 | 547 | Management actions about the Linux kernel should be applicable in kmon for minimizing the dependence on to command line and other tools. 548 | 549 | ### Testing 550 | 551 | kmon should be tested and reported on different architectures for further development and support. 552 | 553 | ## Resources 554 | 555 | ### About the project 556 | 557 | - [Code of conduct](https://github.com/orhun/kmon/blob/master/CODE_OF_CONDUCT.md) 558 | - [Contributing](https://github.com/orhun/kmon/blob/master/CONTRIBUTING.md) 559 | - [Creating a release](https://github.com/orhun/kmon/blob/master/RELEASE.md) 560 | 561 | ### Articles 562 | 563 | - [Exploring the Linux Kernel by Bob Cromwell](https://cromwell-intl.com/open-source/linux-kernel-details.html) 564 | - [Anatomy of the Linux loadable kernel module by Terenceli](https://terenceli.github.io/%E6%8A%80%E6%9C%AF/2018/06/02/linux-loadable-module) 565 | - [Managing kernel modules with kmod by Lucas De Marchi](https://elinux.org/images/8/89/Managing_Kernel_Modules_With_kmod.pdf) 566 | 567 | ### In the media 568 | 569 | - [Manage And Monitor Linux Kernel Modules With Kmon](https://ostechnix.com/manage-and-monitor-linux-kernel-modules-with-kmon/) ( 570 | OSTechNix) 571 | - [Kmon The Linux Kernel Management And Monitoring Software](https://www.youtube.com/watch?v=lukxf6CnR2o) (Brodie Robertson on YouTube) 572 | 573 | ### Gallery 574 | 575 | | Fedora 31 | Debian 10 | Manjaro 19 | 576 | | :---------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------: | 577 | | ![kmon on fedora](https://user-images.githubusercontent.com/24392180/76520554-27817180-6474-11ea-9966-e564f38c8a6a.png) | ![kmon on debian](https://user-images.githubusercontent.com/24392180/76514129-79bc9580-6468-11ea-9013-e32fbbdc1108.png) | ![kmon on manjaro](https://user-images.githubusercontent.com/24392180/76940351-1f5d8200-690b-11ea-8fe9-1d751fe102c5.png) | 578 | 579 | | Ubuntu 18.04 | openSUSE | Void Linux | 580 | | :---------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------: | 581 | | ![kmon on ubuntu](https://user-images.githubusercontent.com/24392180/76690341-18571b00-6650-11ea-85c9-3f511c054194.png) | ![kmon on opensuse](https://user-images.githubusercontent.com/24392180/77414512-38b27280-6dd2-11ea-888c-9bf6f7245387.png) | ![kmon on voidlinux](https://user-images.githubusercontent.com/24392180/77417004-c9d71880-6dd5-11ea-82b2-f6c7df9a05c3.png) | 582 | 583 | ### Social Media 584 | 585 | - Follow [@kmonitor\_](https://twitter.com/kmonitor_) on Twitter 586 | - Follow the [author](https://orhun.dev/): 587 | - [@orhun](https://github.com/orhun) on GitHub 588 | - [@orhundev](https://twitter.com/orhundev) on Twitter 589 | 590 | ## Funding 591 | 592 | ### GitHub 593 | 594 | Support the development of my projects by supporting me on [GitHub Sponsors](https://github.com/sponsors/orhun). 595 | 596 | ### Patreon 597 | 598 | [![Patreon Button](https://user-images.githubusercontent.com/24392180/77826872-e7c8b400-711a-11ea-8f51-502e3a4d46b9.png)](https://www.patreon.com/join/orhunp) 599 | 600 | ### Open Collective 601 | 602 | [![Open Collective backers](https://img.shields.io/opencollective/backers/kmon?color=000000&style=flat-square)](https://opencollective.com/kmon) [![Open Collective sponsors](https://img.shields.io/opencollective/sponsors/kmon?color=000000&style=flat-square)](https://opencollective.com/kmon) 603 | 604 | Support the open source development efforts by becoming a [backer](https://opencollective.com/kmon/contribute/backer-15060/checkout) or [sponsor](https://opencollective.com/kmon/contribute/sponsor-15061/checkout). 605 | 606 | [![Open Collective Button](https://user-images.githubusercontent.com/24392180/77827001-d0d69180-711b-11ea-817e-855ec4cf56f7.png)](https://opencollective.com/kmon/donate) 607 | 608 | ## License 609 | 610 | GNU General Public License ([3.0](https://www.gnu.org/licenses/gpl.txt)) 611 | 612 | ## Copyright 613 | 614 | Copyright © 2020-2024, [Orhun Parmaksız](mailto:orhunparmaksiz@gmail.com) 615 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Creating a Release 2 | 3 | [GitHub](https://github.com/orhun/kmon/releases), [crates.io](https://crates.io/crates/kmon/) and [Docker](https://hub.docker.com/r/orhunp/kmon) releases are automated via [GitHub actions](https://github.com/orhun/kmon/blob/master/.github/workflows/cd.yml) and triggered by pushing a tag. 4 | 5 | 1. Bump the version in [Cargo.toml](Cargo.toml) according to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 2. Update [Cargo.lock](Cargo.lock) by building the project: `cargo build` 7 | 3. Ensure [CHANGELOG.md](CHANGELOG.md) is updated according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. 8 | 4. Commit and push the changes. 9 | 5. Create a new tag: `git tag -s -a v[x.y.z]` ([signed](https://keyserver.ubuntu.com/pks/lookup?search=0x485B7C52E9EC0DC6&op=vindex)) 10 | 6. Push the tag: `git push --tags` 11 | 7. Wait for [Continuous Deployment](https://github.com/orhun/kmon/actions) workflow to finish. 12 | 13 | ## License 14 | 15 | GNU General Public License ([3.0](https://www.gnu.org/licenses/gpl.txt)) 16 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal 2 | show_downloads: true -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | #[path = "src/args.rs"] 2 | mod args; 3 | 4 | use clap::ValueEnum; 5 | use clap_complete::{self, Shell}; 6 | use clap_mangen::Man; 7 | use std::env; 8 | use std::error::Error; 9 | use std::fs::{self, File}; 10 | use std::io::Error as IoError; 11 | use std::path::{Path, PathBuf}; 12 | 13 | fn build_shell_completions(out_dir: &Path) -> Result<(), IoError> { 14 | fs::create_dir_all(out_dir)?; 15 | let mut app = args::get_args(); 16 | let shells = Shell::value_variants(); 17 | for shell in shells { 18 | clap_complete::generate_to( 19 | *shell, 20 | &mut app, 21 | env!("CARGO_PKG_NAME"), 22 | out_dir, 23 | )?; 24 | } 25 | Ok(()) 26 | } 27 | 28 | fn build_manpage(out_dir: &Path) -> Result<(), IoError> { 29 | fs::create_dir_all(out_dir)?; 30 | let app = args::get_args(); 31 | let file = out_dir.join(concat!(env!("CARGO_PKG_NAME"), ".8")); 32 | let mut file = File::create(file)?; 33 | Man::new(app).render(&mut file)?; 34 | Ok(()) 35 | } 36 | 37 | fn main() -> Result<(), Box> { 38 | println!("cargo:rerun-if-changed=src/args.rs"); 39 | let out_dir = match env::var_os("OUT_DIR").map(PathBuf::from) { 40 | None => return Ok(()), 41 | Some(v) => v 42 | .ancestors() 43 | .nth(4) 44 | .expect("failed to determine out dir") 45 | .to_owned(), 46 | }; 47 | build_manpage(&out_dir.join("man"))?; 48 | build_shell_completions(&out_dir.join("completions"))?; 49 | Ok(()) 50 | } 51 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | range: 65..85 3 | round: up 4 | precision: 2 5 | status: 6 | project: 7 | default: 8 | target: auto 9 | threshold: 5% 10 | branches: 11 | - master 12 | if_ci_failed: error 13 | patch: off 14 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | PWD=$(shell pwd) 2 | VER=$(shell uname -r) 3 | KERNEL_BUILD=/lib/modules/$(VER)/build 4 | obj-m += lkm_example.o 5 | 6 | all: 7 | $(MAKE) -C $(KERNEL_BUILD) M=$(PWD) modules 8 | install: 9 | $(MAKE) -C $(KERNEL_BUILD) M=$(PWD) modules_install 10 | clean: 11 | $(MAKE) -C $(KERNEL_BUILD) M=$(PWD) clean 12 | -------------------------------------------------------------------------------- /example/lkm_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | MODULE_LICENSE("GPL"); 6 | MODULE_AUTHOR("orhun"); 7 | MODULE_DESCRIPTION("An example Linux kernel module"); 8 | MODULE_VERSION("0.1"); 9 | 10 | static int __init lkm_example_init(void) { 11 | printk(KERN_INFO "[+] Example kernel module loaded.\n"); 12 | return 0; 13 | } 14 | 15 | static void __exit lkm_example_exit(void) { 16 | printk(KERN_INFO "[-] Example kernel module unloaded.\n"); 17 | } 18 | 19 | module_init(lkm_example_init); 20 | module_exit(lkm_example_exit); -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2018" 2 | max_width = 85 3 | newline_style = "Unix" 4 | hard_tabs = true 5 | tab_spaces = 4 6 | use_field_init_shorthand = true -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use crate::event::Event; 2 | use crate::kernel::cmd::ModuleCommand; 3 | use crate::kernel::lkm::KernelModules; 4 | use crate::kernel::log::KernelLogs; 5 | use crate::kernel::Kernel; 6 | use crate::style::{Style, StyledText, Symbol}; 7 | use crate::util; 8 | use crate::widgets::StatefulList; 9 | use copypasta_ext::display::DisplayServer as ClipboardDisplayServer; 10 | use copypasta_ext::ClipboardProviderExt; 11 | use enum_iterator::Sequence; 12 | use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; 13 | use ratatui::style::Style as TuiStyle; 14 | use ratatui::text::{Line, Span, Text}; 15 | use ratatui::widgets::{ 16 | Block as TuiBlock, Borders, Clear, List, ListItem, Paragraph, Row, Table, Wrap, 17 | }; 18 | use ratatui::Frame; 19 | use regex_lite::RegexBuilder; 20 | use std::fmt::{Debug, Display, Formatter}; 21 | use std::slice::Iter; 22 | use std::sync::mpsc::Sender; 23 | use termion::event::Key; 24 | use unicode_width::UnicodeWidthStr; 25 | 26 | /// Table header of the module table 27 | pub const TABLE_HEADER: &[&str] = &[" Module", "Size", "Used by"]; 28 | 29 | /// Available options in the module management menu 30 | const OPTIONS: &[(&str, &str)] = &[ 31 | ("unload", "Unload the module"), 32 | ("reload", "Reload the module"), 33 | ("blacklist", "Blacklist the module"), 34 | ("dependent", "Show the dependent modules"), 35 | ("copy", "Copy the module name"), 36 | ("load", "Load a kernel module"), 37 | ("clear", "Clear the ring buffer"), 38 | ]; 39 | 40 | /// Supported directions of scrolling 41 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] 42 | pub enum ScrollDirection { 43 | Up, 44 | Down, 45 | Left, 46 | Right, 47 | Top, 48 | Bottom, 49 | } 50 | 51 | impl ScrollDirection { 52 | /// Return iterator of the available scroll directions. 53 | #[allow(dead_code)] 54 | pub fn iter() -> Iter<'static, ScrollDirection> { 55 | [ 56 | ScrollDirection::Up, 57 | ScrollDirection::Down, 58 | ScrollDirection::Left, 59 | ScrollDirection::Right, 60 | ScrollDirection::Top, 61 | ScrollDirection::Bottom, 62 | ] 63 | .iter() 64 | } 65 | } 66 | 67 | /// Main blocks of the terminal 68 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)] 69 | pub enum Block { 70 | UserInput, 71 | ModuleTable, 72 | ModuleInfo, 73 | Activities, 74 | } 75 | 76 | /// Sizes of the terminal blocks 77 | pub struct BlockSize { 78 | pub input: u16, 79 | pub info: u16, 80 | pub activities: u16, 81 | } 82 | 83 | /// Default initialization values for BlockSize 84 | impl Default for BlockSize { 85 | fn default() -> Self { 86 | Self { 87 | input: 60, 88 | info: 40, 89 | activities: 25, 90 | } 91 | } 92 | } 93 | 94 | /// User input mode 95 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)] 96 | pub enum InputMode { 97 | None, 98 | Search, 99 | Load, 100 | } 101 | 102 | impl InputMode { 103 | /// Check if input mode is set. 104 | pub fn is_none(self) -> bool { 105 | self == Self::None 106 | } 107 | } 108 | 109 | /// Implementation of Display for using InputMode members as string 110 | impl Display for InputMode { 111 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 112 | let mut input_mode = *self; 113 | if input_mode.is_none() { 114 | input_mode = match InputMode::first().and_then(|v| v.next()) { 115 | Some(v) => v, 116 | None => input_mode, 117 | } 118 | } 119 | write!(f, "{input_mode:?}") 120 | } 121 | } 122 | 123 | /// Application settings and related methods 124 | pub struct App { 125 | pub selected_block: Block, 126 | pub default_block: Block, 127 | pub block_size: BlockSize, 128 | pub block_index: u8, 129 | pub input_mode: InputMode, 130 | pub input_query: String, 131 | pub options: StatefulList<(String, String)>, 132 | pub show_options: bool, 133 | style: Style, 134 | clipboard: Option>, 135 | } 136 | 137 | impl App { 138 | /// Create a new app instance. 139 | pub fn new(block: Block, style: Style) -> Self { 140 | Self { 141 | selected_block: block, 142 | default_block: block, 143 | block_size: BlockSize::default(), 144 | block_index: 0, 145 | input_mode: InputMode::None, 146 | input_query: String::new(), 147 | options: StatefulList::with_items( 148 | OPTIONS 149 | .iter() 150 | .map(|(option, text)| { 151 | (String::from(*option), String::from(*text)) 152 | }) 153 | .collect(), 154 | ), 155 | show_options: false, 156 | style, 157 | clipboard: match ClipboardDisplayServer::select().try_context() { 158 | None => { 159 | eprintln!("failed to initialize clipboard, no suitable clipboard provider found"); 160 | None 161 | } 162 | clipboard => clipboard, 163 | }, 164 | } 165 | } 166 | 167 | /// Reset app properties to default. 168 | pub fn refresh(&mut self) { 169 | self.selected_block = self.default_block; 170 | self.block_size = BlockSize::default(); 171 | self.block_index = 0; 172 | self.input_mode = InputMode::None; 173 | self.input_query = String::new(); 174 | self.options.state.select(Some(0)); 175 | self.show_options = false; 176 | } 177 | 178 | /// Get style depending on the selected state of the block. 179 | pub fn block_style(&self, block: Block) -> TuiStyle { 180 | if self.show_options { 181 | self.style.colored 182 | } else if block == self.selected_block { 183 | self.style.default 184 | } else { 185 | self.style.colored 186 | } 187 | } 188 | 189 | /// Get the size of the selected block. 190 | pub fn block_size(&mut self) -> &mut u16 { 191 | match self.selected_block { 192 | Block::ModuleInfo => &mut self.block_size.info, 193 | Block::Activities => &mut self.block_size.activities, 194 | _ => &mut self.block_size.input, 195 | } 196 | } 197 | 198 | /// Get clipboard contents as String. 199 | pub fn get_clipboard_contents(&mut self) -> String { 200 | if let Some(clipboard) = self.clipboard.as_mut() { 201 | if let Ok(contents) = clipboard.get_contents() { 202 | return contents; 203 | } 204 | } 205 | String::new() 206 | } 207 | 208 | /// Set clipboard contents. 209 | pub fn set_clipboard_contents(&mut self, contents: &str) { 210 | if let Some(clipboard) = self.clipboard.as_mut() { 211 | if let Err(e) = clipboard.set_contents(contents.to_string()) { 212 | eprintln!("{e}"); 213 | } 214 | } 215 | } 216 | 217 | /// Show help message on the information block. 218 | pub fn show_help_message(&mut self, kernel_modules: &mut KernelModules<'_>) { 219 | let key_bindings: Vec<(&str, &str)> = util::KEY_BINDINGS.to_vec(); 220 | let mut help_text = Vec::new(); 221 | let mut help_text_raw = Vec::new(); 222 | for (key, desc) in &key_bindings { 223 | help_text.push(Line::from(Span::styled( 224 | format!("{}:", &key), 225 | self.style.colored, 226 | ))); 227 | help_text_raw.push(format!("{key}:")); 228 | help_text.push(Line::from(Span::styled( 229 | format!("{}{}", self.style.unicode.get(Symbol::Blank), &desc), 230 | self.style.default, 231 | ))); 232 | help_text_raw.push(format!(" {}", &desc)); 233 | } 234 | kernel_modules.info_scroll_offset = 0; 235 | kernel_modules.command = ModuleCommand::None; 236 | kernel_modules.current_name = 237 | format!("!Help{}", self.style.unicode.get(Symbol::Helmet)); 238 | kernel_modules 239 | .current_info 240 | .set(Text::from(help_text), help_text_raw.join("\n")); 241 | } 242 | 243 | /// Show dependent modules on the information block. 244 | #[allow(clippy::nonminimal_bool)] 245 | pub fn show_dependent_modules( 246 | &mut self, 247 | kernel_modules: &mut KernelModules<'_>, 248 | ) { 249 | let current_line = kernel_modules.default_list.get(kernel_modules.index); 250 | 251 | if let Some(line) = current_line { 252 | // If there is no space in "used_modules", return a vector with "-" 253 | // Otherwise, split the modules by commas and collect them into a vector 254 | let dependent_modules_list = line[2] 255 | .rsplit_once(' ') 256 | .map_or(vec!["-"], |(_, modules)| modules.split(',').collect()); 257 | 258 | if !(dependent_modules_list[0] == "-" 259 | || kernel_modules.current_name.contains("Dependent modules")) 260 | || cfg!(test) 261 | { 262 | kernel_modules.info_scroll_offset = 0; 263 | kernel_modules.command = ModuleCommand::None; 264 | kernel_modules.current_name = format!( 265 | "!Dependent modules of {}{}", 266 | kernel_modules.current_name, 267 | self.style.unicode.get(Symbol::HistoricSite) 268 | ); 269 | let mut dependent_modules = Vec::new(); 270 | for module in &dependent_modules_list { 271 | dependent_modules.push(Line::from(vec![ 272 | Span::styled("-", self.style.colored), 273 | Span::styled(format!(" {module}"), self.style.default), 274 | ])); 275 | } 276 | kernel_modules.current_info.set( 277 | Text::from(dependent_modules), 278 | kernel_modules.current_name.clone(), 279 | ); 280 | } 281 | } 282 | } 283 | 284 | /// Draw a block according to the index. 285 | pub fn draw_dynamic_block( 286 | &mut self, 287 | frame: &mut Frame, 288 | area: Rect, 289 | kernel: &mut Kernel, 290 | ) { 291 | match self.block_index { 292 | 0 => self.draw_kernel_modules(frame, area, &mut kernel.modules), 293 | 1 => self.draw_module_info(frame, area, &mut kernel.modules), 294 | _ => self.draw_kernel_activities(frame, area, &mut kernel.logs), 295 | } 296 | if self.block_index < 2 { 297 | self.block_index += 1; 298 | } else { 299 | self.block_index = 0; 300 | } 301 | } 302 | 303 | /// Draw a paragraph widget for using as user input. 304 | pub fn draw_user_input( 305 | &self, 306 | frame: &mut Frame, 307 | area: Rect, 308 | tx: &Sender>, 309 | ) { 310 | frame.render_widget( 311 | Paragraph::new(Span::raw(self.input_query.to_string())) 312 | .block( 313 | TuiBlock::default() 314 | .border_style(match self.selected_block { 315 | Block::UserInput => { 316 | if self.input_mode.is_none() { 317 | tx.send(Event::Input(Key::Char('\n'))).unwrap(); 318 | } 319 | self.style.default 320 | } 321 | _ => self.style.colored, 322 | }) 323 | .borders(Borders::ALL) 324 | .title(Span::styled( 325 | format!( 326 | "{}{}", 327 | self.input_mode, 328 | match self.input_mode { 329 | InputMode::Load => 330 | self.style.unicode.get(Symbol::Anchor), 331 | _ => self.style.unicode.get(Symbol::Magnifier), 332 | } 333 | ), 334 | self.style.bold, 335 | )), 336 | ) 337 | .alignment(Alignment::Left), 338 | area, 339 | ); 340 | } 341 | 342 | /// Draw a paragraph widget for showing the kernel information. 343 | pub fn draw_kernel_info(&self, frame: &mut Frame, area: Rect, info: &[String]) { 344 | frame.render_widget( 345 | Paragraph::new(Span::raw(&info[1])) 346 | .block( 347 | TuiBlock::default() 348 | .border_style(self.style.colored) 349 | .borders(Borders::ALL) 350 | .title(Span::styled( 351 | format!( 352 | "{}{}", 353 | info[0], 354 | self.style.unicode.get(Symbol::Gear) 355 | ), 356 | self.style.bold, 357 | )) 358 | .title_alignment(Alignment::Center), 359 | ) 360 | .alignment(Alignment::Center) 361 | .wrap(Wrap { trim: true }), 362 | area, 363 | ); 364 | } 365 | 366 | /// Configure and draw kernel modules table. 367 | pub fn draw_kernel_modules( 368 | &mut self, 369 | frame: &mut Frame, 370 | area: Rect, 371 | kernel_modules: &mut KernelModules<'_>, 372 | ) { 373 | // Filter the module list depending on the input query. 374 | let mut kernel_module_list = kernel_modules.default_list.clone(); 375 | match self.input_mode { 376 | InputMode::None | InputMode::Search if !self.input_query.is_empty() => { 377 | if kernel_modules.args.regex() { 378 | if let Ok(regex) = RegexBuilder::new(&self.input_query) 379 | .case_insensitive(true) 380 | .build() 381 | { 382 | kernel_module_list 383 | .retain(|module| regex.is_match(module[0].trim_start())) 384 | } 385 | } else { 386 | let input_query = &self.input_query.to_lowercase(); 387 | kernel_module_list.retain(|module| { 388 | module[0].to_lowercase().contains(input_query) 389 | }); 390 | } 391 | } 392 | _ => {} 393 | } 394 | 395 | // Append '...' if dependent modules exceed the block width. 396 | let dependent_width = (area.width / 2).saturating_sub(7) as usize; 397 | for module in &mut kernel_module_list { 398 | if module[2].len() > dependent_width { 399 | module[2].truncate(dependent_width); 400 | module[2].push_str("..."); 401 | } 402 | } 403 | kernel_modules.list = kernel_module_list; 404 | // Set the scroll offset for modules. 405 | let modules_scroll_offset = area 406 | .height 407 | .checked_sub(5) 408 | .and_then(|height| kernel_modules.index.checked_sub(height as usize)) 409 | .unwrap_or(0); 410 | // Set selected state of the modules and render the table widget. 411 | frame.render_widget( 412 | Table::new( 413 | kernel_modules 414 | .list 415 | .iter() 416 | .skip(modules_scroll_offset) 417 | .enumerate() 418 | .map(|(i, item)| { 419 | let item = item.iter().map(|v| v.to_string()); 420 | if Some(i) 421 | == kernel_modules 422 | .index 423 | .checked_sub(modules_scroll_offset) 424 | { 425 | Row::new(item).style(self.style.default) 426 | } else { 427 | Row::new(item).style(self.style.colored) 428 | } 429 | }), 430 | &[ 431 | Constraint::Percentage(30), 432 | Constraint::Percentage(20), 433 | Constraint::Percentage(50), 434 | ], 435 | ) 436 | .header( 437 | Row::new(TABLE_HEADER.iter().map(|v| v.to_string())) 438 | .style(self.style.bold), 439 | ) 440 | .block( 441 | TuiBlock::default() 442 | .border_style(self.block_style(Block::ModuleTable)) 443 | .borders(Borders::ALL) 444 | .title(Span::styled( 445 | format!( 446 | "Loaded Kernel Modules {}{}/{}{} {}{}%{}", 447 | self.style.unicode.get(Symbol::LeftBracket), 448 | match kernel_modules.list.len() { 449 | 0 => kernel_modules.index, 450 | _ => kernel_modules.index + 1, 451 | }, 452 | kernel_modules.list.len(), 453 | self.style.unicode.get(Symbol::RightBracket), 454 | self.style.unicode.get(Symbol::LeftBracket), 455 | if !kernel_modules.list.is_empty() { 456 | ((kernel_modules.index + 1) as f64 457 | / kernel_modules.list.len() as f64 458 | * 100.0) as u64 459 | } else { 460 | 0 461 | }, 462 | self.style.unicode.get(Symbol::RightBracket), 463 | ), 464 | self.style.bold, 465 | )), 466 | ), 467 | area, 468 | ); 469 | if self.show_options { 470 | self.draw_options_menu(frame, area, kernel_modules); 471 | } 472 | } 473 | 474 | /// Draws the options menu as a popup. 475 | pub fn draw_options_menu( 476 | &mut self, 477 | frame: &mut Frame, 478 | area: Rect, 479 | kernel_modules: &mut KernelModules<'_>, 480 | ) { 481 | let block_title = format!( 482 | "Options ({})", 483 | kernel_modules.list[kernel_modules.index][0] 484 | .split_whitespace() 485 | .next() 486 | .unwrap_or("?") 487 | .trim() 488 | ); 489 | let items = self 490 | .options 491 | .items 492 | .iter() 493 | .map(|(_, text)| ListItem::new(Span::raw(format!(" {text}")))) 494 | .collect::>>(); 495 | let (mut percent_y, mut percent_x) = (40, 60); 496 | let text_height = items.iter().map(|v| v.height() as f32).sum::() + 3.; 497 | if area.height.checked_sub(5).unwrap_or(area.height) as f32 > text_height { 498 | percent_y = ((text_height / area.height as f32) * 100.) as u16; 499 | } 500 | if let Some(text_width) = self 501 | .options 502 | .items 503 | .iter() 504 | .map(|(_, text)| text.width()) 505 | .chain(vec![block_title.width()]) 506 | .max() 507 | .map(|v| v as f32 + 7.) 508 | { 509 | if area.width.checked_sub(2).unwrap_or(area.width) as f32 > text_width { 510 | percent_x = ((text_width / area.width as f32) * 100.) as u16; 511 | } 512 | } 513 | let popup_layout = Layout::default() 514 | .direction(Direction::Vertical) 515 | .constraints( 516 | [ 517 | Constraint::Percentage((100 - percent_y) / 2), 518 | Constraint::Percentage(percent_y), 519 | Constraint::Percentage((100 - percent_y) / 2), 520 | ] 521 | .as_ref(), 522 | ) 523 | .split(area); 524 | let popup_rect = Layout::default() 525 | .direction(Direction::Horizontal) 526 | .constraints( 527 | [ 528 | Constraint::Percentage((100 - percent_x) / 2), 529 | Constraint::Percentage(percent_x), 530 | Constraint::Percentage((100 - percent_x) / 2), 531 | ] 532 | .as_ref(), 533 | ) 534 | .split(popup_layout[1])[1]; 535 | frame.render_widget(Clear, popup_rect); 536 | frame.render_stateful_widget( 537 | List::new(items) 538 | .block( 539 | TuiBlock::default() 540 | .title(Span::styled(block_title, self.style.bold)) 541 | .title_alignment(Alignment::Center) 542 | .style(self.style.default) 543 | .borders(Borders::ALL), 544 | ) 545 | .style(self.style.colored) 546 | .highlight_style(self.style.default), 547 | popup_rect, 548 | &mut self.options.state, 549 | ); 550 | } 551 | 552 | /// Draw a paragraph widget for showing module information. 553 | pub fn draw_module_info( 554 | &self, 555 | frame: &mut Frame, 556 | area: Rect, 557 | kernel_modules: &mut KernelModules<'_>, 558 | ) { 559 | frame.render_widget( 560 | Paragraph::new(kernel_modules.current_info.get()) 561 | .block( 562 | TuiBlock::default() 563 | .border_style(self.block_style(Block::ModuleInfo)) 564 | .borders(Borders::ALL) 565 | .title(Span::styled( 566 | format!( 567 | "{}{}", 568 | kernel_modules.get_current_command().title, 569 | self.style.unicode.get( 570 | kernel_modules.get_current_command().symbol 571 | ) 572 | ), 573 | self.style.bold, 574 | )), 575 | ) 576 | .alignment( 577 | if kernel_modules.command.is_none() 578 | && !kernel_modules 579 | .current_info 580 | .raw_text 581 | .contains("Execution Error\n") 582 | { 583 | Alignment::Left 584 | } else { 585 | Alignment::Center 586 | }, 587 | ) 588 | .wrap(Wrap { trim: true }) 589 | .scroll((kernel_modules.info_scroll_offset as u16, 0)), 590 | area, 591 | ); 592 | } 593 | 594 | /// Draw a paragraph widget for showing kernel activities. 595 | pub fn draw_kernel_activities( 596 | &self, 597 | frame: &mut Frame, 598 | area: Rect, 599 | kernel_logs: &mut KernelLogs, 600 | ) { 601 | frame.render_widget( 602 | Paragraph::new(StyledText::default().stylize_data( 603 | kernel_logs.select(area.height, 2), 604 | "] ", 605 | self.style.clone(), 606 | )) 607 | .block( 608 | TuiBlock::default() 609 | .border_style(self.block_style(Block::Activities)) 610 | .borders(Borders::ALL) 611 | .title(Span::styled( 612 | format!( 613 | "Kernel Activities{}", 614 | self.style.unicode.get(Symbol::HighVoltage) 615 | ), 616 | self.style.bold, 617 | )), 618 | ) 619 | .alignment(Alignment::Left), 620 | area, 621 | ); 622 | } 623 | } 624 | 625 | #[cfg(test)] 626 | mod tests { 627 | use super::*; 628 | use crate::event::Events; 629 | use crate::kernel::info; 630 | use crate::kernel::lkm::ListArgs; 631 | use clap::ArgMatches; 632 | use ratatui::backend::TestBackend; 633 | use ratatui::Terminal; 634 | #[test] 635 | fn test_app() { 636 | let args = ArgMatches::default(); 637 | let mut kernel_modules = 638 | KernelModules::new(ListArgs::new(&args), Style::new(&args)); 639 | let mut app = App::new(Block::ModuleTable, kernel_modules.style.clone()); 640 | app.set_clipboard_contents("test"); 641 | assert_ne!("x", app.get_clipboard_contents()); 642 | assert_eq!(app.style.default, app.block_style(Block::ModuleTable)); 643 | assert_eq!(app.style.colored, app.block_style(Block::Activities)); 644 | let mut kernel_logs = KernelLogs::default(); 645 | let backend = TestBackend::new(20, 10); 646 | let mut terminal = Terminal::new(backend).unwrap(); 647 | terminal 648 | .draw(|f| { 649 | let size = f.size(); 650 | app.selected_block = Block::UserInput; 651 | app.draw_user_input(f, size, &Events::new(100, &kernel_logs).tx); 652 | app.draw_kernel_info(f, size, &info::KernelInfo::new().current_info); 653 | app.input_query = String::from("a"); 654 | app.draw_kernel_modules(f, size, &mut kernel_modules); 655 | app.draw_module_info(f, size, &mut kernel_modules); 656 | app.draw_kernel_activities(f, size, &mut kernel_logs); 657 | }) 658 | .unwrap(); 659 | } 660 | #[test] 661 | fn test_input_mode() { 662 | let mut input_mode = InputMode::Load; 663 | assert!(!input_mode.is_none()); 664 | assert!(input_mode.to_string().contains("Load")); 665 | input_mode = InputMode::None; 666 | assert!(input_mode.to_string().contains("Search")); 667 | } 668 | } 669 | -------------------------------------------------------------------------------- /src/args.rs: -------------------------------------------------------------------------------- 1 | use clap::{Arg, ArgAction, Command as App}; 2 | 3 | /// ASCII format of the project logo 4 | const ASCII_LOGO: &str = " 5 | `` ```````````` ```` ``````````` ``````````` 6 | :NNs `hNNNNNNNNNNNNh` sNNNy yNNNNNNNNNN+ dNNNNNNNNNN: 7 | /MMMydMMyyyyyyydMMMMdhMMMMy yMMMyyyhMMMo dMMMyyydMMM/ 8 | /MMMMMMM` oMMMMMMMMMMy yMMM` -MMMo dMMN /MMM/ 9 | /MMMs:::hhhs oMMM+:::MMMNhhhNMMMdhhdMMMmhhhNMMN /MMM/ 10 | :mmm/ dmmh +mmm- `mmmmmmmmmmmmmmmmmmmmmmmmmd /mmm: 11 | ``` ``` ``` `````````````````````````` ```"; 12 | 13 | /// Parse command line arguments using clap. 14 | pub fn get_args() -> App { 15 | App::new(env!("CARGO_PKG_NAME")) 16 | .version(env!("CARGO_PKG_VERSION")) 17 | .author(env!("CARGO_PKG_AUTHORS")) 18 | .about(concat!( 19 | env!("CARGO_PKG_NAME"), 20 | " ", 21 | env!("CARGO_PKG_VERSION"), 22 | "\n", 23 | env!("CARGO_PKG_AUTHORS"), 24 | "\n", 25 | env!("CARGO_PKG_DESCRIPTION"), 26 | "\n\n", 27 | "Press '?' while running the terminal UI to see key bindings." 28 | )) 29 | .before_help(ASCII_LOGO) 30 | .arg( 31 | Arg::new("accent-color") 32 | .short('a') 33 | .long("accent-color") 34 | .value_name("COLOR") 35 | .default_value("white") 36 | .help("Set the accent color using hex or color name") 37 | .num_args(1), 38 | ) 39 | .arg( 40 | Arg::new("color") 41 | .short('c') 42 | .long("color") 43 | .value_name("COLOR") 44 | .default_value("darkgray") 45 | .help("Set the main color using hex or color name") 46 | .num_args(1), 47 | ) 48 | .arg( 49 | Arg::new("rate") 50 | .short('t') 51 | .long("tickrate") 52 | .value_name("MS") 53 | .default_value("250") 54 | .help("Set the refresh rate of the terminal") 55 | .num_args(1), 56 | ) 57 | .arg( 58 | Arg::new("reverse") 59 | .short('r') 60 | .long("reverse") 61 | .help("Reverse the kernel module list") 62 | .action(ArgAction::SetTrue), 63 | ) 64 | .arg( 65 | Arg::new("unicode") 66 | .short('u') 67 | .long("unicode") 68 | .help("Show Unicode symbols for the block titles") 69 | .action(ArgAction::SetTrue), 70 | ) 71 | .arg( 72 | Arg::new("regex") 73 | .short('E') 74 | .long("regex") 75 | .help("Interpret the module search query as a regular expression") 76 | .action(ArgAction::SetTrue), 77 | ) 78 | .subcommand( 79 | App::new("sort") 80 | .about("Sort kernel modules") 81 | .arg( 82 | Arg::new("size") 83 | .short('s') 84 | .long("size") 85 | .help("Sort modules by their sizes") 86 | .action(ArgAction::SetTrue), 87 | ) 88 | .arg( 89 | Arg::new("name") 90 | .short('n') 91 | .long("name") 92 | .help("Sort modules by their names") 93 | .action(ArgAction::SetTrue), 94 | ) 95 | .arg( 96 | Arg::new("dependent") 97 | .short('d') 98 | .long("dependent") 99 | .help("Sort modules by their dependent modules") 100 | .action(ArgAction::SetTrue), 101 | ), 102 | ) 103 | } 104 | 105 | #[cfg(test)] 106 | mod tests { 107 | use super::*; 108 | #[test] 109 | fn test_args() { 110 | get_args().debug_assert(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/event.rs: -------------------------------------------------------------------------------- 1 | use crate::kernel::log::KernelLogs; 2 | use std::io; 3 | use std::sync::mpsc; 4 | use std::thread; 5 | use std::time::Duration; 6 | use termion::event::Key; 7 | use termion::input::TermRead; 8 | 9 | /// Terminal event methods 10 | pub enum Event { 11 | Input(I), 12 | Kernel(String), 13 | Tick, 14 | } 15 | 16 | /// Terminal events 17 | #[allow(dead_code)] 18 | pub struct Events { 19 | pub tx: mpsc::Sender>, 20 | pub rx: mpsc::Receiver>, 21 | input_handler: thread::JoinHandle<()>, 22 | kernel_handler: thread::JoinHandle<()>, 23 | tick_handler: thread::JoinHandle<()>, 24 | } 25 | 26 | impl Events { 27 | /// Create a new events instance. 28 | pub fn new(refresh_rate: u64, kernel_logs: &KernelLogs) -> Self { 29 | // Convert refresh rate to Duration from milliseconds. 30 | let refresh_rate = Duration::from_millis(refresh_rate); 31 | // Create a new asynchronous channel. 32 | let (tx, rx) = mpsc::channel(); 33 | // Handle inputs using stdin stream and sender of the channel. 34 | let input_handler = { 35 | let tx = tx.clone(); 36 | thread::spawn(move || { 37 | let stdin = io::stdin(); 38 | for key in stdin.keys().flatten() { 39 | tx.send(Event::Input(key)).unwrap(); 40 | } 41 | }) 42 | }; 43 | // Handle kernel logs using 'dmesg' output. 44 | let kernel_handler = { 45 | let tx = tx.clone(); 46 | let mut kernel_logs = kernel_logs.clone(); 47 | thread::spawn(move || loop { 48 | if kernel_logs.update() { 49 | tx.send(Event::Kernel(kernel_logs.output.to_string())) 50 | .unwrap_or_default(); 51 | } 52 | thread::sleep(refresh_rate * 10); 53 | }) 54 | }; 55 | // Create a loop for handling events. 56 | let tick_handler = { 57 | let tx = tx.clone(); 58 | thread::spawn(move || loop { 59 | tx.send(Event::Tick).unwrap_or_default(); 60 | thread::sleep(refresh_rate); 61 | }) 62 | }; 63 | // Return events. 64 | Self { 65 | tx, 66 | rx, 67 | input_handler, 68 | kernel_handler, 69 | tick_handler, 70 | } 71 | } 72 | } 73 | 74 | #[cfg(test)] 75 | mod tests { 76 | use super::*; 77 | use std::error::Error; 78 | #[test] 79 | fn test_events() -> Result<(), Box> { 80 | let kernel_logs = KernelLogs::default(); 81 | let events = Events::new(100, &kernel_logs); 82 | let mut i = 0; 83 | loop { 84 | let tx = events.tx.clone(); 85 | thread::spawn(move || { 86 | let _ = tx.send(Event::Input(Key::Char( 87 | std::char::from_digit(i, 10).unwrap_or('x'), 88 | ))); 89 | }); 90 | i += 1; 91 | match events.rx.recv()? { 92 | Event::Input(v) => { 93 | if v == Key::Char('9') { 94 | break; 95 | } 96 | } 97 | Event::Tick => thread::sleep(Duration::from_millis(100)), 98 | Event::Kernel(log) => assert!(!log.is_empty()), 99 | } 100 | } 101 | Ok(()) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/kernel/cmd.rs: -------------------------------------------------------------------------------- 1 | use crate::style::Symbol; 2 | use std::{ffi::OsStr, path::Path}; 3 | 4 | /// Kernel module related command 5 | #[derive(Debug)] 6 | pub struct Command { 7 | pub cmd: String, 8 | pub desc: &'static str, 9 | pub title: String, 10 | pub symbol: Symbol, 11 | } 12 | 13 | impl Command { 14 | /// Create a new command instance. 15 | fn new(cmd: String, desc: &'static str, title: &str, symbol: Symbol) -> Self { 16 | // Parse the command title if '!' is given. 17 | Self { 18 | cmd, 19 | desc, 20 | title: title 21 | .rsplit_once('!') 22 | .map_or(title, |(_, title)| title) 23 | .to_string(), 24 | symbol, 25 | } 26 | } 27 | } 28 | 29 | /// Kernel module management commands 30 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] 31 | pub enum ModuleCommand { 32 | None, 33 | Load, 34 | Unload, 35 | Reload, 36 | Blacklist, 37 | Clear, 38 | } 39 | 40 | impl TryFrom for ModuleCommand { 41 | type Error = (); 42 | fn try_from(s: String) -> Result { 43 | match s.as_ref() { 44 | "load" => Ok(Self::Load), 45 | "unload" => Ok(Self::Unload), 46 | "reload" => Ok(Self::Reload), 47 | "blacklist" => Ok(Self::Blacklist), 48 | "clear" => Ok(Self::Clear), 49 | _ => Err(()), 50 | } 51 | } 52 | } 53 | 54 | impl ModuleCommand { 55 | /// Get Command struct from a enum element. 56 | pub fn get(self, module_name: &str) -> Command { 57 | match self { 58 | Self::None => Command::new(String::from(""), "", &format!("Module: {module_name}"), Symbol::None), 59 | Self::Load => Command::new( 60 | if Self::is_module_filename(Path::new(module_name)) { 61 | format!("insmod {}", &module_name) 62 | } else { 63 | format!("modprobe {0} || insmod {0}.ko", &module_name) 64 | }, 65 | "Add and remove modules from the Linux Kernel\n 66 | This command inserts a module to the kernel.", 67 | &format!("Load: {module_name}"), Symbol::Anchor), 68 | Self::Unload => Command::new( 69 | format!("modprobe -r {0} || rmmod {0}", &module_name), 70 | "modprobe/rmmod: Add and remove modules from the Linux Kernel 71 | modprobe -r, --remove or rmmod\n 72 | This option causes modprobe to remove rather than insert a module. \ 73 | If the modules it depends on are also unused, modprobe will try to \ 74 | remove them too. \ 75 | For modules loaded with insmod rmmod will be used instead. \ 76 | There is usually no reason to remove modules, but some buggy \ 77 | modules require it. Your distribution kernel may not have been \ 78 | built to support removal of modules at all.", 79 | &format!("Remove: {module_name}"), Symbol::CircleX), 80 | Self::Reload => Command::new( 81 | format!("{} && {}", 82 | ModuleCommand::Unload.get(module_name).cmd, 83 | ModuleCommand::Load.get(module_name).cmd), 84 | "modprobe/insmod/rmmod: Add and remove modules from the Linux Kernel\n 85 | This command reloads a module, removes and inserts to the kernel.", 86 | &format!("Reload: {module_name}"), Symbol::FuelPump), 87 | Self::Blacklist => Command::new( 88 | format!("if ! grep -q {module} /etc/modprobe.d/blacklist.conf; then 89 | echo 'blacklist {module}' >> /etc/modprobe.d/blacklist.conf 90 | echo 'install {module} /bin/false' >> /etc/modprobe.d/blacklist.conf 91 | fi", module = &module_name), 92 | "This command blacklists a module and any other module that depends on it.\n 93 | Blacklisting is a mechanism to prevent the kernel module from loading. \ 94 | This could be useful if, for example, the associated hardware is not needed, \ 95 | or if loading that module causes problems. 96 | The blacklist command will blacklist a module so that it will not be loaded \ 97 | automatically, but the module may be loaded if another non-blacklisted module \ 98 | depends on it or if it is loaded manually. However, there is a workaround for \ 99 | this behaviour; the install command instructs modprobe to run a custom command \ 100 | instead of inserting the module in the kernel as normal, so the module will \ 101 | always fail to load.", 102 | &format!("Blacklist: {module_name}"), Symbol::SquareX), 103 | Self::Clear => Command::new( 104 | String::from("dmesg --clear"), 105 | "dmesg: Print or control the kernel ring buffer 106 | option: -C, --clear\n 107 | Clear the ring buffer.", 108 | "Clear", Symbol::Cloud), 109 | } 110 | } 111 | 112 | /// Check if module command is set. 113 | pub fn is_none(self) -> bool { 114 | self == Self::None 115 | } 116 | 117 | /// Check if module name is a filename with suffix 'ko' 118 | pub fn is_module_filename(module_name: &Path) -> bool { 119 | module_name.extension() == Some(OsStr::new("ko")) 120 | } 121 | } 122 | 123 | #[cfg(test)] 124 | mod tests { 125 | use super::*; 126 | #[test] 127 | fn test_module_command() { 128 | let module_command = ModuleCommand::None; 129 | assert!(module_command == ModuleCommand::None); 130 | 131 | assert_ne!("", ModuleCommand::None.get("test").title); 132 | assert_ne!("", ModuleCommand::Load.get("module").desc); 133 | assert_ne!("", ModuleCommand::Unload.get("!command").cmd); 134 | assert_ne!("", ModuleCommand::Blacklist.get("~").cmd); 135 | 136 | assert_eq!( 137 | "modprobe test-module || insmod test-module.ko", 138 | ModuleCommand::Load.get("test-module").cmd 139 | ); 140 | assert_eq!( 141 | "insmod test-module.ko", 142 | ModuleCommand::Load.get("test-module.ko").cmd 143 | ); 144 | 145 | assert_eq!( 146 | "modprobe -r test-module || rmmod test-module", 147 | ModuleCommand::Unload.get("test-module").cmd 148 | ); 149 | assert_eq!( 150 | "modprobe -r test-module.ko || rmmod test-module.ko", 151 | ModuleCommand::Unload.get("test-module.ko").cmd 152 | ); 153 | 154 | assert_eq!( 155 | format!( 156 | "{} && {}", 157 | ModuleCommand::Unload.get("test-module").cmd, 158 | ModuleCommand::Load.get("test-module").cmd 159 | ), 160 | ModuleCommand::Reload.get("test-module").cmd, 161 | ); 162 | 163 | assert_eq!( 164 | format!( 165 | "{} && {}", 166 | ModuleCommand::Unload.get("test-module.ko").cmd, 167 | ModuleCommand::Load.get("test-module.ko").cmd 168 | ), 169 | ModuleCommand::Reload.get("test-module.ko").cmd, 170 | ); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/kernel/info.rs: -------------------------------------------------------------------------------- 1 | use crate::util; 2 | use std::vec::IntoIter; 3 | 4 | /// Kernel and system information 5 | pub struct KernelInfo { 6 | pub current_info: Vec, 7 | uname_output: IntoIter>, 8 | } 9 | 10 | impl Default for KernelInfo { 11 | fn default() -> Self { 12 | Self::new() 13 | } 14 | } 15 | 16 | impl KernelInfo { 17 | /// Create a new kernel info instance. 18 | pub fn new() -> Self { 19 | let mut kernel_info = Self { 20 | current_info: Vec::new(), 21 | uname_output: Vec::new().into_iter(), 22 | }; 23 | kernel_info.refresh(); 24 | kernel_info 25 | } 26 | 27 | /// Refresh the kernel information fields. 28 | pub fn refresh(&mut self) { 29 | self.uname_output = KernelInfo::get_infos(); 30 | self.next(); 31 | } 32 | 33 | /// Select the next 'uname' output as kernel information. 34 | pub fn next(&mut self) { 35 | match self.uname_output.next() { 36 | Some(v) => self.current_info = v, 37 | None => self.refresh(), 38 | } 39 | } 40 | 41 | /// Execute 'uname' command and return its output along with its description. 42 | fn get_infos() -> IntoIter> { 43 | vec![ 44 | vec![ 45 | String::from("Kernel Release"), 46 | util::exec_cmd("uname", &["-srn"]) 47 | .unwrap_or_else(|_| String::from("?")), 48 | ], 49 | vec![ 50 | String::from("Kernel Version"), 51 | util::exec_cmd("uname", &["-v"]) 52 | .unwrap_or_else(|_| String::from("?")), 53 | ], 54 | vec![ 55 | String::from("Kernel Platform"), 56 | util::exec_cmd("uname", &["-om"]) 57 | .unwrap_or_else(|_| String::from("?")), 58 | ], 59 | ] 60 | .into_iter() 61 | } 62 | } 63 | 64 | #[cfg(test)] 65 | mod tests { 66 | use super::*; 67 | #[test] 68 | fn test_info() { 69 | let mut kernel_info = KernelInfo::default(); 70 | for _x in 0..kernel_info.uname_output.len() + 1 { 71 | kernel_info.next(); 72 | } 73 | assert_eq!("Kernel Release", kernel_info.current_info[0]); 74 | assert_eq!( 75 | util::exec_cmd("uname", &["-srn"]).unwrap(), 76 | kernel_info.current_info[1] 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/kernel/lkm.rs: -------------------------------------------------------------------------------- 1 | use crate::app::ScrollDirection; 2 | use crate::kernel::cmd::{Command, ModuleCommand}; 3 | use crate::style::{Style, StyledText, Symbol}; 4 | use crate::util; 5 | use bytesize::ByteSize; 6 | use clap::ArgMatches; 7 | use ratatui::text::{Line, Span, Text}; 8 | use std::error::Error; 9 | use std::slice::Iter; 10 | 11 | /// Type of the sorting of module list 12 | #[derive(Clone, Copy, Debug)] 13 | enum SortType { 14 | None, 15 | Size, 16 | Name, 17 | Dependent, 18 | } 19 | 20 | impl SortType { 21 | /// Return iterator for the sort types. 22 | #[allow(dead_code)] 23 | pub fn iter() -> Iter<'static, SortType> { 24 | [ 25 | SortType::None, 26 | SortType::Size, 27 | SortType::Name, 28 | SortType::Dependent, 29 | ] 30 | .iter() 31 | } 32 | } 33 | 34 | /// Listing properties of module list 35 | pub struct ListArgs { 36 | sort: SortType, 37 | reverse: bool, 38 | regex: bool, 39 | } 40 | 41 | impl ListArgs { 42 | /// Create a new list arguments instance. 43 | pub fn new(args: &ArgMatches) -> Self { 44 | let mut sort_type = SortType::None; 45 | if let Some(("sort", matches)) = args.subcommand() { 46 | if matches.get_flag("size") { 47 | sort_type = SortType::Size; 48 | } else if matches.get_flag("dependent") { 49 | sort_type = SortType::Dependent; 50 | } else { 51 | sort_type = SortType::Name; 52 | } 53 | } 54 | Self { 55 | sort: sort_type, 56 | reverse: args.try_get_one::("reverse").ok().flatten() 57 | == Some(&true), 58 | regex: args.try_get_one::("regex").ok().flatten() == Some(&true), 59 | } 60 | } 61 | 62 | pub fn regex(&self) -> bool { 63 | self.regex 64 | } 65 | } 66 | 67 | /// Loadable kernel modules 68 | pub struct KernelModules<'a> { 69 | pub default_list: Vec>, 70 | pub list: Vec>, 71 | pub current_name: String, 72 | pub current_info: StyledText<'a>, 73 | pub command: ModuleCommand, 74 | pub index: usize, 75 | pub info_scroll_offset: usize, 76 | pub style: Style, 77 | pub args: ListArgs, 78 | } 79 | 80 | impl KernelModules<'_> { 81 | /// Create a new kernel modules instance. 82 | pub fn new(args: ListArgs, style: Style) -> Self { 83 | let mut kernel_modules = Self { 84 | default_list: Vec::new(), 85 | list: Vec::new(), 86 | current_name: String::new(), 87 | current_info: StyledText::default(), 88 | command: ModuleCommand::None, 89 | index: 0, 90 | info_scroll_offset: 0, 91 | args, 92 | style, 93 | }; 94 | if let Err(e) = kernel_modules.refresh() { 95 | eprintln!("{e}"); 96 | } 97 | kernel_modules 98 | } 99 | 100 | /// Parse kernel modules from '/proc/modules'. 101 | pub fn refresh(&mut self) -> Result<(), Box> { 102 | let mut module_list: Vec> = Vec::new(); 103 | // Set the command for reading kernel modules and execute it. 104 | let mut module_read_cmd = String::from("cat /proc/modules"); 105 | match self.args.sort { 106 | SortType::Size => module_read_cmd += " | sort -n -r -t ' ' -k2", 107 | SortType::Name => module_read_cmd += " | sort -t ' ' -k1", 108 | SortType::Dependent => module_read_cmd += " | sort -n -r -t ' ' -k3", 109 | _ => {} 110 | } 111 | let modules_content = util::exec_cmd("sh", &["-c", &module_read_cmd])?; 112 | 113 | // Parse content for module name, size and related information. 114 | for line in modules_content.lines() { 115 | let columns: Vec<&str> = line.split_whitespace().collect(); 116 | let mut module_name = format!(" {}", columns[0]); 117 | if columns.len() >= 7 { 118 | module_name.push(' '); 119 | module_name.push_str(columns[6]); 120 | } 121 | let mut used_modules = format!("{} {}", columns[2], columns[3]); 122 | if used_modules.ends_with(',') { 123 | used_modules.pop(); 124 | } 125 | let module_size = 126 | ByteSize::b(columns[1].parse().unwrap_or(0)).to_string(); 127 | module_list.push(vec![module_name, module_size, used_modules]); 128 | } 129 | // Reverse the kernel modules if the argument is provided. 130 | if self.args.reverse { 131 | module_list.reverse(); 132 | } 133 | self.default_list.clone_from(&module_list); 134 | self.list = module_list; 135 | self.scroll_list(ScrollDirection::Top); 136 | Ok(()) 137 | } 138 | 139 | /// Get the current command using current module name. 140 | pub fn get_current_command(&self) -> Command { 141 | self.command.get(&self.current_name) 142 | } 143 | 144 | /// Set the current module command and show confirmation message. 145 | pub fn set_current_command( 146 | &mut self, 147 | module_command: ModuleCommand, 148 | command_name: String, 149 | ) { 150 | if !command_name.contains(' ') && !self.current_name.starts_with('!') { 151 | if !command_name.is_empty() { 152 | self.current_name = command_name; 153 | } 154 | self.command = module_command; 155 | self.current_info.set( 156 | Text::from({ 157 | let mut spans = vec![ 158 | Line::from(Span::styled( 159 | "Execute the following command? [y/N]:", 160 | self.style.colored, 161 | )), 162 | Line::from(Span::styled( 163 | self.get_current_command().cmd, 164 | self.style.default, 165 | )), 166 | Line::default(), 167 | ]; 168 | spans.append( 169 | &mut Text::styled( 170 | self.get_current_command().desc, 171 | self.style.colored, 172 | ) 173 | .lines, 174 | ); 175 | spans 176 | }), 177 | self.get_current_command().cmd, 178 | ); 179 | self.info_scroll_offset = 0; 180 | } 181 | } 182 | 183 | /// Execute the current module command. 184 | pub fn execute_command(&mut self) -> bool { 185 | let mut command_executed = false; 186 | if !self.command.is_none() { 187 | match util::exec_cmd("sh", &["-c", &self.get_current_command().cmd]) { 188 | Ok(_) => command_executed = true, 189 | Err(e) => { 190 | self.current_info.set( 191 | Text::from({ 192 | let mut spans = vec![ 193 | Line::from(Span::styled( 194 | "Failed to execute command:", 195 | self.style.colored, 196 | )), 197 | Line::from(Span::styled( 198 | format!("'{}'", self.get_current_command().cmd), 199 | self.style.default, 200 | )), 201 | Line::default(), 202 | ]; 203 | spans.append( 204 | &mut Text::styled(e.to_string(), self.style.default) 205 | .lines, 206 | ); 207 | spans 208 | }), 209 | format!( 210 | "Execution Error\n'{}'\n{}", 211 | self.get_current_command().cmd, 212 | e 213 | ), 214 | ); 215 | self.current_name = 216 | format!("!Error{}", self.style.unicode.get(Symbol::NoEntry)); 217 | } 218 | } 219 | self.command = ModuleCommand::None; 220 | } 221 | command_executed 222 | } 223 | 224 | /// Cancel the execution of the current command. 225 | pub fn cancel_execution(&mut self) -> bool { 226 | if !self.command.is_none() { 227 | self.command = ModuleCommand::None; 228 | if self.index != 0 { 229 | self.index -= 1; 230 | self.scroll_list(ScrollDirection::Down); 231 | } else { 232 | self.index += 1; 233 | self.scroll_list(ScrollDirection::Up); 234 | }; 235 | true 236 | } else { 237 | false 238 | } 239 | } 240 | 241 | /// Scroll to the position of used module at given index. 242 | pub fn show_used_module(&mut self, mod_index: usize) { 243 | if let Some(used_module) = self.list[self.index][2] 244 | .split(' ') 245 | .collect::>() 246 | .get(1) 247 | .unwrap_or(&"") 248 | .split(',') 249 | .collect::>() 250 | .get(mod_index) 251 | { 252 | if let Some(v) = self 253 | .list 254 | .iter() 255 | .position(|module| module[0] == format!(" {used_module}")) 256 | { 257 | match v { 258 | 0 => { 259 | self.index = v + 1; 260 | self.scroll_list(ScrollDirection::Up); 261 | } 262 | v if v > 0 => { 263 | self.index = v - 1; 264 | self.scroll_list(ScrollDirection::Down); 265 | } 266 | _ => {} 267 | } 268 | } 269 | } 270 | } 271 | 272 | /// Scroll module list up/down and select module. 273 | pub fn scroll_list(&mut self, direction: ScrollDirection) { 274 | self.info_scroll_offset = 0; 275 | if self.list.is_empty() { 276 | self.index = 0; 277 | } else { 278 | // Scroll module list. 279 | match direction { 280 | ScrollDirection::Up => self.previous_module(), 281 | ScrollDirection::Down => self.next_module(), 282 | ScrollDirection::Top => self.index = 0, 283 | ScrollDirection::Bottom => self.index = self.list.len() - 1, 284 | _ => {} 285 | } 286 | // Set current module name. 287 | self.current_name = self.list[self.index][0] 288 | .split_whitespace() 289 | .next() 290 | .unwrap_or("?") 291 | .trim() 292 | .to_string(); 293 | // Execute 'modinfo' and add style to its output. 294 | self.current_info.stylize_data( 295 | Box::leak( 296 | util::exec_cmd("modinfo", &[&self.current_name]) 297 | .unwrap_or_else(|e| { 298 | format!("module information not available: {e}") 299 | }) 300 | .replace("signature: ", "signature: \n") 301 | .into_boxed_str(), 302 | ), 303 | ":", 304 | self.style.clone(), 305 | ); 306 | // Clear the current command. 307 | if !self.command.is_none() { 308 | self.command = ModuleCommand::None; 309 | } 310 | } 311 | } 312 | 313 | /// Select the next module. 314 | pub fn next_module(&mut self) { 315 | self.index += 1; 316 | if self.index > self.list.len() - 1 { 317 | self.index = 0; 318 | } 319 | } 320 | 321 | /// Select the previous module. 322 | pub fn previous_module(&mut self) { 323 | if self.index > 0 { 324 | self.index -= 1; 325 | } else { 326 | self.index = self.list.len() - 1; 327 | } 328 | } 329 | 330 | /// Scroll the module information text up/down. 331 | pub fn scroll_mod_info( 332 | &mut self, 333 | direction: ScrollDirection, 334 | smooth_scroll: bool, 335 | ) { 336 | let scroll_amount = if smooth_scroll { 1 } else { 2 }; 337 | match direction { 338 | ScrollDirection::Up => { 339 | if self.info_scroll_offset > scroll_amount - 1 { 340 | self.info_scroll_offset -= scroll_amount; 341 | } 342 | } 343 | ScrollDirection::Down => { 344 | if self.current_info.lines() > 0 { 345 | self.info_scroll_offset += scroll_amount; 346 | self.info_scroll_offset %= self.current_info.lines() * 2; 347 | } 348 | } 349 | _ => {} 350 | } 351 | } 352 | } 353 | 354 | #[cfg(test)] 355 | mod tests { 356 | use super::*; 357 | #[test] 358 | fn test_kernel_modules() { 359 | let args = ArgMatches::default(); 360 | let mut list_args = ListArgs::new(&args); 361 | list_args.sort = SortType::Size; 362 | list_args.reverse = true; 363 | let mut kernel_modules = KernelModules::new(list_args, Style::new(&args)); 364 | for sort_type in SortType::iter().rev().chain(SortType::iter()) { 365 | kernel_modules.args.sort = *sort_type; 366 | kernel_modules.refresh(); 367 | } 368 | for direction in ScrollDirection::iter().rev().chain(ScrollDirection::iter()) 369 | { 370 | kernel_modules.show_used_module(0); 371 | kernel_modules.scroll_list(*direction); 372 | kernel_modules 373 | .scroll_mod_info(*direction, *direction == ScrollDirection::Up); 374 | } 375 | kernel_modules.scroll_list(ScrollDirection::Down); 376 | assert_eq!(0, kernel_modules.index); 377 | kernel_modules.scroll_list(ScrollDirection::Up); 378 | assert_eq!(kernel_modules.default_list.len() - 1, kernel_modules.index); 379 | assert_ne!(0, kernel_modules.default_list.len()); 380 | assert_ne!(0, kernel_modules.current_name.len()); 381 | assert_ne!(0, kernel_modules.current_info.lines()); 382 | kernel_modules 383 | .set_current_command(ModuleCommand::Load, String::from("test")); 384 | assert_eq!("test", kernel_modules.current_name); 385 | assert!(!kernel_modules.execute_command()); 386 | kernel_modules.set_current_command(ModuleCommand::Load, String::new()); 387 | kernel_modules.scroll_list(ScrollDirection::Top); 388 | for command in [ 389 | ModuleCommand::Unload, 390 | ModuleCommand::Blacklist, 391 | ModuleCommand::None, 392 | ] { 393 | kernel_modules.set_current_command(command, String::new()); 394 | assert_eq!(!command.is_none(), kernel_modules.cancel_execution()); 395 | } 396 | } 397 | } 398 | -------------------------------------------------------------------------------- /src/kernel/log.rs: -------------------------------------------------------------------------------- 1 | use crate::app::ScrollDirection; 2 | use crate::util; 3 | use std::fmt::Write as _; 4 | 5 | /// Kernel activity logs 6 | #[derive(Clone, Debug, Default)] 7 | pub struct KernelLogs { 8 | pub output: String, 9 | pub selected_output: String, 10 | last_line: String, 11 | crop_offset: usize, 12 | pub index: usize, 13 | } 14 | 15 | impl KernelLogs { 16 | /// Update the output variable value if 'dmesg' logs changed. 17 | pub fn update(&mut self) -> bool { 18 | self.output = util::exec_cmd( 19 | "dmesg", 20 | &["--kernel", "--human", "--ctime", "--color=never"], 21 | ) 22 | .unwrap_or_else(|e| format!("failed to retrieve dmesg output: {e}")); 23 | let logs_updated = 24 | self.output.lines().next_back().unwrap_or_default() != self.last_line; 25 | self.last_line = self 26 | .output 27 | .lines() 28 | .next_back() 29 | .unwrap_or_default() 30 | .to_string(); 31 | logs_updated 32 | } 33 | 34 | /// Refresh the kernel logs. 35 | pub fn refresh(&mut self) { 36 | self.last_line = String::new(); 37 | self.index = 0; 38 | self.crop_offset = 0; 39 | self.update(); 40 | } 41 | 42 | /// Select a part of the output depending on the area properties. 43 | pub fn select(&mut self, area_height: u16, area_sub: u16) -> &str { 44 | self.selected_output = self 45 | .output 46 | .lines() 47 | .map(|line| match line.char_indices().nth(self.crop_offset) { 48 | Some((pos, _)) => &line[pos..], 49 | None => "", 50 | }) 51 | .skip( 52 | area_height 53 | .checked_sub(area_sub) 54 | .and_then(|height| { 55 | (self.output.lines().count() - self.index) 56 | .checked_sub(height as usize) 57 | }) 58 | .unwrap_or(0), 59 | ) 60 | .fold(String::new(), |mut s, i| { 61 | let _ = writeln!(s, "{i}"); 62 | s 63 | }); 64 | &self.selected_output 65 | } 66 | 67 | /// Scroll the kernel logs up/down. 68 | pub fn scroll(&mut self, direction: ScrollDirection, smooth_scroll: bool) { 69 | let scroll_amount = if smooth_scroll { 1 } else { 3 }; 70 | match direction { 71 | ScrollDirection::Up => { 72 | if self.index + scroll_amount <= self.output.lines().count() { 73 | self.index += scroll_amount; 74 | } 75 | } 76 | ScrollDirection::Down => { 77 | if self.index > scroll_amount - 1 { 78 | self.index -= scroll_amount; 79 | } else { 80 | self.index = 0; 81 | } 82 | } 83 | ScrollDirection::Left => { 84 | self.crop_offset = self.crop_offset.saturating_sub(10) 85 | } 86 | ScrollDirection::Right => { 87 | self.crop_offset = self.crop_offset.checked_add(10).unwrap_or(0) 88 | } 89 | _ => {} 90 | } 91 | } 92 | } 93 | 94 | #[cfg(test)] 95 | mod tests { 96 | use super::*; 97 | #[test] 98 | fn test_kernel_logs() { 99 | let mut kernel_logs = KernelLogs::default(); 100 | for direction in ScrollDirection::iter().rev().chain(ScrollDirection::iter()) 101 | { 102 | kernel_logs.scroll(*direction, *direction == ScrollDirection::Top); 103 | } 104 | assert!(kernel_logs.update()); 105 | assert_ne!(0, kernel_logs.output.lines().count()); 106 | assert_ne!(0, kernel_logs.select(10, 2).len()); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/kernel/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod cmd; 2 | pub mod info; 3 | pub mod lkm; 4 | pub mod log; 5 | use crate::style::Style; 6 | use clap::ArgMatches; 7 | use info::KernelInfo; 8 | use lkm::{KernelModules, ListArgs}; 9 | use log::KernelLogs; 10 | 11 | /// Kernel struct for logs, information and modules 12 | pub struct Kernel { 13 | pub logs: KernelLogs, 14 | pub info: KernelInfo, 15 | pub modules: KernelModules<'static>, 16 | } 17 | 18 | impl Kernel { 19 | /// Create a new kernel instance. 20 | pub fn new(args: &ArgMatches) -> Self { 21 | Self { 22 | logs: KernelLogs::default(), 23 | info: KernelInfo::default(), 24 | modules: KernelModules::new(ListArgs::new(args), Style::new(args)), 25 | } 26 | } 27 | 28 | /// Refresh kernel logs, modules and information. 29 | pub fn refresh(&mut self) { 30 | self.logs.refresh(); 31 | self.info.refresh(); 32 | let _ = self.modules.refresh(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::tabs_in_doc_comments)] 2 | 3 | pub mod app; 4 | pub mod event; 5 | pub mod kernel; 6 | pub mod widgets; 7 | #[macro_use] 8 | pub mod util; 9 | pub mod args; 10 | pub mod style; 11 | 12 | use crate::app::{App, Block, InputMode, ScrollDirection}; 13 | use crate::kernel::cmd::ModuleCommand; 14 | use crate::kernel::Kernel; 15 | use enum_iterator::Sequence; 16 | use event::{Event, Events}; 17 | use ratatui::backend::Backend; 18 | use ratatui::layout::{Constraint, Direction, Layout}; 19 | use ratatui::Terminal; 20 | use std::error::Error; 21 | use termion::event::Key; 22 | use unicode_width::UnicodeWidthStr; 23 | 24 | /// Configure the terminal and draw its widgets. 25 | pub fn start_tui( 26 | mut terminal: Terminal, 27 | mut kernel: Kernel, 28 | events: &Events, 29 | ) -> Result<(), Box> 30 | where 31 | B: Backend, 32 | { 33 | // Configure the application. 34 | let mut app = App::new(Block::ModuleTable, kernel.modules.style.clone()); 35 | // Draw terminal and render the widgets. 36 | loop { 37 | terminal.draw(|frame| { 38 | let chunks = Layout::default() 39 | .direction(Direction::Vertical) 40 | .constraints( 41 | [ 42 | Constraint::Percentage(100 - app.block_size.activities), 43 | Constraint::Percentage(app.block_size.activities), 44 | ] 45 | .as_ref(), 46 | ) 47 | .split(frame.area()); 48 | { 49 | let chunks = Layout::default() 50 | .direction(Direction::Horizontal) 51 | .constraints( 52 | [ 53 | Constraint::Percentage(100 - app.block_size.info), 54 | Constraint::Percentage(app.block_size.info), 55 | ] 56 | .as_ref(), 57 | ) 58 | .split(chunks[0]); 59 | { 60 | let chunks = Layout::default() 61 | .direction(Direction::Vertical) 62 | .constraints( 63 | [Constraint::Length(3), Constraint::Percentage(100)] 64 | .as_ref(), 65 | ) 66 | .split(chunks[0]); 67 | { 68 | let chunks = Layout::default() 69 | .direction(Direction::Horizontal) 70 | .constraints( 71 | [ 72 | Constraint::Percentage(app.block_size.input), 73 | Constraint::Percentage( 74 | 100 - app.block_size.input, 75 | ), 76 | ] 77 | .as_ref(), 78 | ) 79 | .split(chunks[0]); 80 | app.draw_user_input(frame, chunks[0], &events.tx); 81 | app.draw_kernel_info( 82 | frame, 83 | chunks[1], 84 | &kernel.info.current_info, 85 | ); 86 | } 87 | if app.block_size.info != 100 { 88 | app.draw_dynamic_block(frame, chunks[1], &mut kernel); 89 | } else { 90 | app.block_index += 1; 91 | } 92 | } 93 | app.draw_dynamic_block(frame, chunks[1], &mut kernel); 94 | } 95 | app.draw_dynamic_block(frame, chunks[1], &mut kernel); 96 | if !app.input_mode.is_none() { 97 | frame.set_cursor_position((1 + app.input_query.width() as u16, 1)); 98 | } 99 | })?; 100 | // Handle terminal events. 101 | match events.rx.recv()? { 102 | // Key input events. 103 | Event::Input(input) => { 104 | let mut hide_options = true; 105 | if app.input_mode.is_none() { 106 | // Default input mode. 107 | match input { 108 | // Quit. 109 | Key::Char('q') 110 | | Key::Char('Q') 111 | | Key::Ctrl('c') 112 | | Key::Ctrl('d') 113 | | Key::Esc => { 114 | if app.show_options { 115 | app.show_options = false; 116 | } else { 117 | break; 118 | } 119 | } 120 | // Refresh. 121 | Key::Char('r') | Key::Char('R') | Key::F(5) => { 122 | app.refresh(); 123 | kernel.refresh(); 124 | } 125 | // Show help message. 126 | Key::Char('?') | Key::F(1) => { 127 | app.show_help_message(&mut kernel.modules); 128 | } 129 | Key::Char('m') | Key::Char('o') => { 130 | app.show_options = true; 131 | hide_options = false; 132 | } 133 | // Scroll the selected block up. 134 | Key::Up 135 | | Key::Char('k') 136 | | Key::Char('K') 137 | | Key::Alt('k') 138 | | Key::Alt('K') => { 139 | if app.show_options { 140 | app.options.previous(); 141 | continue; 142 | } else { 143 | app.options.state.select(Some(0)); 144 | } 145 | match app.selected_block { 146 | Block::ModuleTable => { 147 | kernel.modules.scroll_list(ScrollDirection::Up) 148 | } 149 | Block::ModuleInfo => kernel.modules.scroll_mod_info( 150 | ScrollDirection::Up, 151 | input == Key::Alt('k') || input == Key::Alt('K'), 152 | ), 153 | Block::Activities => { 154 | kernel.logs.scroll( 155 | ScrollDirection::Up, 156 | input == Key::Alt('k') 157 | || input == Key::Alt('K'), 158 | ); 159 | } 160 | _ => {} 161 | } 162 | } 163 | // Scroll the selected block down. 164 | Key::Down 165 | | Key::Char('j') 166 | | Key::Char('J') 167 | | Key::Alt('j') 168 | | Key::Alt('J') => { 169 | if app.show_options { 170 | app.options.next(); 171 | continue; 172 | } else { 173 | app.options.state.select(Some(0)); 174 | } 175 | match app.selected_block { 176 | Block::ModuleTable => { 177 | kernel.modules.scroll_list(ScrollDirection::Down) 178 | } 179 | Block::ModuleInfo => kernel.modules.scroll_mod_info( 180 | ScrollDirection::Down, 181 | input == Key::Alt('j') || input == Key::Alt('J'), 182 | ), 183 | Block::Activities => { 184 | kernel.logs.scroll( 185 | ScrollDirection::Down, 186 | input == Key::Alt('j') 187 | || input == Key::Alt('J'), 188 | ); 189 | } 190 | _ => {} 191 | } 192 | } 193 | // Select the next terminal block. 194 | Key::Left | Key::Char('h') | Key::Char('H') => { 195 | app.selected_block = match app.selected_block.previous() 196 | { 197 | Some(v) => v, 198 | None => Block::last().unwrap(), 199 | } 200 | } 201 | // Select the previous terminal block. 202 | Key::Right | Key::Char('l') | Key::Char('L') => { 203 | app.selected_block = match app.selected_block.next() { 204 | Some(v) => v, 205 | None => Block::first().unwrap(), 206 | } 207 | } 208 | // Expand the selected block. 209 | Key::Alt('e') => { 210 | let block_size = app.block_size(); 211 | if *block_size < 95 { 212 | *block_size += 5; 213 | } else { 214 | *block_size = 100; 215 | } 216 | } 217 | // Shrink the selected block. 218 | Key::Alt('s') => { 219 | let block_size = app.block_size(); 220 | *block_size = 221 | (*block_size).checked_sub(5).unwrap_or_default() 222 | } 223 | // Change the block position. 224 | Key::Ctrl('x') => { 225 | if app.block_index == 2 { 226 | app.block_index = 0; 227 | } else { 228 | app.block_index += 1; 229 | } 230 | } 231 | // Scroll to the top of the module list. 232 | Key::Ctrl('t') | Key::Home => { 233 | app.options.state.select(Some(0)); 234 | app.selected_block = Block::ModuleTable; 235 | kernel.modules.scroll_list(ScrollDirection::Top) 236 | } 237 | // Scroll to the bottom of the module list. 238 | Key::Ctrl('b') | Key::End => { 239 | app.options.state.select(Some(0)); 240 | app.selected_block = Block::ModuleTable; 241 | kernel.modules.scroll_list(ScrollDirection::Bottom) 242 | } 243 | // Scroll kernel activities up. 244 | Key::PageUp => { 245 | app.selected_block = Block::Activities; 246 | kernel.logs.scroll(ScrollDirection::Up, false); 247 | } 248 | // Scroll kernel activities down. 249 | Key::PageDown => { 250 | app.selected_block = Block::Activities; 251 | kernel.logs.scroll(ScrollDirection::Down, false); 252 | } 253 | // Scroll kernel activities left. 254 | Key::Alt('h') | Key::Alt('H') => { 255 | app.selected_block = Block::Activities; 256 | kernel.logs.scroll(ScrollDirection::Left, false); 257 | } 258 | // Scroll kernel activities right. 259 | Key::Alt('l') | Key::Alt('L') => { 260 | app.selected_block = Block::Activities; 261 | kernel.logs.scroll(ScrollDirection::Right, false); 262 | } 263 | // Scroll module information up. 264 | Key::Char('<') | Key::Alt(' ') => { 265 | app.selected_block = Block::ModuleInfo; 266 | kernel 267 | .modules 268 | .scroll_mod_info(ScrollDirection::Up, false) 269 | } 270 | // Scroll module information down. 271 | Key::Char('>') | Key::Char(' ') => { 272 | app.selected_block = Block::ModuleInfo; 273 | kernel 274 | .modules 275 | .scroll_mod_info(ScrollDirection::Down, false) 276 | } 277 | // Show the next kernel information. 278 | Key::Char('\\') | Key::Char('\t') | Key::BackTab => { 279 | kernel.info.next(); 280 | } 281 | // Display the dependent modules. 282 | Key::Char('d') | Key::Alt('d') => { 283 | app.show_dependent_modules(&mut kernel.modules); 284 | } 285 | // Clear the kernel ring buffer. 286 | Key::Ctrl('l') 287 | | Key::Ctrl('u') 288 | | Key::Alt('c') 289 | | Key::Alt('C') => { 290 | kernel.modules.set_current_command( 291 | ModuleCommand::Clear, 292 | String::new(), 293 | ); 294 | } 295 | // Unload kernel module. 296 | Key::Char('u') 297 | | Key::Char('U') 298 | | Key::Char('-') 299 | | Key::Backspace 300 | | Key::Ctrl('h') => { 301 | kernel.modules.set_current_command( 302 | ModuleCommand::Unload, 303 | String::new(), 304 | ); 305 | } 306 | // Blacklist kernel module. 307 | Key::Char('x') 308 | | Key::Char('X') 309 | | Key::Char('b') 310 | | Key::Char('B') 311 | | Key::Delete => { 312 | kernel.modules.set_current_command( 313 | ModuleCommand::Blacklist, 314 | String::new(), 315 | ); 316 | } 317 | // Reload kernel module. 318 | Key::Ctrl('r') 319 | | Key::Ctrl('R') 320 | | Key::Alt('r') 321 | | Key::Alt('R') => { 322 | kernel.modules.set_current_command( 323 | ModuleCommand::Reload, 324 | String::new(), 325 | ); 326 | } 327 | // Execute the current command. 328 | Key::Char('y') | Key::Char('Y') => { 329 | if kernel.modules.execute_command() { 330 | events 331 | .tx 332 | .send(Event::Input(Key::Char('r'))) 333 | .unwrap(); 334 | } 335 | } 336 | // Cancel the execution of current command. 337 | Key::Char('n') | Key::Char('N') => { 338 | if kernel.modules.cancel_execution() { 339 | app.selected_block = Block::ModuleTable; 340 | } 341 | } 342 | // Copy the data in selected block to clipboard. 343 | Key::Char('c') | Key::Char('C') => { 344 | app.set_clipboard_contents(match app.selected_block { 345 | Block::ModuleTable => &kernel.modules.current_name, 346 | Block::ModuleInfo => { 347 | &kernel.modules.current_info.raw_text 348 | } 349 | Block::Activities => { 350 | kernel.logs.selected_output.trim() 351 | } 352 | _ => "", 353 | }); 354 | } 355 | // Paste the clipboard contents and switch to search mode. 356 | Key::Char('v') | Key::Ctrl('V') | Key::Ctrl('v') => { 357 | let clipboard_contents = app.get_clipboard_contents(); 358 | app.input_query += &clipboard_contents; 359 | events.tx.send(Event::Input(Key::Char('\n'))).unwrap(); 360 | kernel.modules.index = 0; 361 | } 362 | // User input mode. 363 | Key::Char('\n') 364 | | Key::Char('s') 365 | | Key::Char('S') 366 | | Key::Char('i') 367 | | Key::Char('I') 368 | | Key::Char('+') 369 | | Key::Char('/') 370 | | Key::Insert => { 371 | if input == Key::Char('\n') && app.show_options { 372 | if let Ok(command) = ModuleCommand::try_from( 373 | app.options 374 | .selected() 375 | .map(|(v, _)| v.to_string()) 376 | .unwrap_or_default(), 377 | ) { 378 | if command == ModuleCommand::Load { 379 | events 380 | .tx 381 | .send(Event::Input(Key::Char('+'))) 382 | .unwrap(); 383 | } else { 384 | kernel.modules.set_current_command( 385 | command, 386 | String::new(), 387 | ); 388 | } 389 | } else { 390 | match app 391 | .options 392 | .selected() 393 | .map(|(v, _)| v.as_ref()) 394 | { 395 | Some("dependent") => { 396 | app.show_dependent_modules( 397 | &mut kernel.modules, 398 | ); 399 | } 400 | Some("copy") => app.set_clipboard_contents( 401 | &kernel.modules.current_name, 402 | ), 403 | _ => {} 404 | } 405 | } 406 | } else { 407 | app.selected_block = Block::UserInput; 408 | app.input_mode = match input { 409 | Key::Char('+') 410 | | Key::Char('i') 411 | | Key::Char('I') 412 | | Key::Insert => InputMode::Load, 413 | _ => InputMode::Search, 414 | }; 415 | if input != Key::Char('\n') { 416 | app.input_query = String::new(); 417 | } 418 | } 419 | } 420 | // Other character input. 421 | Key::Char(v) => { 422 | // Check if input is a number except zero. 423 | let index = v.to_digit(10).unwrap_or(0); 424 | // Show the used module info at given index. 425 | if index != 0 && !kernel.modules.list.is_empty() { 426 | app.selected_block = Block::ModuleTable; 427 | kernel.modules.show_used_module(index as usize - 1); 428 | } 429 | } 430 | _ => {} 431 | } 432 | } else { 433 | // User input mode. 434 | match input { 435 | // Quit with ctrl-d. 436 | Key::Ctrl('d') => { 437 | break; 438 | } 439 | // Switch to the previous input mode. 440 | Key::Up => { 441 | app.input_mode = match app.input_mode.previous() { 442 | Some(v) => v, 443 | None => InputMode::last().unwrap(), 444 | }; 445 | if app.input_mode.is_none() { 446 | app.input_mode = InputMode::last().unwrap(); 447 | } 448 | app.input_query = String::new(); 449 | } 450 | // Switch to the next input mode. 451 | Key::Down => { 452 | app.input_mode = match app.input_mode.next() { 453 | Some(v) => v, 454 | None => InputMode::first() 455 | .and_then(|v| v.next()) 456 | .unwrap(), 457 | }; 458 | app.input_query = String::new(); 459 | } 460 | // Copy input query to the clipboard. 461 | Key::Ctrl('c') => { 462 | let query = app.input_query.clone(); 463 | app.set_clipboard_contents(&query); 464 | } 465 | // Paste the clipboard contents. 466 | Key::Ctrl('v') => { 467 | let clipboard_contents = app.get_clipboard_contents(); 468 | app.input_query += &clipboard_contents; 469 | } 470 | // Exit user input mode. 471 | Key::Char('\n') 472 | | Key::Char('\t') 473 | | Key::F(1) 474 | | Key::Right 475 | | Key::Left => { 476 | // Select the next eligible block for action. 477 | app.selected_block = match input { 478 | Key::Left => match app.selected_block.previous() { 479 | Some(v) => v, 480 | None => Block::last().unwrap(), 481 | }, 482 | Key::Char('\n') => match app.input_mode { 483 | InputMode::Load 484 | if !app.input_query.is_empty() => 485 | { 486 | Block::ModuleInfo 487 | } 488 | _ => Block::ModuleTable, 489 | }, 490 | _ => Block::ModuleTable, 491 | }; 492 | // Show the first modules information if the search mode is set. 493 | if app.input_mode == InputMode::Search 494 | && kernel.modules.index == 0 495 | { 496 | kernel.modules.scroll_list(ScrollDirection::Top); 497 | // Load kernel module. 498 | } else if app.input_mode == InputMode::Load 499 | && !app.input_query.is_empty() 500 | { 501 | kernel.modules.set_current_command( 502 | ModuleCommand::Load, 503 | app.input_query, 504 | ); 505 | app.input_query = String::new(); 506 | } 507 | // Set the input mode flag. 508 | app.input_mode = InputMode::None; 509 | } 510 | // Append character to input query. 511 | Key::Char(c) => { 512 | app.input_query.push(c); 513 | kernel.modules.index = 0; 514 | } 515 | // Delete the last character from input query. 516 | Key::Backspace | Key::Ctrl('h') => { 517 | app.input_query.pop(); 518 | kernel.modules.index = 0; 519 | } 520 | // Clear the input query. 521 | Key::Delete | Key::Ctrl('l') => { 522 | app.input_query = String::new(); 523 | kernel.modules.index = 0; 524 | } 525 | // Clear the input query and exit user input mode. 526 | Key::Esc => { 527 | events.tx.send(Event::Input(Key::Delete)).unwrap(); 528 | events.tx.send(Event::Input(Key::Char('\n'))).unwrap(); 529 | } 530 | _ => {} 531 | } 532 | } 533 | if hide_options { 534 | app.show_options = false; 535 | } 536 | } 537 | // Kernel events. 538 | Event::Kernel(logs) => { 539 | kernel.logs.output = logs; 540 | } 541 | _ => {} 542 | } 543 | } 544 | Ok(()) 545 | } 546 | 547 | #[cfg(test)] 548 | mod tests { 549 | use super::*; 550 | use clap::ArgMatches; 551 | use ratatui::backend::TestBackend; 552 | use std::sync::mpsc::Sender; 553 | use std::thread; 554 | use std::time::Duration; 555 | #[test] 556 | fn test_tui() -> Result<(), Box> { 557 | let args = ArgMatches::default(); 558 | let kernel = Kernel::new(&args); 559 | let events = Events::new(100, &kernel.logs); 560 | let tx = events.tx.clone(); 561 | thread::spawn(move || { 562 | // Test the general keys. 563 | for key in [ 564 | Key::Char('?'), 565 | Key::Ctrl('t'), 566 | Key::Ctrl('b'), 567 | Key::Alt('e'), 568 | Key::Alt('s'), 569 | Key::Ctrl('x'), 570 | Key::Ctrl('x'), 571 | Key::Ctrl('x'), 572 | Key::Char('x'), 573 | Key::Char('n'), 574 | Key::Char('d'), 575 | Key::Ctrl('l'), 576 | Key::Char('u'), 577 | Key::Ctrl('r'), 578 | Key::Char('y'), 579 | Key::PageUp, 580 | Key::PageDown, 581 | Key::Alt('l'), 582 | Key::Alt('h'), 583 | Key::Char('<'), 584 | Key::Char('>'), 585 | Key::Char('\t'), 586 | Key::Char('m'), 587 | Key::Down, 588 | Key::Char('\n'), 589 | ] { 590 | send_key(&tx, key); 591 | } 592 | send_key(&tx, Key::Char('r')); 593 | // Test the switch keys. 594 | for arrow_key in [Key::Right, Key::Left] { 595 | for selected_key in [arrow_key; Block::CARDINALITY] { 596 | send_key(&tx, selected_key); 597 | for key in [ 598 | Key::Up, 599 | Key::Down, 600 | Key::Down, 601 | Key::Up, 602 | Key::Char('c'), 603 | Key::Char('~'), 604 | Key::Char('1'), 605 | ] { 606 | send_key(&tx, key); 607 | } 608 | } 609 | } 610 | // Test the input mode keys. 611 | for key in [ 612 | Key::Char('v'), 613 | Key::Delete, 614 | Key::Char('~'), 615 | Key::Backspace, 616 | Key::Ctrl('c'), 617 | Key::Ctrl('v'), 618 | Key::Char('a'), 619 | Key::Char('\n'), 620 | Key::Char('\n'), 621 | Key::Char('?'), 622 | Key::Char('\n'), 623 | Key::Esc, 624 | Key::Char('i'), 625 | Key::Char('x'), 626 | Key::Char('\n'), 627 | ] { 628 | send_key(&tx, key); 629 | } 630 | // Exit. 631 | send_key(&tx, Key::Esc) 632 | }); 633 | start_tui(Terminal::new(TestBackend::new(20, 10))?, kernel, &events) 634 | } 635 | 636 | // Try to send a key event until Sender succeeds. 637 | fn send_key(tx: &Sender>, key: Key) { 638 | let mut x = true; 639 | while x { 640 | x = tx.send(Event::Input(key)).is_err(); 641 | thread::sleep(Duration::from_millis(10)); 642 | } 643 | } 644 | } 645 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use kmon::args; 2 | use kmon::event::Events; 3 | use kmon::kernel::Kernel; 4 | use kmon::util; 5 | use ratatui::backend::TermionBackend; 6 | use ratatui::Terminal; 7 | use std::error::Error; 8 | use std::io::stdout; 9 | use termion::input::MouseTerminal; 10 | use termion::raw::IntoRawMode; 11 | use termion::screen::IntoAlternateScreen; 12 | 13 | /// Entry point. 14 | fn main() -> Result<(), Box> { 15 | let args = args::get_args().get_matches(); 16 | let kernel = Kernel::new(&args); 17 | let events = Events::new( 18 | args.get_one::("rate") 19 | .unwrap() 20 | .parse::() 21 | .unwrap_or(250), 22 | &kernel.logs, 23 | ); 24 | if !cfg!(test) { 25 | util::setup_panic_hook()?; 26 | let stdout = stdout().into_raw_mode()?.into_alternate_screen()?; 27 | let stdout = MouseTerminal::from(stdout); 28 | let backend = TermionBackend::new(stdout); 29 | kmon::start_tui(Terminal::new(backend)?, kernel, &events) 30 | } else { 31 | Ok(()) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/style.rs: -------------------------------------------------------------------------------- 1 | use clap::ArgMatches; 2 | use colorsys::Rgb; 3 | use ratatui::style::{Color, Modifier, Style as TuiStyle}; 4 | use ratatui::text::{Line, Span, Text}; 5 | use std::collections::HashMap; 6 | 7 | /// Unicode symbol 8 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] 9 | pub enum Symbol { 10 | None, 11 | Blank, 12 | Gear, 13 | Cloud, 14 | Anchor, 15 | Helmet, 16 | CircleX, 17 | SquareX, 18 | NoEntry, 19 | FuelPump, 20 | Magnifier, 21 | HighVoltage, 22 | LeftBracket, 23 | RightBracket, 24 | HistoricSite, 25 | } 26 | 27 | /// Supported Unicode symbols 28 | #[derive(Clone, Debug)] 29 | pub struct Unicode<'a> { 30 | symbols: HashMap, 31 | replace: bool, 32 | } 33 | 34 | impl Unicode<'_> { 35 | /// Create a new Unicode instance. 36 | pub fn new(replace: bool) -> Self { 37 | Self { 38 | symbols: map! { 39 | Symbol::None => &["", ""], 40 | Symbol::Blank => &["\u{2800} ", "\u{2800} "], 41 | Symbol::Gear => &[" \u{2699} ", ""], 42 | Symbol::Cloud => &[" \u{26C5} ", ""], 43 | Symbol::Anchor => &[" \u{2693}", ""], 44 | Symbol::Helmet => &[" \u{26D1} ", ""], 45 | Symbol::CircleX => &[" \u{1F167} ", ""], 46 | Symbol::SquareX => &[" \u{1F187} ", ""], 47 | Symbol::NoEntry => &[" \u{26D4}", ""], 48 | Symbol::FuelPump => &[" \u{26FD}", ""], 49 | Symbol::Magnifier => &[" \u{1F50D}", ""], 50 | Symbol::HighVoltage => &[" \u{26A1}", ""], 51 | Symbol::LeftBracket => &["\u{2997}", "("], 52 | Symbol::RightBracket => &["\u{2998}", ")"], 53 | Symbol::HistoricSite => &[" \u{26EC} ", ""] 54 | }, 55 | replace, 56 | } 57 | } 58 | 59 | /// Get string from a Unicode symbol. 60 | pub fn get(&self, symbol: Symbol) -> &str { 61 | self.symbols[&symbol][self.replace as usize] 62 | } 63 | } 64 | 65 | /// Style properties 66 | #[derive(Clone, Debug)] 67 | pub struct Style { 68 | pub default: TuiStyle, 69 | pub bold: TuiStyle, 70 | pub colored: TuiStyle, 71 | pub unicode: Unicode<'static>, 72 | } 73 | 74 | impl Style { 75 | /// Create a new style instance from given arguments. 76 | pub fn new(args: &ArgMatches) -> Self { 77 | let mut default = TuiStyle::reset(); 78 | if let Ok(true) = args.try_contains_id("accent-color") { 79 | default = 80 | default.fg(Self::get_color(args, "accent-color", Color::White)); 81 | } 82 | Self { 83 | default, 84 | bold: TuiStyle::reset().add_modifier(Modifier::BOLD), 85 | colored: TuiStyle::reset().fg(Self::get_color( 86 | args, 87 | "color", 88 | Color::DarkGray, 89 | )), 90 | unicode: Unicode::new( 91 | args.try_get_one::("unicode").ok().flatten() == Some(&false), 92 | ), 93 | } 94 | } 95 | 96 | /// Parse a color value from arguments. 97 | fn get_color(args: &ArgMatches, arg_name: &str, default_color: Color) -> Color { 98 | let colors = map![ 99 | "black" => Color::Black, 100 | "red" => Color::Red, 101 | "green" => Color::Green, 102 | "yellow" => Color::Yellow, 103 | "blue" => Color::Blue, 104 | "magenta" => Color::Magenta, 105 | "cyan" => Color::Cyan, 106 | "gray" => Color::Gray, 107 | "darkgray" => Color::DarkGray, 108 | "lightred" => Color::LightRed, 109 | "lightgreen" => Color::LightGreen, 110 | "lightyellow" => Color::LightYellow, 111 | "lightblue" => Color::LightBlue, 112 | "lightmagenta" => Color::LightMagenta, 113 | "lightcyan" => Color::LightCyan, 114 | "white" => Color::White 115 | ]; 116 | match args.try_get_one::(arg_name) { 117 | Ok(Some(v)) => *colors.get::(&v.to_lowercase()).unwrap_or({ 118 | if let Ok(rgb) = Rgb::from_hex_str(&format!("#{v}")) { 119 | Box::leak(Box::new(Color::Rgb( 120 | rgb.red() as u8, 121 | rgb.green() as u8, 122 | rgb.blue() as u8, 123 | ))) 124 | } else { 125 | &default_color 126 | } 127 | }), 128 | _ => default_color, 129 | } 130 | } 131 | } 132 | 133 | /// Styled text that has raw and style parts 134 | #[derive(Debug, Default)] 135 | pub struct StyledText<'a> { 136 | pub raw_text: String, 137 | pub styled_text: Text<'a>, 138 | } 139 | 140 | impl<'a> StyledText<'a> { 141 | /// Get a vector of Text widget from styled text. 142 | pub fn get(&'a self) -> Text<'a> { 143 | if self.styled_text.lines.is_empty() { 144 | Text::raw(&self.raw_text) 145 | } else { 146 | self.styled_text.clone() 147 | } 148 | } 149 | 150 | /// Set a styled text. 151 | pub fn set(&mut self, text: Text<'static>, placeholder: String) { 152 | self.styled_text = text; 153 | self.raw_text = placeholder; 154 | } 155 | 156 | /// Add style to given text depending on a delimiter. 157 | pub fn stylize_data( 158 | &mut self, 159 | text: &'a str, 160 | delimiter: &str, 161 | style: Style, 162 | ) -> Text<'a> { 163 | self.styled_text = Text::default(); 164 | self.raw_text = text.to_string(); 165 | for line in text.lines() { 166 | let data = line.split(delimiter).collect::>(); 167 | if data.len() > 1 && data[0].trim().len() > 2 { 168 | self.styled_text.lines.push(Line::from(vec![ 169 | Span::styled(format!("{}{}", data[0], delimiter), style.colored), 170 | Span::styled(data[1..data.len()].join(delimiter), style.default), 171 | ])); 172 | } else { 173 | self.styled_text 174 | .lines 175 | .push(Line::from(Span::styled(line, style.default))) 176 | } 177 | } 178 | self.styled_text.clone() 179 | } 180 | 181 | /// Return the line count of styled text. 182 | pub fn lines(&self) -> usize { 183 | if self.styled_text.lines.is_empty() { 184 | self.raw_text.lines().count() 185 | } else { 186 | self.styled_text.lines.len() 187 | } 188 | } 189 | } 190 | 191 | #[cfg(test)] 192 | mod tests { 193 | use super::*; 194 | use clap::ArgMatches; 195 | #[test] 196 | fn test_style() { 197 | let args = ArgMatches::default(); 198 | let style = Style::new(&args); 199 | let mut styled_text = StyledText::default(); 200 | styled_text.set( 201 | Text::styled("styled\ntext", style.colored), 202 | String::from("test"), 203 | ); 204 | assert_eq!( 205 | Text::styled("styled\ntext", style.colored), 206 | styled_text.get() 207 | ); 208 | assert_eq!(2, styled_text.lines()); 209 | assert_eq!("test", styled_text.raw_text); 210 | } 211 | #[test] 212 | fn test_unicode() { 213 | let mut unicode = Unicode::new(true); 214 | for symbol in unicode.symbols.clone() { 215 | if symbol.0 != Symbol::Blank { 216 | assert!(symbol.1[1].len() < 2) 217 | } 218 | } 219 | unicode.replace = false; 220 | for symbol in unicode.symbols { 221 | if symbol.0 != Symbol::None { 222 | assert_ne!("", symbol.1[0]); 223 | } 224 | } 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /src/util.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::io::{self, Write}; 3 | use std::panic; 4 | use std::process::Command; 5 | use termion::raw::IntoRawMode; 6 | 7 | /// Macro for concise initialization of hashmap 8 | macro_rules! map { 9 | ($( $key: expr => $val: expr ),*) => {{ 10 | let mut map = ::std::collections::HashMap::new(); 11 | $( map.insert($key, $val); )* 12 | map 13 | }} 14 | } 15 | 16 | /// Array of the key bindings 17 | pub const KEY_BINDINGS: &[(&str, &str)] = &[ 18 | ("'?', f1", "help"), 19 | ("right/left, h/l", "switch between blocks"), 20 | ("up/down, k/j, alt-k/j", "scroll up/down [selected block]"), 21 | ("pgup/pgdown", "scroll up/down [kernel activities]"), 22 | ("", "scroll up/down [module information]"), 23 | ("alt-h/l", "scroll right/left [kernel activities]"), 24 | ("ctrl-t/b, home/end", "scroll to top/bottom [module list]"), 25 | ("alt-e/s", "expand/shrink the selected block"), 26 | ("ctrl-x", "change the block position"), 27 | ("ctrl-l/u, alt-c", "clear the kernel ring buffer"), 28 | ("d, alt-d", "show the dependent modules"), 29 | ("1..9", "jump to the dependent module"), 30 | ("\\, tab, backtab", "show the next kernel information"), 31 | ("/, s, enter", "search a kernel module"), 32 | ("+, i, insert", "load a kernel module"), 33 | ("-, u, backspace", "unload the kernel module"), 34 | ("x, b, delete", "blacklist the kernel module"), 35 | ("ctrl-r, alt-r", "reload the kernel module"), 36 | ("m, o", "show the options menu"), 37 | ("y/n", "execute/cancel the command"), 38 | ("c/v", "copy/paste"), 39 | ("r, f5", "refresh"), 40 | ("q, ctrl-c/d, esc", "quit"), 41 | ]; 42 | 43 | /// Execute a operating system command and return its output. 44 | pub fn exec_cmd(cmd: &str, cmd_args: &[&str]) -> Result { 45 | match Command::new(cmd).args(cmd_args).output() { 46 | Ok(output) => { 47 | if output.status.success() { 48 | Ok(String::from_utf8(output.stdout) 49 | .expect("not UTF-8") 50 | .trim_end() 51 | .to_string()) 52 | } else { 53 | Err(String::from_utf8(output.stderr) 54 | .expect("not UTF-8") 55 | .trim_end() 56 | .to_string()) 57 | } 58 | } 59 | Err(e) => Err(e.to_string()), 60 | } 61 | } 62 | 63 | /// Sets up the panic hook for the terminal. 64 | /// 65 | /// See 66 | pub fn setup_panic_hook() -> Result<(), Box> { 67 | let raw_output = io::stdout().into_raw_mode()?; 68 | raw_output.suspend_raw_mode()?; 69 | 70 | let panic_hook = panic::take_hook(); 71 | panic::set_hook(Box::new(move |panic| { 72 | let panic_cleanup = || -> Result<(), Box> { 73 | let mut output = io::stdout(); 74 | write!( 75 | output, 76 | "{}{}{}", 77 | termion::clear::All, 78 | termion::screen::ToMainScreen, 79 | termion::cursor::Show 80 | )?; 81 | raw_output.suspend_raw_mode()?; 82 | output.flush()?; 83 | Ok(()) 84 | }; 85 | panic_cleanup().expect("failed to clean up for panic"); 86 | panic_hook(panic); 87 | })); 88 | 89 | Ok(()) 90 | } 91 | 92 | #[cfg(test)] 93 | mod tests { 94 | use super::*; 95 | #[test] 96 | fn test_exec_cmd() { 97 | assert_eq!("test", exec_cmd("printf", &["test"]).unwrap()); 98 | assert_eq!( 99 | "true", 100 | exec_cmd("sh", &["-c", "test 10 -eq 10 && echo 'true'"]).unwrap() 101 | ); 102 | assert_eq!( 103 | "err", 104 | exec_cmd("cat", &["-x"]).unwrap_or(String::from("err")) 105 | ); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/widgets.rs: -------------------------------------------------------------------------------- 1 | use ratatui::widgets::ListState; 2 | 3 | /// List widget with TUI controlled states. 4 | #[derive(Debug)] 5 | pub struct StatefulList { 6 | /// List items (states). 7 | pub items: Vec, 8 | /// State that can be modified by TUI. 9 | pub state: ListState, 10 | } 11 | 12 | impl StatefulList { 13 | /// Constructs a new instance of `StatefulList`. 14 | pub fn new(items: Vec, mut state: ListState) -> StatefulList { 15 | state.select(Some(0)); 16 | Self { items, state } 17 | } 18 | 19 | /// Construct a new `StatefulList` with given items. 20 | pub fn with_items(items: Vec) -> StatefulList { 21 | Self::new(items, ListState::default()) 22 | } 23 | 24 | /// Returns the selected item. 25 | pub fn selected(&self) -> Option<&T> { 26 | self.items.get(self.state.selected()?) 27 | } 28 | 29 | /// Selects the next item. 30 | pub fn next(&mut self) { 31 | let i = match self.state.selected() { 32 | Some(i) => { 33 | if i >= self.items.len() - 1 { 34 | 0 35 | } else { 36 | i + 1 37 | } 38 | } 39 | None => 0, 40 | }; 41 | self.state.select(Some(i)); 42 | } 43 | 44 | /// Selects the previous item. 45 | pub fn previous(&mut self) { 46 | let i = match self.state.selected() { 47 | Some(i) => { 48 | if i == 0 { 49 | self.items.len() - 1 50 | } else { 51 | i - 1 52 | } 53 | } 54 | None => 0, 55 | }; 56 | self.state.select(Some(i)); 57 | } 58 | } 59 | 60 | #[cfg(test)] 61 | mod tests { 62 | use super::*; 63 | 64 | #[test] 65 | fn test_stateful_list() { 66 | let mut list = StatefulList::with_items(vec!["data1", "data2", "data3"]); 67 | list.state.select(Some(1)); 68 | assert_eq!(Some(&"data2"), list.selected()); 69 | list.next(); 70 | assert_eq!(Some(2), list.state.selected()); 71 | list.previous(); 72 | assert_eq!(Some(1), list.state.selected()); 73 | } 74 | } 75 | --------------------------------------------------------------------------------