├── .gitignore ├── todo ├── fonts ├── inter.ttf └── inter-bold.ttf ├── icons ├── back.png ├── raise.png └── remove.png ├── appicon └── appicon.png ├── branding └── todo-showcase.png ├── todo.desktop ├── Makefile ├── config.h ├── README.md ├── setup.sh ├── LICENSE └── todo.c /.gitignore: -------------------------------------------------------------------------------- 1 | ./tododata.bin 2 | ./todo 3 | ./*.json 4 | -------------------------------------------------------------------------------- /todo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/todo -------------------------------------------------------------------------------- /fonts/inter.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/fonts/inter.ttf -------------------------------------------------------------------------------- /icons/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/icons/back.png -------------------------------------------------------------------------------- /icons/raise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/icons/raise.png -------------------------------------------------------------------------------- /icons/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/icons/remove.png -------------------------------------------------------------------------------- /appicon/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/appicon/appicon.png -------------------------------------------------------------------------------- /fonts/inter-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/fonts/inter-bold.ttf -------------------------------------------------------------------------------- /branding/todo-showcase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cococry/todo/HEAD/branding/todo-showcase.png -------------------------------------------------------------------------------- /todo.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | TryExec=todo 4 | Exec=todo 5 | Icon=/usr/share/icons/todo/appicon.png 6 | Terminal=false 7 | Categories=Utility;Office; 8 | 9 | Name=todo 10 | GenericName=Task Management 11 | Comment=A suckless task management program 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | BIN=todo 3 | SOURCE=*.c 4 | LIBS=-lglfw -lleif -lclipboard -lm -lGL -lxcb 5 | 6 | .PHONY: all clean install uninstall 7 | 8 | all: 9 | $(CC) -o $(BIN) $(SOURCE) $(LIBS) 10 | 11 | clean: 12 | rm -f $(BIN) 13 | 14 | install: 15 | cp $(BIN) /usr/bin/ 16 | cp ./todo.desktop /usr/share/applications 17 | @mkdir -p /usr/share/icons/todo 18 | cp ./appicon/appicon.png /usr/share/icons/todo 19 | @mkdir -p /usr/share/todo 20 | cp -r ./fonts/ /usr/share/todo/ 21 | cp -r ./icons/ /usr/share/todo/ 22 | 23 | uninstall: 24 | rm -f /usr/bin/todo 25 | rm -f /usr/share/applications/todo.desktop 26 | rm -f ~/.tododata 27 | rm -rf /usr/share/icons/todo/ 28 | rm -rf /usr/share/todo/ -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN_INIT_W 1280 4 | #define WIN_INIT_H 720 5 | 6 | #define BG_COLOR (LfColor){6, 6, 6, 255} 7 | 8 | 9 | #define FONT "/usr/share/todo/fonts/inter.ttf" 10 | #define FONT_BOLD "/usr/share/todo/fonts/inter-bold.ttf" 11 | 12 | #define TODO_DATA_DIR getenv("HOME") 13 | #define TODO_DATA_FILE ".tododata" 14 | 15 | #define BACK_ICON "/usr/share/todo/icons/back.png" 16 | #define REMOVE_ICON "/usr/share/todo/icons/remove.png" 17 | #define RAISE_ICON "/usr/share/todo/icons/raise.png" 18 | 19 | #define GLOBAL_MARGIN 25.0f 20 | 21 | #define INPUT_BUF_SIZE 512 22 | 23 | #define SECONDARY_COLOR (LfColor){65, 167, 204, 255} 24 | 25 | #define DA_INIT_CAP 64 26 | 27 | #define SMOOTH_SCROLL false 28 | 29 | #define DATE_CMD "date +\"%d.%m.%Y, %H:%M\"" 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # todo 2 | 3 | Todo Showcase 4 | 5 | ## Overview 6 | *todo* is a GUI task management utility that does one job, which is managing & storing your tasks. The app is written completly in C in under 1000 lines of code. 7 | 8 | It supports serialization & deserialization of tasks. Furthmore, the app implements a priority system for your tasks and the displayed tasks are sorted from high to low priority. 9 | There is also a filtering system that filters tasks after different critia (eg. completed, high priority,in progress). 10 | 11 | The application is designed with configuration in mind and editing the config.h file will let you configure everything very easily. The source code is also very extensible and it is easy to add or change features if you have some knowledge of C. 12 | 13 | ## UI 14 | 15 | The UI of the applicaton is written entirely with the [leif](https://github.com/cococry/leif) UI library which is a small immediate mode UI framework that i've written. The rendering is done with modern OpenGL by utilising a batch rendering system under the hood. As *todo* using any big UI framework like QT or GTK, it can be considered as very [suckless](https://suckless.org/philosophy). 16 | 17 | ## Terminal Interface 18 | 19 | todo can also be used in the terminal without any gui if you prefer that. There are subcommands for every action that can 20 | be done in the UI. For more information: 21 | 22 | ```console 23 | todo --help 24 | ``` 25 | 26 | ## Quick Start 27 | 28 | On Linux: 29 | ```console 30 | git clone https://github.com/cococry/todo 31 | cd todo 32 | ./setup.sh 33 | ``` 34 | 35 | On Windows: 36 | 37 | You would need to manually create a build script for leif and 38 | build a static library and then link that library with the todo app and compile the app. 39 | That would be a bit of a challange, but possible :) 40 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit immediately if a command exits with a non-zero status 4 | set -e 5 | 6 | # Change to the directory where the script is located 7 | cd "$(dirname "$0")" 8 | 9 | # Check if apt is available (for Debian-based distributions) 10 | if hash apt >/dev/null 2>&1; then 11 | # Install required packages 12 | sudo apt-get install -y pkg-config libglfw3 libglfw3-dev mesa-common-dev libglu1-mesa-dev libxcb1-dev 13 | sudo apt autoremove 14 | elif hash dnf >/dev/null 2>&1; then 15 | # Install required packages (for RHEL-based distributions) 16 | sudo dnf install -y pkgconfig-glfw3-devel mesa-libGL-devel mesa-libGLU-devel libX11-devel 17 | elif hash pacman >/dev/null 2>&1; then 18 | # Install required packages (for Arch-based distributions) 19 | sudo pacman -S --noconfirm pkgconf glfw-x11 mesa libglvnd 20 | else 21 | echo "Error: No supported package manager (apt, dnf, pacman) found. Cannot install required packages." 22 | exit 1 23 | fi 24 | 25 | # Clone, build, and install cglm 26 | git clone https://github.com/recp/cglm 27 | cd cglm 28 | mkdir build 29 | cd build 30 | cmake .. 31 | make 32 | sudo make install 33 | cd ../../ 34 | rm -rf cglm 35 | 36 | # Clone, build, and install libclipboard 37 | git clone https://github.com/jtanx/libclipboard 38 | cd libclipboard 39 | cmake . 40 | make -j4 41 | sudo make install 42 | cd .. 43 | rm -rf libclipboard 44 | 45 | # Clone, build, and install leif 46 | git clone https://github.com/cococry/leif 47 | cd leif 48 | make 49 | sudo make install 50 | cd .. 51 | rm -rf leif 52 | 53 | # Build the main project 54 | make 55 | sudo make install 56 | 57 | echo "=====================" 58 | echo "INSTALLATION FINISHED" 59 | echo "=====================" 60 | 61 | # Prompt the user to start the app 62 | read -p "Do you want to start the app (y/n): " answer 63 | 64 | # Convert the answer to lowercase to handle Y/y and N/n 65 | answer=${answer,,} 66 | 67 | # Check the user's response 68 | if [[ "$answer" == "y" ]]; then 69 | echo "Starting..." 70 | todo 71 | elif [[ "$answer" == "n" ]]; then 72 | echo "todo has been installed to your system." 73 | echo "It can be launched from the terminal with 'todo'." 74 | echo "A .desktop file is also installed so you can find it in your application launcher." 75 | echo "You can also use a terminal interface for todo:" 76 | todo --help 77 | else 78 | echo "Invalid input. Please enter y or n." 79 | fi 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /todo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "config.h" 11 | 12 | typedef enum { 13 | FILTER_ALL = 0, 14 | FILTER_IN_PROGRESS, 15 | FILTER_COMPLETED, 16 | FILTER_LOW, 17 | FILTER_MEDIUM, 18 | FILTER_HIGH 19 | } todo_filter; 20 | 21 | typedef enum { 22 | TAB_DASHBOARD = 0, 23 | TAB_NEW_TASK 24 | } tab; 25 | 26 | typedef enum { 27 | PRIORITY_LOW = 0, 28 | PRIORITY_MEDIUM, 29 | PRIORITY_HIGH, 30 | PRIORITY_COUNT 31 | } entry_priority; 32 | 33 | typedef struct { 34 | bool completed; 35 | char* desc, *date; 36 | 37 | entry_priority priority; 38 | } todo_entry; 39 | 40 | typedef struct { 41 | todo_entry** entries; 42 | uint32_t count, cap; 43 | } entries_da; 44 | 45 | typedef struct { 46 | GLFWwindow* win; 47 | int32_t winw, winh; 48 | 49 | todo_filter crnt_filter; 50 | tab crnt_tab; 51 | entries_da todo_entries; 52 | 53 | LfFont titlefont, smallfont; 54 | 55 | LfInputField new_task_input; 56 | char new_task_input_buf[INPUT_BUF_SIZE]; 57 | LfTexture backicon, removeicon, raiseicon; 58 | 59 | FILE* serialization_file; 60 | 61 | char tododata_file[128]; 62 | } state; 63 | 64 | static void resizecb(GLFWwindow* win, int32_t w, int32_t h); 65 | static void rendertopbar(); 66 | static void renderfilters(); 67 | static void renderentries(); 68 | 69 | static void initwin(); 70 | static void initui(); 71 | static void initentries(); 72 | static void terminate(); 73 | 74 | static void renderdashboard(); 75 | static void rendernewtask(); 76 | 77 | static void entries_da_init(entries_da* da); 78 | static void entries_da_resize(entries_da* da, int32_t new_cap); 79 | static void entries_da_push(entries_da* da, todo_entry* entry); 80 | static void entries_da_remove_i(entries_da* da, uint32_t i); 81 | static void entries_da_free(entries_da* da); 82 | 83 | static int compare_entry_priority(const void* a, const void* b); 84 | static void sort_entries_by_priority(entries_da* da); 85 | 86 | static char* get_command_output(const char* cmd); 87 | 88 | static void serialize_todo_entry(FILE* file, todo_entry* entry); 89 | static void serialize_todo_list(const char* filename, entries_da* da); 90 | static todo_entry* deserialize_todo_entry(FILE* file); 91 | static void deserialize_todo_list(const char* filename, entries_da* da); 92 | 93 | static void print_requires_argument(const char* option, uint32_t numargs); 94 | static void str_to_lower(char* str); 95 | 96 | static state s; 97 | 98 | void 99 | resizecb(GLFWwindow* win, int32_t w, int32_t h) { 100 | s.winw = w; 101 | s.winh = h; 102 | lf_resize_display(w, h); 103 | glViewport(0, 0, w, h); 104 | } 105 | 106 | void 107 | rendertopbar() { 108 | // Title 109 | lf_push_font(&s.titlefont); 110 | { 111 | LfUIElementProps props = lf_get_theme().text_props; 112 | lf_push_style_props(props); 113 | lf_text("Your To Do"); 114 | lf_pop_style_props(); 115 | } 116 | lf_pop_font(); 117 | 118 | // Button 119 | { 120 | const char* text = "New Task"; 121 | const float width = 150.0f; 122 | 123 | // UI Properties 124 | LfUIElementProps props = lf_get_theme().button_props; 125 | props.border_width = 0.0f; 126 | props.margin_top = 0.0f; 127 | props.color = SECONDARY_COLOR; 128 | props.corner_radius = 4.0f; 129 | lf_push_style_props(props); 130 | lf_set_ptr_x_absolute(s.winw - width - GLOBAL_MARGIN * 2.0f); 131 | 132 | // Button 133 | lf_set_line_should_overflow(false); 134 | if(lf_button_fixed("New Task", width, -1) == LF_CLICKED) { 135 | s.crnt_tab = TAB_NEW_TASK; 136 | } 137 | lf_set_line_should_overflow(true); 138 | 139 | lf_pop_style_props(); 140 | } 141 | } 142 | 143 | void 144 | renderfilters() { 145 | // Filters 146 | uint32_t itemcount = 6; 147 | static const char* items[] = { 148 | "ALL", "IN PROGRESS", "COMPLETED", "LOW", "MEDIUM", "HIGH" 149 | }; 150 | 151 | // UI Properties 152 | LfUIElementProps props = lf_get_theme().button_props; 153 | props.margin_left = 10.0f; 154 | props.margin_right = 10.0f; 155 | props.margin_top = 20.0f; 156 | props.padding = 10.0f; 157 | props.border_width = 0.0f; 158 | props.color = LF_NO_COLOR; 159 | props.corner_radius = 8.0f; 160 | props.text_color = LF_WHITE; 161 | 162 | lf_push_font(&s.smallfont); 163 | 164 | // Calculating width 165 | float width = 0.0f; 166 | { 167 | float ptrx_before = lf_get_ptr_x(); 168 | lf_push_style_props(props); 169 | lf_set_cull_end_x(s.winw); 170 | lf_set_cull_end_y(s.winh); 171 | lf_set_no_render(true); 172 | for(uint32_t i = 0; i < itemcount; i++) { 173 | lf_button(items[i]); 174 | } 175 | lf_unset_cull_end_x(); 176 | lf_unset_cull_end_y(); 177 | lf_set_no_render(false); 178 | width = lf_get_ptr_x() - ptrx_before - props.margin_right - props.padding; 179 | } 180 | 181 | lf_set_ptr_x_absolute(s.winw - width - GLOBAL_MARGIN); 182 | 183 | // Rendering the filter items 184 | lf_set_line_should_overflow(false); 185 | for(uint32_t i = 0; i < itemcount; i++) { 186 | // If the filter is currently selected, render a 187 | // box around it to indicate selection. 188 | if(s.crnt_filter == (uint32_t)i) { 189 | props.color = (LfColor){255, 255, 255, 50}; 190 | } else { 191 | props.color = LF_NO_COLOR; 192 | } 193 | // Rendering the button 194 | lf_push_style_props(props); 195 | if(lf_button(items[i]) == LF_CLICKED) { 196 | s.crnt_filter = i; 197 | } 198 | lf_pop_style_props(); 199 | } 200 | // Popping props 201 | lf_set_line_should_overflow(true); 202 | lf_pop_style_props(); 203 | lf_pop_font(); 204 | } 205 | 206 | void 207 | renderentries() { 208 | lf_div_begin(((vec2s){lf_get_ptr_x(), lf_get_ptr_y()}), 209 | ((vec2s){(s.winw - lf_get_ptr_x()) - GLOBAL_MARGIN, (s.winh - lf_get_ptr_y()) - GLOBAL_MARGIN}), 210 | true); 211 | 212 | uint32_t renderedcount = 0; 213 | for(uint32_t i = 0; i < s.todo_entries.count; i++) { 214 | todo_entry* entry = s.todo_entries.entries[i]; 215 | // Filtering the entries 216 | if(s.crnt_filter == FILTER_COMPLETED && !entry->completed) continue; 217 | if(s.crnt_filter == FILTER_IN_PROGRESS && entry->completed) continue; 218 | if(s.crnt_filter == FILTER_LOW && entry->priority != PRIORITY_LOW) continue; 219 | if(s.crnt_filter == FILTER_MEDIUM && entry->priority != PRIORITY_MEDIUM) continue; 220 | if(s.crnt_filter == FILTER_HIGH && entry->priority != PRIORITY_HIGH) continue; 221 | 222 | { 223 | float ptry_before = lf_get_ptr_y(); 224 | float priority_size = 15.0f; 225 | lf_set_ptr_y_absolute(lf_get_ptr_y() + priority_size); 226 | lf_set_ptr_x_absolute(lf_get_ptr_x() + 5.0f); 227 | bool clicked_priority = lf_hovered((vec2s){lf_get_ptr_x(), lf_get_ptr_y()}, (vec2s){priority_size, priority_size}) && 228 | lf_mouse_button_went_down(GLFW_MOUSE_BUTTON_LEFT); 229 | if(clicked_priority) { 230 | if(entry->priority + 1 >= PRIORITY_COUNT) { 231 | entry->priority = 0; 232 | } else { 233 | entry->priority++; 234 | } 235 | sort_entries_by_priority(&s.todo_entries); 236 | } 237 | switch (entry->priority) { 238 | case PRIORITY_LOW: { 239 | lf_rect(priority_size, priority_size, (LfColor){76, 175, 80, 255}, 4.0f); 240 | break; 241 | } 242 | case PRIORITY_MEDIUM: { 243 | lf_rect(priority_size, priority_size, (LfColor){255, 235, 59, 255}, 4.0f); 244 | break; 245 | } 246 | case PRIORITY_HIGH: { 247 | lf_rect(priority_size, priority_size, (LfColor){244, 67, 54, 255}, 4.0f); 248 | break; 249 | } 250 | default: 251 | break; 252 | } 253 | lf_set_ptr_y_absolute(ptry_before); 254 | } 255 | { 256 | LfUIElementProps props = lf_get_theme().button_props; 257 | props.color = LF_NO_COLOR; 258 | props.border_width = 0.0f; props.padding = 0.0f; props.margin_top = 13; props.margin_left = 10.0f; 259 | lf_push_style_props(props); 260 | if(lf_image_button(((LfTexture){.id = s.removeicon.id, .width = 20, .height = 20})) == LF_CLICKED) { 261 | entries_da_remove_i(&s.todo_entries, i); 262 | serialize_todo_list(s.tododata_file, &s.todo_entries); 263 | } 264 | lf_pop_style_props(); 265 | } 266 | { 267 | LfUIElementProps props = lf_get_theme().checkbox_props; 268 | props.border_width = 1.0f; props.corner_radius = 0; props.margin_top = 11; props.padding = 5.0f; 269 | props.color = BG_COLOR; 270 | lf_push_style_props(props); 271 | if(lf_checkbox("", &entry->completed, LF_NO_COLOR, SECONDARY_COLOR) == LF_CLICKED) { 272 | serialize_todo_list(s.tododata_file, &s.todo_entries); 273 | } 274 | lf_pop_style_props(); 275 | } 276 | 277 | float textptrx = lf_get_ptr_x(); 278 | lf_text(entry->desc); 279 | 280 | lf_set_ptr_x_absolute(textptrx); 281 | lf_set_ptr_y_absolute(lf_get_ptr_y() + lf_get_theme().font.font_size); 282 | { 283 | LfUIElementProps props = lf_get_theme().text_props; 284 | props.margin_top = 2.5f; 285 | props.text_color = (LfColor){150, 150, 150, 255}; 286 | lf_push_style_props(props); 287 | lf_push_font(&s.smallfont); 288 | lf_text(entry->date); 289 | lf_pop_font(); 290 | lf_pop_style_props(); 291 | } 292 | 293 | { 294 | uint32_t texw = 15, texh = 8; 295 | lf_set_ptr_x_absolute(s.winw - GLOBAL_MARGIN - texw); 296 | lf_set_line_should_overflow(false); 297 | 298 | LfUIElementProps props = lf_get_theme().button_props; 299 | props.color = LF_NO_COLOR; 300 | props.border_width = 0.0f; props.padding = 0.0f; props.margin_left = 0.0f; props.margin_right = 0.0f; 301 | lf_push_style_props(props); 302 | lf_set_image_color((LfColor){120, 120, 120, 255}); 303 | if(lf_image_button(((LfTexture){.id = s.raiseicon.id, .width = texw, .height = texh})) == LF_CLICKED) { 304 | todo_entry* tmp = s.todo_entries.entries[0]; 305 | s.todo_entries.entries[0] = entry; 306 | s.todo_entries.entries[i] = tmp; 307 | serialize_todo_list(s.tododata_file, &s.todo_entries); 308 | } 309 | lf_unset_image_color(); 310 | lf_set_line_should_overflow(true); 311 | lf_pop_style_props(); 312 | } 313 | 314 | lf_next_line(); 315 | renderedcount++; 316 | } 317 | if(!renderedcount) { 318 | lf_text("There is nothing here."); 319 | } 320 | 321 | lf_div_end(); 322 | } 323 | 324 | void 325 | initwin() { 326 | // Initialize GLFW 327 | glfwInit(); 328 | 329 | // Setting base window width 330 | s.winw = WIN_INIT_W; 331 | s.winh = WIN_INIT_H; 332 | 333 | // Creating & initializing window and UI library 334 | s.win = glfwCreateWindow(s.winw, s.winh, "todo", NULL, NULL); 335 | glfwMakeContextCurrent(s.win); 336 | glfwSetFramebufferSizeCallback(s.win, resizecb); 337 | lf_init_glfw(s.winw, s.winh, s.win); 338 | } 339 | 340 | void 341 | initui() { 342 | // Initializing fonts 343 | s.titlefont = lf_load_font(FONT_BOLD, 40); 344 | s.smallfont = lf_load_font(FONT, 20); 345 | 346 | s.crnt_filter = FILTER_ALL; 347 | 348 | // Initializing base theme 349 | LfTheme theme = lf_get_theme(); 350 | theme.div_props.color = LF_NO_COLOR; 351 | lf_free_font(&theme.font); 352 | theme.font = lf_load_font(FONT, 24); 353 | theme.scrollbar_props.corner_radius = 2; 354 | theme.scrollbar_props.color = lf_color_brightness(BG_COLOR, 3.0); 355 | theme.div_smooth_scroll = SMOOTH_SCROLL; 356 | lf_set_theme(theme); 357 | 358 | // Initializing retained state 359 | memset(s.new_task_input_buf, 0, INPUT_BUF_SIZE); 360 | s.new_task_input = (LfInputField){ 361 | .width = 400, 362 | .buf = s.new_task_input_buf, 363 | .buf_size = INPUT_BUF_SIZE, 364 | .placeholder = (char*)"What is there to do?" 365 | }; 366 | 367 | s.backicon = lf_load_texture(BACK_ICON, true, LF_TEX_FILTER_LINEAR); 368 | s.removeicon = lf_load_texture(REMOVE_ICON, true, LF_TEX_FILTER_LINEAR); 369 | s.raiseicon = lf_load_texture(RAISE_ICON, true, LF_TEX_FILTER_LINEAR); 370 | initentries(); 371 | } 372 | 373 | void 374 | initentries() { 375 | strcat(s.tododata_file, TODO_DATA_DIR); 376 | strcat(s.tododata_file, "/"); 377 | strcat(s.tododata_file, TODO_DATA_FILE); 378 | 379 | entries_da_init(&s.todo_entries); 380 | deserialize_todo_list(s.tododata_file, &s.todo_entries); 381 | } 382 | 383 | void 384 | terminate() { 385 | // Terminate UI library 386 | lf_terminate(); 387 | 388 | // Freeing allocated resources 389 | lf_free_font(&s.smallfont); 390 | lf_free_font(&s.titlefont); 391 | entries_da_free(&s.todo_entries); 392 | 393 | // Terminate Windowing 394 | glfwDestroyWindow(s.win); 395 | glfwTerminate(); 396 | } 397 | void 398 | renderdashboard() { 399 | rendertopbar(); 400 | lf_next_line(); 401 | renderfilters(); 402 | lf_next_line(); 403 | renderentries(); 404 | } 405 | 406 | void 407 | rendernewtask() { 408 | // Title 409 | lf_push_font(&s.titlefont); 410 | { 411 | LfUIElementProps props = lf_get_theme().text_props; 412 | props.margin_bottom = 15.0f; 413 | lf_push_style_props(props); 414 | lf_text("Add a new Task"); 415 | lf_pop_style_props(); 416 | lf_pop_font(); 417 | } 418 | 419 | lf_next_line(); 420 | 421 | // Description input field 422 | { 423 | lf_push_font(&s.smallfont); 424 | lf_text("Description"); 425 | lf_pop_font(); 426 | 427 | lf_next_line(); 428 | LfUIElementProps props = lf_get_theme().inputfield_props; 429 | props.padding = 15; 430 | props.border_width = 0; 431 | props.color = BG_COLOR; 432 | props.corner_radius = 11; 433 | props.text_color = LF_WHITE; 434 | props.border_width = 1.0f; 435 | props.border_color = s.new_task_input.selected ? LF_WHITE : (LfColor){170, 170, 170, 255}; 436 | props.corner_radius = 2.5f; 437 | props.margin_bottom = 10.0f; 438 | lf_push_style_props(props); 439 | lf_input_text(&s.new_task_input); 440 | lf_pop_style_props(); 441 | } 442 | 443 | lf_next_line(); 444 | 445 | lf_next_line(); 446 | 447 | // Priority dropdown 448 | static int32_t selected_priority = -1; 449 | { 450 | lf_push_font(&s.smallfont); 451 | lf_text("Priority"); 452 | lf_pop_font(); 453 | 454 | lf_next_line(); 455 | static const char* items[3] = { 456 | "Low", 457 | "Medium", 458 | "High" 459 | }; 460 | static bool opened = false; 461 | LfUIElementProps props = lf_get_theme().button_props; 462 | props.color = (LfColor){70, 70, 70, 255}; 463 | props.text_color = LF_WHITE; 464 | props.border_width = 0.0f; 465 | props.corner_radius = 5.0f; 466 | lf_push_style_props(props); 467 | lf_dropdown_menu(items, "Priority", 3, 200, 80, &selected_priority, &opened); 468 | lf_pop_style_props(); 469 | } 470 | 471 | // Add Button 472 | { 473 | bool form_complete = (strlen(s.new_task_input_buf) && selected_priority != -1); 474 | const char* text = "Add"; 475 | const float width = 150.0f; 476 | 477 | LfUIElementProps props = lf_get_theme().button_props; 478 | props.margin_left = 0.0f; 479 | props.margin_right = 0.0f; 480 | props.corner_radius = 5.0f; 481 | props.border_width = 0.0f; 482 | props.color = !form_complete ? (LfColor){80, 80, 80, 255} : SECONDARY_COLOR; 483 | lf_push_style_props(props); 484 | lf_set_line_should_overflow(false); 485 | lf_set_ptr_x_absolute(s.winw - (width + lf_get_theme().button_props.padding * 2.0f) - GLOBAL_MARGIN); 486 | lf_set_ptr_y_absolute(s.winh - (lf_button_dimension(text).y + lf_get_theme().button_props.padding * 2.0f) - GLOBAL_MARGIN); 487 | 488 | // If the user wants to add a new task: 489 | if((lf_button_fixed(text, width, -1) == LF_CLICKED && form_complete) || 490 | (lf_key_went_down(GLFW_KEY_ENTER) && form_complete)) { 491 | 492 | // Copy the description input buffers content to a new pointer 493 | char* desc = malloc(strlen(s.new_task_input_buf)); 494 | strcpy(desc, s.new_task_input_buf); 495 | 496 | // Allocate a new entry 497 | todo_entry* entry = malloc(sizeof(todo_entry)); 498 | entry->desc = desc; 499 | entry->date = get_command_output(DATE_CMD); 500 | entry->completed = false; 501 | entry->priority = (entry_priority)selected_priority; 502 | entries_da_push(&s.todo_entries, entry); 503 | sort_entries_by_priority(&s.todo_entries); 504 | 505 | // Serialize entries 506 | serialize_todo_list(s.tododata_file, &s.todo_entries); 507 | 508 | // Reset interface state 509 | memset(s.new_task_input_buf, 0, sizeof(s.new_task_input_buf)); 510 | s.new_task_input.cursor_index = 0; 511 | lf_input_field_unselect_all(&s.new_task_input); 512 | } 513 | lf_set_line_should_overflow(true); 514 | lf_pop_style_props(); 515 | } 516 | 517 | // Back Icon button 518 | lf_next_line(); 519 | { 520 | LfUIElementProps props = lf_get_theme().button_props; 521 | props.color = LF_NO_COLOR; 522 | props.border_width = 0.0f; 523 | props.padding = 0.0f; 524 | props.margin_left = 0.0f; 525 | props.margin_right = 0.0f; 526 | props.margin_top = 0.0f; 527 | props.margin_bottom = 0.0f; 528 | lf_push_style_props(props); 529 | lf_set_line_should_overflow(false); 530 | LfTexture backbutton = (LfTexture){.id = s.backicon.id, .width = 20, .height = 40}; 531 | lf_set_ptr_y_absolute(s.winh - backbutton.height - GLOBAL_MARGIN * 2.0f); 532 | lf_set_ptr_x_absolute(GLOBAL_MARGIN); 533 | 534 | if(lf_image_button(backbutton) == LF_CLICKED) { 535 | s.crnt_tab = TAB_DASHBOARD; 536 | } 537 | lf_set_line_should_overflow(true); 538 | lf_pop_style_props(); 539 | } 540 | } 541 | void 542 | entries_da_init(entries_da* da) { 543 | da->cap = DA_INIT_CAP; 544 | da->count = 0; 545 | da->entries = (todo_entry**)malloc(sizeof(todo_entry) * da->cap); 546 | } 547 | 548 | void 549 | entries_da_push(entries_da* da, todo_entry* entry) { 550 | if(da->count == da->cap) { 551 | entries_da_resize(da, da->cap * 2); 552 | } 553 | da->entries[da->count++] = entry; 554 | } 555 | 556 | void 557 | entries_da_resize(entries_da* da, int32_t new_cap) { 558 | todo_entry** temp = (todo_entry**)realloc(da->entries, new_cap * sizeof(todo_entry)); 559 | if (!temp) { 560 | fprintf(stderr, "Failed to reallocate memory\n"); 561 | exit(EXIT_FAILURE); 562 | } 563 | da->entries = temp; 564 | da->cap = new_cap; 565 | } 566 | 567 | void 568 | entries_da_remove_i(entries_da* da, uint32_t i) { 569 | // Bounds check 570 | if (i < 0 || i >= da->count) { 571 | printf("Index out of bounds\n"); 572 | return; 573 | } 574 | 575 | // Remove element 576 | for (uint32_t idx = i; idx < da->count - 1; idx++) { 577 | da->entries[idx] = da->entries[idx + 1]; 578 | } 579 | 580 | // Decrease the count 581 | da->count--; 582 | } 583 | 584 | void entries_da_free(entries_da* da) { 585 | if(da->entries) 586 | free(da->entries); 587 | da->cap = 0; 588 | da->count = 0; 589 | } 590 | 591 | int 592 | compare_entry_priority(const void* a, const void* b) { 593 | todo_entry* entry_a = *(todo_entry**)a; 594 | todo_entry* entry_b = *(todo_entry**)b; 595 | return (entry_b->priority - entry_a->priority); 596 | } 597 | 598 | void 599 | sort_entries_by_priority(entries_da* da) { 600 | qsort(da->entries, da->count, sizeof(todo_entry*), compare_entry_priority); 601 | } 602 | 603 | char* 604 | get_command_output(const char* cmd) { 605 | FILE *fp; 606 | char buffer[1024]; 607 | char *result = NULL; 608 | size_t result_size = 0; 609 | 610 | // Opening a new pipe with the fiven command 611 | fp = popen(cmd, "r"); 612 | if (fp == NULL) { 613 | printf("Failed to run command\n"); 614 | return NULL; 615 | } 616 | 617 | // Reading the output 618 | while (fgets(buffer, sizeof(buffer), fp) != NULL) { 619 | size_t buffer_len = strlen(buffer); 620 | char *temp = realloc(result, result_size + buffer_len + 1); 621 | if (temp == NULL) { 622 | printf("Memory allocation failed\n"); 623 | free(result); 624 | pclose(fp); 625 | return NULL; 626 | } 627 | result = temp; 628 | strcpy(result + result_size, buffer); 629 | result_size += buffer_len; 630 | } 631 | pclose(fp); 632 | return result; 633 | } 634 | 635 | void 636 | serialize_todo_entry(FILE* file, todo_entry* entry) { 637 | // Write completed to file 638 | fwrite(&entry->completed, sizeof(bool), 1, file); 639 | 640 | // Write description to file 641 | size_t desc_len = strlen(entry->desc) + 1; // +1 for null terminator 642 | // Writing the description length to the file for later 643 | // deserialization 644 | fwrite(&desc_len, sizeof(size_t), 1, file); 645 | fwrite(entry->desc, sizeof(char), desc_len, file); 646 | 647 | // Write date to file 648 | size_t date_len = strlen(entry->date) + 1; // +1 for null terminator 649 | // Writing the date length to the file for later 650 | // deserialization 651 | fwrite(&date_len, sizeof(size_t), 1, file); 652 | fwrite(entry->date, sizeof(char), date_len, file); 653 | 654 | // Write priority to file 655 | fwrite(&entry->priority, sizeof(entry_priority), 1, file); 656 | } 657 | 658 | void 659 | serialize_todo_list(const char* filename, entries_da* da) { 660 | FILE* file = fopen(filename, "wb"); 661 | if(!file) { 662 | printf("Failed to open data file.\n"); 663 | return; 664 | } 665 | for(uint32_t i = 0; i < da->count; i++) { 666 | serialize_todo_entry(file, da->entries[i]); 667 | } 668 | fclose(file); 669 | } 670 | 671 | todo_entry* 672 | deserialize_todo_entry(FILE* file) { 673 | // Allocate entry 674 | todo_entry *entry = malloc(sizeof(todo_entry)); 675 | 676 | // Read if entry is completed 677 | if (fread(&entry->completed, sizeof(bool), 1, file) != 1) { 678 | free(entry); 679 | return NULL; 680 | } 681 | 682 | // Read the length of the description 683 | size_t desc_len; 684 | if (fread(&desc_len, sizeof(size_t), 1, file) != 1) { 685 | free(entry); 686 | return NULL; 687 | } 688 | 689 | // Allocating space to store the entries description 690 | entry->desc = malloc(desc_len); 691 | if (!entry->desc) { 692 | free(entry); 693 | return NULL; 694 | } 695 | // Read the description from the file 696 | if (fread(entry->desc, sizeof(char), desc_len, file) != desc_len) { 697 | free(entry->desc); 698 | free(entry); 699 | return NULL; 700 | } 701 | 702 | // Read the date length from the file 703 | size_t date_len; 704 | if (fread(&date_len, sizeof(size_t), 1, file) != 1) { 705 | free(entry->desc); 706 | free(entry); 707 | return NULL; 708 | } 709 | // Allocating space for the date 710 | entry->date = malloc(date_len); 711 | if (!entry->date) { 712 | free(entry->desc); 713 | free(entry); 714 | return NULL; 715 | } 716 | // Reading the date string 717 | if (fread(entry->date, sizeof(char), date_len, file) != date_len) { 718 | free(entry->desc); 719 | free(entry->date); 720 | free(entry); 721 | return NULL; 722 | } 723 | 724 | // Reading the entires priority 725 | if (fread(&entry->priority, sizeof(entry_priority), 1, file) != 1) { 726 | free(entry->desc); 727 | free(entry->date); 728 | free(entry); 729 | return NULL; 730 | } 731 | 732 | return entry; 733 | } 734 | void deserialize_todo_list(const char* filename, entries_da* da) { 735 | FILE *file = fopen(filename, "rb"); 736 | if(!file) { 737 | // If file does not exist, create it 738 | file = fopen(filename, "w"); 739 | fclose(file); 740 | } 741 | file = fopen(filename, "rb"); 742 | todo_entry *entry; 743 | while ((entry = deserialize_todo_entry(file)) != NULL) { 744 | entries_da_push(da, entry); 745 | } 746 | fclose(file); 747 | } 748 | 749 | void print_requires_argument(const char* option, uint32_t numargs) { 750 | printf("todo: option requires %i argument(s): '%s'\n", numargs, option); 751 | printf("Try todo --help for more information\n"); 752 | } 753 | 754 | void str_to_lower(char* str) { 755 | while(*str) { 756 | *str = tolower((unsigned char)*str); 757 | str++; 758 | } 759 | } 760 | 761 | int 762 | main(int argc, char** argv) { 763 | // Handle terminal interface 764 | if(argc > 1) { 765 | initentries(); 766 | char* subcmd = argv[1]; 767 | str_to_lower(subcmd); 768 | if(strcmp(subcmd, "--help") == 0 || strcmp(subcmd, "-h") == 0) { 769 | printf("Usage: todo [OPTION...] [ARGUMENTS...]\n"); 770 | printf("\t-h, --help Open help menu\n"); 771 | printf("\t-l, --list Display todo list\n"); 772 | printf("\t-a, --add \"[desc]\" [priority] Add a new task to the todo list\n"); 773 | printf("\t-r, --remove [idx] Remove a task with a given index from the list.\n"); 774 | printf("\t-d, --done [idx] Mark a task with a given index as completed.\n"); 775 | printf("\t-n, --not-done [idx] Mark a task with a given index as not completed.\n"); 776 | printf("\t-r, --raise [idx] Raises a task with a given index to the top.\n"); 777 | } 778 | else if(strcmp(subcmd, "--list") == 0 || strcmp(subcmd, "-l") == 0) { 779 | printf("======== Your To Do ========\n"); 780 | char* priorities_str[] = { 781 | "L", "M", "H" 782 | }; 783 | sort_entries_by_priority(&s.todo_entries); 784 | for(uint32_t i = 0; i < s.todo_entries.count; i++) { 785 | todo_entry* entry = s.todo_entries.entries[i]; 786 | printf("%i | (%s) [%c]: %s\n", i, priorities_str[entry->priority], entry->completed ? 'x' : ' ', entry->desc); 787 | } 788 | if(!s.todo_entries.count) { 789 | printf("There is nothing here.\n"); 790 | } 791 | printf("============================\n"); 792 | } 793 | else if(strcmp(subcmd, "--add") == 0 || strcmp(subcmd, "-a") == 0) { 794 | if(argc < 4) { 795 | print_requires_argument(argv[1], 2); 796 | return EXIT_FAILURE; 797 | } 798 | char* desc = argv[2]; 799 | char* priority_str = argv[3]; 800 | 801 | str_to_lower(priority_str); 802 | 803 | entry_priority priority; 804 | if(strcmp(priority_str, "low") == 0) 805 | priority = PRIORITY_LOW; 806 | else if(strcmp(priority_str, "medium") == 0) 807 | priority = PRIORITY_MEDIUM; 808 | else if(strcmp(priority_str, "high") == 0) 809 | priority = PRIORITY_HIGH; 810 | else { 811 | printf("todo: invalid priority given: '%s' (valid priorities: {low, medium, high})\n", priority_str); 812 | return EXIT_FAILURE; 813 | } 814 | todo_entry* entry = (todo_entry*)malloc(sizeof(todo_entry)); 815 | entry->priority = priority; 816 | entry->desc = desc; 817 | entry->completed = false; 818 | entry->date = get_command_output(DATE_CMD); 819 | 820 | entries_da_push(&s.todo_entries, entry); 821 | serialize_todo_list(s.tododata_file, &s.todo_entries); 822 | 823 | printf("todo: added new entry to do list.\n"); 824 | 825 | free(entry); 826 | entry = NULL; 827 | } 828 | else if(strcmp(subcmd, "--remove") == 0 || strcmp(subcmd, "-r") == 0) { 829 | if(argc < 3) { 830 | print_requires_argument(argv[1], 1); 831 | return EXIT_FAILURE; 832 | } 833 | int32_t idx = atoi(argv[2]); 834 | if(idx < 0 || idx >= s.todo_entries.count) { 835 | printf("todo: index for removal out of bounds.\n"); 836 | return EXIT_FAILURE; 837 | } 838 | char* entry_desc = malloc(strlen(s.todo_entries.entries[idx]->desc)); 839 | strcpy(entry_desc, s.todo_entries.entries[idx]->desc); 840 | 841 | entries_da_remove_i(&s.todo_entries, idx); 842 | serialize_todo_list(s.tododata_file, &s.todo_entries); 843 | 844 | printf("todo: removed item %i ('%s') from list.\n", idx, entry_desc); 845 | 846 | free(entry_desc); 847 | entry_desc = NULL; 848 | } 849 | else if(strcmp(subcmd, "--done") == 0 || strcmp(subcmd, "-d") == 0) { 850 | if(argc < 3) { 851 | print_requires_argument(argv[1], 1); 852 | return EXIT_FAILURE; 853 | } 854 | int32_t idx = atoi(argv[2]); 855 | if(idx < 0 || idx >= s.todo_entries.count) { 856 | printf("todo: index for marking as done out of bounds.\n"); 857 | return EXIT_FAILURE; 858 | } 859 | 860 | todo_entry* entry = s.todo_entries.entries[idx]; 861 | entry->completed = true; 862 | serialize_todo_list(s.tododata_file, &s.todo_entries); 863 | 864 | printf("todo: marked item %i ('%s') as done.\n", idx, entry->desc); 865 | } 866 | else if(strcmp(subcmd, "--not-done") == 0 || strcmp(subcmd, "-n") == 0) { 867 | if(argc < 3) { 868 | print_requires_argument(argv[1], 1); 869 | return EXIT_FAILURE; 870 | } 871 | int32_t idx = atoi(argv[2]); 872 | if(idx < 0 || idx >= s.todo_entries.count) { 873 | printf("todo: index for marking as not done out of bounds.\n"); 874 | return EXIT_FAILURE; 875 | } 876 | 877 | todo_entry* entry = s.todo_entries.entries[idx]; 878 | entry->completed = false; 879 | serialize_todo_list(s.tododata_file, &s.todo_entries); 880 | 881 | printf("todo: marked item %i ('%s') as not done.\n", idx, entry->desc); 882 | } 883 | else if(strcmp(subcmd, "--raise") == 0 || strcmp(subcmd, "-r") == 0) { 884 | if(argc < 3) { 885 | print_requires_argument(argv[1], 1); 886 | return EXIT_FAILURE; 887 | } 888 | int32_t idx = atoi(argv[2]); 889 | if(idx < 0 || idx >= s.todo_entries.count) { 890 | printf("todo: index for raising out of bounds.\n"); 891 | return EXIT_FAILURE; 892 | } 893 | 894 | todo_entry* tmp = s.todo_entries.entries[0]; 895 | s.todo_entries.entries[0] = s.todo_entries.entries[idx]; 896 | s.todo_entries.entries[idx] = tmp; 897 | 898 | serialize_todo_list(s.tododata_file, &s.todo_entries); 899 | 900 | printf("todo: raised item %i ('%s') to the top.\n", idx, s.todo_entries.entries[0]->desc); 901 | } 902 | else { 903 | printf("todo: invalid option: '%s'.\n", argv[1]); 904 | printf("Try todo --help for more information.\n"); 905 | return EXIT_FAILURE; 906 | } 907 | return EXIT_SUCCESS; 908 | } 909 | 910 | initwin(); 911 | initui(); 912 | 913 | vec4s bgcol = lf_color_to_zto(BG_COLOR); 914 | while(!glfwWindowShouldClose(s.win)) { 915 | glClear(GL_COLOR_BUFFER_BIT); 916 | glClearColor(bgcol.r, bgcol.g, bgcol.b, bgcol.a); 917 | 918 | lf_begin(); 919 | 920 | // Beginning the root div 921 | lf_div_begin(((vec2s){GLOBAL_MARGIN, GLOBAL_MARGIN}), ((vec2s){s.winw - GLOBAL_MARGIN * 2.0f, s.winh - GLOBAL_MARGIN * 2.0f}), true); 922 | 923 | switch (s.crnt_tab) { 924 | case TAB_DASHBOARD: 925 | renderdashboard(); 926 | break; 927 | case TAB_NEW_TASK: 928 | rendernewtask(); 929 | break; 930 | } 931 | 932 | // Ending the root div 933 | lf_div_end(); 934 | lf_end(); 935 | 936 | glfwPollEvents(); 937 | glfwSwapBuffers(s.win); 938 | } 939 | terminate(); 940 | return EXIT_SUCCESS; 941 | } 942 | --------------------------------------------------------------------------------