From 940d82561d4cee4ef432d99b7bb4ea8f7b6782b3 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 4 May 2024 21:06:17 +0200 Subject: [PATCH] style(treewide): Format and improve the headers This commit represents one run of `./scripts/renew_copyright_headers.sh`. --- Cargo.toml | 21 ++-- README.md | 6 +- branding/README.md | 1 + config/c/plugin.c | 191 ++++++++++++++++++-------------- config/lua/init.lua | 27 ++--- docs/CommandLine.md | 4 +- docs/Commands.md | 1 + docs/CommitMessageStyle.md | 32 +++--- docs/Config.md | 3 +- docs/Philosophy.md | 3 + docs/trinitrix.1.md | 4 +- flake.nix | 1 - scripts/valgrind_test.sh | 4 +- src/app/events/handlers/main.rs | 2 +- src/ui/mod.rs | 2 +- src/ui/old/central/mod.rs | 3 +- src/ui/old/mod.rs | 1 - treefmt.nix | 1 - update.sh | 3 +- 19 files changed, 170 insertions(+), 140 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6ffbec2..c5d3f57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,26 +38,31 @@ default-run = "trinitrix" clap = { version = "4.5.4", features = ["derive"] } cli-log = "2.0" anyhow = "1.0" -tokio = { version = "1.37", features = ["macros", "rt-multi-thread", "fs", "time"] } -tokio-util = {version = "0.7.10"} +tokio = { version = "1.37", features = [ + "macros", + "rt-multi-thread", + "fs", + "time", +] } +tokio-util = { version = "0.7.10" } # config -trinitry = {version = "0.1.0"} -keymaps = {version = "0.1.1", features = ["crossterm"] } +trinitry = { version = "0.1.0" } +keymaps = { version = "0.1.1", features = ["crossterm"] } directories = "5.0.1" # c api libloading = "0.8.3" -trixy = {version = "0.1.1"} +trixy = { version = "0.1.1" } # lua stuff mlua = { version = "0.9.7", features = ["lua54", "async", "send", "serialize"] } once_cell = "1.19.0" # tui feature specific parts -tui = {version = "0.19"} -tui-textarea = { version = "0.2", features = ["crossterm"]} -crossterm = { version = "0.25"} +tui = { version = "0.19" } +tui-textarea = { version = "0.2", features = ["crossterm"] } +crossterm = { version = "0.25" } [dev-dependencies] pretty_assertions = "1.4.0" diff --git a/README.md b/README.md index b6e6c2c..f66e9d7 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,14 @@ OTHER DEALINGS IN THE SOFTWARE. --> # Trinitrix + Trinitrix is a terminal UI client for the matrix chat protocol. Docs can be found [here](https://git.nerdcult.net/antifallobst/trinitrix/src/branch/master/docs). ---- +______________________________________________________________________ # License (MIT) + Copyright 2023 The Trinitrix Project Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -52,4 +54,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +OTHER DEALINGS IN THE SOFTWARE. diff --git a/branding/README.md b/branding/README.md index 1db7c70..9c58c1a 100644 --- a/branding/README.md +++ b/branding/README.md @@ -27,4 +27,5 @@ OTHER DEALINGS IN THE SOFTWARE. --> # License + The [square Trinitrix Logo](./square.svg) by Eric-Paul Ickhorn is marked with the CC0 1.0 Universal License. diff --git a/config/c/plugin.c b/config/c/plugin.c index 82f941e..09c76b6 100644 --- a/config/c/plugin.c +++ b/config/c/plugin.c @@ -1,30 +1,30 @@ /* -* Copyright (C) 2024 - 2024: -* The Trinitrix Project -* SPDX-License-Identifier: MIT -* -* This file is part of Trinitrix. -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation files -* (the “Software”), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, -* publish, distribute, sublicense, and/or sell copies of the Software, -* and to permit persons to whom the Software is furnished to do so, -* subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -*/ + * Copyright (C) 2024 - 2024: + * The Trinitrix Project + * SPDX-License-Identifier: MIT + * + * This file is part of Trinitrix. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the “Software”), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ #include "../../dist/interface.h" #include @@ -32,95 +32,116 @@ #include #include -#define println(args...) \ - fprintf(log_file, "\33[32;1m(plugin):\33[0m \33[34;1m"); \ - fprintf(log_file, args); \ - fprintf(log_file, "\n\33[0m"); \ - fflush(log_file); +#define println(args...) \ + fprintf (log_file, "\33[32;1m(plugin):\33[0m \33[34;1m"); \ + fprintf (log_file, args); \ + fprintf (log_file, "\n\33[0m"); \ + fflush (log_file); -#define eprintln(args...) \ - fprintf(log_file, "\33[32;1m(plugin):\33[0m\33[31;1m "); \ - fprintf(log_file, args); \ - fprintf(log_file, "\n\33[0m"); \ - fflush(log_file); +#define eprintln(args...) \ + fprintf (log_file, "\33[32;1m(plugin):\33[0m\33[31;1m "); \ + fprintf (log_file, args); \ + fprintf (log_file, "\n\33[0m"); \ + fflush (log_file); int is_first_log_file_open = 1; -FILE *get_log_file() { +FILE * +get_log_file () +{ FILE *log_file; - if (is_first_log_file_open) { - is_first_log_file_open = 0; - log_file = fopen("plugin.txt", "w"); - } else { - log_file = fopen("plugin.txt", "wa"); - } + if (is_first_log_file_open) + { + is_first_log_file_open = 0; + log_file = fopen ("plugin.txt", "w"); + } + else + { + log_file = fopen ("plugin.txt", "wa"); + } - if (log_file == NULL) { - printf("Error opening file!\n"); - exit(1); - } + if (log_file == NULL) + { + printf ("Error opening file!\n"); + exit (1); + } return log_file; } -void handle_error() { - FILE *log_file = get_log_file(); - eprintln("GOT an error"); +void +handle_error () +{ + FILE *log_file = get_log_file (); + eprintln ("GOT an error"); - int error_length = last_error_length(); - char *error = malloc(error_length); - last_error_message(error, error_length); - eprintln("Encountered error: %s", error); - free(error); + int error_length = last_error_length (); + char *error = malloc (error_length); + last_error_message (error, error_length); + eprintln ("Encountered error: %s", error); + free (error); } -void set_normal_mode() { - if (!trinitrix.api.ui.set_mode(Normal)) - handle_error(); +void +set_normal_mode () +{ + if (!trinitrix.api.ui.set_mode (Normal)) + handle_error (); } -void set_command_mode() { - if (!trinitrix.api.ui.set_mode(Command)) - handle_error(); +void +set_command_mode () +{ + if (!trinitrix.api.ui.set_mode (Command)) + handle_error (); } -void set_insert_mode() { - if (!trinitrix.api.ui.set_mode(Insert)) - handle_error(); +void +set_insert_mode () +{ + if (!trinitrix.api.ui.set_mode (Insert)) + handle_error (); } -void print_hi() { - if (!trinitrix.api.raw.raise_error("hi!")) - handle_error(); +void +print_hi () +{ + if (!trinitrix.api.raw.raise_error ("hi!")) + handle_error (); } -void print_warning() { - if (!trinitrix.api.raw.raise_error( +void +print_warning () +{ + if (!trinitrix.api.raw.raise_error ( "To exit trinitrix use 'trinitrix.api.exit()' instead!")) - handle_error(); + handle_error (); } -int plugin_main() { - FILE *log_file = get_log_file(); +int +plugin_main () +{ + FILE *log_file = get_log_file (); - println("Hi, setting first keymap!"); - if (!trinitrix.api.keymaps.add("ci", "", set_normal_mode)) - handle_error(); - println("Done setting that keymap"); + println ("Hi, setting first keymap!"); + if (!trinitrix.api.keymaps.add ("ci", "", set_normal_mode)) + handle_error (); + println ("Done setting that keymap"); - if (!trinitrix.api.keymaps.add("n", ":", set_command_mode)) - handle_error(); + if (!trinitrix.api.keymaps.add ("n", ":", set_command_mode)) + handle_error (); - trinitrix.api.keymaps.add("n", "i", set_insert_mode); - trinitrix.api.keymaps.add("n", "", trinitrix.api.ui.cycle_planes); + trinitrix.api.keymaps.add ("n", "i", set_insert_mode); + trinitrix.api.keymaps.add ("n", "", trinitrix.api.ui.cycle_planes); // a simple test to prove that key chords work - trinitrix.api.keymaps.add("ni", "jj", print_hi); + trinitrix.api.keymaps.add ("ni", "jj", print_hi); - trinitrix.api.keymaps.add("n", "q", trinitrix.api.exit); + trinitrix.api.keymaps.add ("n", "q", trinitrix.api.exit); // Help people - trinitrix.api.keymaps.add("n", "", print_warning); + trinitrix.api.keymaps.add ("n", "", print_warning); // workaround to avoid c de-allocating our nice strings - while (1) { - }; + while (1) + { + }; return EXIT_SUCCESS; } diff --git a/config/lua/init.lua b/config/lua/init.lua index aa938b0..79ba134 100644 --- a/config/lua/init.lua +++ b/config/lua/init.lua @@ -27,7 +27,7 @@ -- FIXME(@soispha): The code here has been deprecated, update it when trixy supports lua <2024-05-03> -- create the required tables under `std` -trinitrix.std = { keymaps = {} }; +trinitrix.std = { keymaps = {} } --- Add a new keymap. This is just a convenience function which registers the function --- and at the same time deals with the fact that the whole trinitrix api is async. @@ -35,17 +35,15 @@ trinitrix.std = { keymaps = {} }; ---@param key string ---@param callback function trinitrix.std.keymaps.add = function(mode, key, callback) - local callback_key = trinitrix.api.register_function(function() - local co = coroutine.create(callback) - while coroutine.status(co) ~= "dead" do - coroutine.resume(co) - end - end) - trinitrix.api.keymaps.add(mode, key, callback_key) + local callback_key = trinitrix.api.register_function(function() + local co = coroutine.create(callback) + while coroutine.status(co) ~= "dead" do + coroutine.resume(co) + end + end) + trinitrix.api.keymaps.add(mode, key, callback_key) end - - trinitrix.std.keymaps.add("ci", "", trinitrix.api.ui.set_mode_normal) trinitrix.std.keymaps.add("n", ":", trinitrix.api.ui.command_line_show) @@ -53,10 +51,13 @@ trinitrix.std.keymaps.add("n", "i", trinitrix.api.ui.set_mode_insert) trinitrix.std.keymaps.add("n", "", trinitrix.api.ui.cycle_planes) -- a simple test to prove that key chords work -trinitrix.std.keymaps.add("ni", "jj", function() print("hi") end) +trinitrix.std.keymaps.add("ni", "jj", function() + print("hi") +end) trinitrix.std.keymaps.add("n", "q", trinitrix.api.exit) - -- Help people -trinitrix.std.keymaps.add("n", "", function() print("To exit trinitrix use 'trinitrix.api.exit()' instead!") end) +trinitrix.std.keymaps.add("n", "", function() + print("To exit trinitrix use 'trinitrix.api.exit()' instead!") +end) diff --git a/docs/CommandLine.md b/docs/CommandLine.md index d4261d3..3bdd407 100644 --- a/docs/CommandLine.md +++ b/docs/CommandLine.md @@ -27,9 +27,11 @@ OTHER DEALINGS IN THE SOFTWARE. --> # Command Line + Trinitrix has a command line, which you can use to control and navigate the app. You can activate it with the `CommandLineShow` command, which is mapped to `+c` by default. ## Syntax (LUA) + The command line uses [lua](https://www.lua.org/about.html) and provides a builtin function for every internal command. -The function names are the snake case variants of the command names. \ No newline at end of file +The function names are the snake case variants of the command names. diff --git a/docs/Commands.md b/docs/Commands.md index 7b745ab..7848766 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -27,6 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE. --> # Commands + Trinitrix relies heavily on the concept of commands. There is a command for every interaction with the application. By this, everything can use the same internal API, what makes the whole application extreme extensible and customizable. diff --git a/docs/CommitMessageStyle.md b/docs/CommitMessageStyle.md index 1b5c60a..2c8e66b 100644 --- a/docs/CommitMessageStyle.md +++ b/docs/CommitMessageStyle.md @@ -27,6 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE. --> # Commit message style + *This specification is heavily inspired by the [AngularJS commit message format](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format).* We have very precise rules over how our Git commit messages must be formatted. @@ -34,7 +35,6 @@ This format leads to **easier to read commit history**. Each commit message consists of a **header**, a **body** (optional), and a **footer** (optional). - ```
@@ -50,7 +50,6 @@ When the body is present it must be at least 20 characters long and must conform The `footer` is optional. The _Commit Message Footer format_ (described below) describes what the footer is used for and the structure it must have. - ## Commit Message Header ``` @@ -65,29 +64,29 @@ The `footer` is optional. The _Commit Message Footer format_ (described below) d The `` and `` fields are mandatory, the `()` field is optional. - ### type Must be one of the following: -* **Build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) -* **Docs**: Documentation only changes -* **Feat**: A new feature -* **Fix**: A bug fix -* **Perf**: A code change that improves performance -* **Refactor**: A code change that neither fixes a bug nor adds a feature -* **Test**: Adding missing tests or correcting existing tests -* **Merge**: A merging commit +- **Build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) +- **Docs**: Documentation only changes +- **Feat**: A new feature +- **Fix**: A bug fix +- **Perf**: A code change that improves performance +- **Refactor**: A code change that neither fixes a bug nor adds a feature +- **Test**: Adding missing tests or correcting existing tests +- **Merge**: A merging commit ### Scope + The scope should be the name of the module affected (as perceived by the person reading the changelog generated from commit messages). Specify submodules if needed! Example scopes: -* `app::events` -* `ui` +- `app::events` +- `ui` When a commit affects the whole tree, use `treewide`. @@ -95,10 +94,9 @@ When a commit affects the whole tree, use `treewide`. Use the summary field to provide a succinct description of the change: -* use the imperative, present tense: "change" not "changed" nor "changes" -* don't capitalize the first letter -* no dot (.) at the end - +- use the imperative, present tense: "change" not "changed" nor "changes" +- don't capitalize the first letter +- no dot (.) at the end ## Commit Message Body diff --git a/docs/Config.md b/docs/Config.md index 0be8ffd..7accd9f 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -27,5 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE. --> # Config + To configure trinitrix, you can add a file named `config.lua` to the userdata path. -This file will be interpreted on startup with the same syntax as the Command Line. \ No newline at end of file +This file will be interpreted on startup with the same syntax as the Command Line. diff --git a/docs/Philosophy.md b/docs/Philosophy.md index 9a44f4a..c807a2a 100644 --- a/docs/Philosophy.md +++ b/docs/Philosophy.md @@ -29,16 +29,19 @@ OTHER DEALINGS IN THE SOFTWARE. # Design Philosophy ## Customizability + Trinitrix aims to be highly customizable. The command API provides a customizazion method, which can be used by an initial config script or live from the intern cli by the user. The command API should cover at least 90% of the possible configuration settings. ## Cross Platform + Trinitrix is cross platform. Even if the targeted users are nerdy linux users xD. This can be easily achieved by using only cross platform libraries such as `crossterm` or `tui`. ## Future Proof / Extensible + Modules and Interfaces should be designed in a way, that they're not limited to only use case. They should be open for every usecase, that makes sense. A good example is the command API, which is a unified way to interact with the application. diff --git a/docs/trinitrix.1.md b/docs/trinitrix.1.md index dfee02a..dedb1fb 100644 --- a/docs/trinitrix.1.md +++ b/docs/trinitrix.1.md @@ -50,9 +50,9 @@ Trinitrix is a multi protocol client. That is implemented via cbs and plugins. **--version**, **-v** : Displays the software version and exit. -**--plugin-path \**, **-p \** +**--plugin-path \**, **-p \** : The SHARED_OBJECT to load as a dynamic library. The `plugin_main` function will be - executed. +executed. # EXAMPLES diff --git a/flake.nix b/flake.nix index 23c5c2b..ac95dd7 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,6 @@ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. - { description = "A multi protocol chat client"; diff --git a/scripts/valgrind_test.sh b/scripts/valgrind_test.sh index 2d166bc..d8427bf 100755 --- a/scripts/valgrind_test.sh +++ b/scripts/valgrind_test.sh @@ -1,3 +1,4 @@ +#! /usr/bin/env sh # Copyright (C) 2024 - 2024: # The Trinitrix Project # SPDX-License-Identifier: MIT @@ -24,9 +25,8 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -#! /usr/bin/env sh cd "$(dirname "$0")" || { - echo "BUG: There is no parent dirname!"; + echo "BUG: There is no parent dirname!" exit 1 } cd .. diff --git a/src/app/events/handlers/main.rs b/src/app/events/handlers/main.rs index a4287a3..1259aa2 100644 --- a/src/app/events/handlers/main.rs +++ b/src/app/events/handlers/main.rs @@ -32,7 +32,7 @@ use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers} use crate::{ app::{ command_interface::{ - Api::{Exit, Ui, RoomMessageSend}, + Api::{Exit, RoomMessageSend, Ui}, Command, Trinitrix::Api, Ui::{CommandLineShow, CyclePlanes, CyclePlanesRev, SetModeInsert, SetModeNormal}, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index f634890..cc30d66 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -26,5 +26,5 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -pub mod ui_trait; pub mod repl; +pub mod ui_trait; diff --git a/src/ui/old/central/mod.rs b/src/ui/old/central/mod.rs index f6ad3d9..7e4dce6 100644 --- a/src/ui/old/central/mod.rs +++ b/src/ui/old/central/mod.rs @@ -178,8 +178,7 @@ pub struct UI<'a> { pub cli: Option>, } -impl<'r> TirinitrixUi for UI<'r> { -} +impl<'r> TirinitrixUi for UI<'r> {} impl Drop for UI<'_> { fn drop(&mut self) { diff --git a/src/ui/old/mod.rs b/src/ui/old/mod.rs index e68d2ca..180a419 100644 --- a/src/ui/old/mod.rs +++ b/src/ui/old/mod.rs @@ -27,7 +27,6 @@ */ pub mod central; -pub mod ui_trait; use std::{io, io::Stdout}; diff --git a/treefmt.nix b/treefmt.nix index e983f6c..5953690 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -23,7 +23,6 @@ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. - { treefmt-nix, pkgs, diff --git a/update.sh b/update.sh index a8c7983..ce95fe3 100755 --- a/update.sh +++ b/update.sh @@ -1,3 +1,4 @@ +#! /usr/bin/env sh # Copyright (C) 2024 - 2024: # The Trinitrix Project # SPDX-License-Identifier: MIT @@ -24,8 +25,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -#!/usr/bin/env sh - cargo update && cargo upgrade # vim: ft=sh