From a26b808d2851361f7153524781cee4c2a3d99a4b Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 Jan 2020 10:30:07 +0100 Subject: [PATCH 1/5] Fixed spelling mistakes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd99476..ef7d6d9 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,10 @@ show_menu(sizeof(items) / sizeof(struct MenuItem), items, "Vorlesungsaufgaben", * 6. Argument: Style des Menüs: Standardmäßig wird DEFAULT, MODERN, SOLID und NO_BORDER unterstützt */ ```` -### Style hinzufügen -Eigene Styles können wie folgt hinzugefügt werden: +### Border hinzufügen +Eigene Border-Styles können wie folgt hinzugefügt werden: ```C -const struct MenuBoder NAME = { +const struct MenuBorder NAME = { 'a', // Char für den rechten und linken Rand 'b', // Char für den oberen und unteren Rand 'c', // Char für die linke obere Ecke @@ -59,4 +59,4 @@ const struct MenuBoder NAME = { } ``` -Neue Styles am Besten direkt unter den #include Anweisungen einfügen. Der neue Style kann über den angegebenen Namen verwendet werden. +Neue Border am Besten direkt unter den ```#include``` Anweisungen einfügen. Die neue Border kann über den angegebenen Namen, wie im obigen Beispiel erläutert, verwendet werden. From 1e81f1b9c28a39425f34b55db7536ce81357d737 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 Jan 2020 14:43:11 +0100 Subject: [PATCH 2/5] Update README.md --- README.md | 57 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ef7d6d9..f583870 100644 --- a/README.md +++ b/README.md @@ -21,29 +21,50 @@ Headerdatei einbinden: ### Anwendungsbeispiel ```C struct MenuItem items[] = { - {"Euklidscher Algorithmus", '1', (void*)&euklid}, // String = Name des Menüpunktes - {"Gerstenkorn", '2', (void*)&gerste}, // Char = Taste zum Aufrufen - {"Osterdatum ausrechnen", '3', (void*)&ostern}, // (void*)&MethodenName = Methode, die aufgerufen wird - {"ASCII Tabelle", '4', (void*)&ascii}, // Methode MUSS nicht vom Typ void sein! - {"DB-Pruefziffer", '5', (void*)&db}, // (void*)& MUSS immer davor stehen! + {"Euklidscher Algorithmus", '1', (void*)&euklid}, // String = Name des Menüpunktes + {"Gerstenkorn", '2', (void*)&gerste}, // Char = Taste zum Aufrufen + {"Osterdatum ausrechnen", '3', (void*)&ostern}, // (void*)&MethodenName = Methode, die aufgerufen wird + {"ASCII Tabelle", '4', (void*)&ascii}, // Methode MUSS nicht vom Typ void sein! + {"DB-Pruefziffer", '5', (void*)&db}, // (void*)& MUSS immer davor stehen! {"Modulo 11", '6', (void*)&mod11}, - {"BLANK", NULL, (void*)NULL}, // Fügt einen leere Zeile hinzu -> Gliederung - {"Namen TEST", 'a', (void*)&namen}, - {"Strings", 'b', (void*)&strHeader}, - {"BLANK", NULL, (void*)NULL}, - {"Exit", 'q', (void*)&exit} // exit beendet das Programm + {"BLANK", NULL, (void*)NULL}, // Fügt einen leere Zeile hinzu -> Gliederung + {"Namen TEST", '7', (void*)&namen}, + {"BLANK", NULL, (void*)NULL}, + {"Exit", 'q', (void*)&exit} // exit beendet das Programm }; -show_menu(sizeof(items) / sizeof(struct MenuItem), items, "Vorlesungsaufgaben", true, true, &NO_BORDER); + +struct MenuItem stringsEX[] = { + {"strcat()", '1', (void*)&strcatEx}, + {"strlen()", '2', (void*)&strlenEx}, + {"strncpy()", '3', (void*)&strncpyEx}, + {"strchr()", '4', (void*)&strchrEx}, + {"strstr()", '5', (void*)&strstrEx}, + {"strtok()", '6', (void*)&strtokEx}, + {"BLANK", NULL, (void*)NULL}, + {"Ersetzen", '7', (void*)&replace} +}; + +struct MenuPage pages[] = { + {items, sizeof(items) / sizeof(struct MenuItem), "Vorlesungsaufgaben", true, true, &SOLID}, + {stringsEX, sizeof(stringsEX) / sizeof(struct MenuItem), "String - Beispiele", true, true, &SOLID} + /* + * 1. Argument: Vorher angelegtes struct; Enthält alle Items der Seite + * 2. Argument: Anzahl der Elemente der Seite; Einfach so lassen + * 3. Argument: Titel der Seite + * 4. Argument: Menü im Loop; Nach beenden der Methode wieder Menü aufrufen + * 5. Argument: Pause nach dem Ausführen der Methode; Ausgaben lesbar + * 6. Argument: Style des Menüs: Standardmäßig wird DEFAULT, MODERN, SOLID und NO_BORDER unterstützt + */ +}; +show_menu(pages, sizeof(pages) / sizeof(struct MenuPage), true); + /* - * 1. Argument: Anzahl der Elemente; Einfach so lassen - * 2. Argument: Vorher angelegtes struct; Einfach so lassen - * 3. Argument: Titel des Menüs - * 4. Argument: Menü im loop; Nach beenden der Methode wieder Menü aufrufen - * 5. Argument: Pause nach dem Ausführen der Methode; Ausgaben lesbar - * 6. Argument: Style des Menüs: Standardmäßig wird DEFAULT, MODERN, SOLID und NO_BORDER unterstützt + * 1. Argument: Vorher angelegtes struct; Enthält alle Seiten des Menüs + * 2. Argument: Anzahl der Seiten; Einfach so lassen + * 3. Argument: Gesamtes Menü in einer unendlich-Schleife */ - ```` +``` ### Border hinzufügen Eigene Border-Styles können wie folgt hinzugefügt werden: ```C From 9f5b615df917c65a46c748c74ece3b44c536908f Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 14 Jan 2020 08:12:36 +0100 Subject: [PATCH 3/5] Removed show_menu from menu.h, simplified some code --- menu.c | 126 +++++++++++++++++++++++++++++++-------------------------- menu.h | 17 ++------ 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/menu.c b/menu.c index 721e23d..7e51057 100644 --- a/menu.c +++ b/menu.c @@ -1,5 +1,6 @@ #include "pch.h" #include "framework.h" + #include "menu.h" const struct MenuBorder DEFAULT = { @@ -18,6 +19,66 @@ const struct MenuBorder SOLID = { 186, 205, 201, 187, 200, 188, '[', ']' }; +void show_menu(const int itemc, const struct MenuItem itemv[], const char title[], const struct MenuBorder* border); + +void page(const struct MenuPage* pages, const size_t page_count, const bool infinite_loop) +{ + unsigned int page_index = 0; + bool action_performed, loop, page_changed = true; + char page_key, itemKey; + int i; + + do { + do { + show_menu(pages[page_index].item_count, pages[page_index].items, pages[page_index].title, pages[page_index].border); + + // Wait for user selection + putchar('>'); + putchar(' '); + + loop = pages[page_index].loopback; + page_key = _getch(); + + // Forward paging + if (page_key == 'm' && page_index < page_count - 1) + ++page_index; + // Backward paging + else if (page_key == 'n' && page_index > 0) + --page_index; + else + { + page_changed = false; + itemKey = page_key; + do { + action_performed = false; + + itemKey != page_key ? itemKey = _getch() : page_key; + page_key = 0; + for (i = 0; i < pages[page_index].item_count; ++i) + { + if (pages[page_index].items[i].key == itemKey) + { + // Perform action + system("cls"); + pages[page_index].items[i].action(); + action_performed = true; + + // Pause if requested + if (pages[page_index].pause) + { + putchar('\n'); + system("pause"); + } + } + } + } while (!action_performed); + } + } while (loop || page_changed); + + page_index = 0; + } while (infinite_loop); +} + // Checks if a line index should display a menu item bool is_item_line(const int line, const int itemc, int* item_index) { @@ -40,57 +101,8 @@ void get_console_dimensions(int* width, int* height) *height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } -void page(const struct MenuPage *pages, const size_t page_count, const bool infinite_loop) { - unsigned int page_index = 0; - bool action_performed, loop, pageChanged = true; - char pageKey, itemKey; - - do { - do { - show_menu(pages[page_index].item_count, pages[page_index].items, pages[page_index].title, pages[page_index].border); - - // Wait for user selection - putchar('>'); - putchar(' '); - - loop = pages[page_index].loopback; - pageKey = _getch(); - - if (pageKey == 'm') - page_index < page_count - 1 ? page_index++ : page_index; - else if (pageKey == 'n') - page_index > 0 ? page_index-- : page_index; - else { - pageChanged = false; - itemKey = pageKey; - do { - action_performed = false; - - itemKey != pageKey ? itemKey = _getch() : pageKey; - pageKey = 0; - for (int i = 0; i < pages[page_index].item_count; ++i) { - if (pages[page_index].items[i].key == itemKey) { - // Perform action - system("cls"); - pages[page_index].items[i].action(); - action_performed = true; - - // Pause if requested - if (pages[page_index].pause) { - putchar('\n'); - system("pause"); - } - } - } - } while (!action_performed); - } - } while (loop || pageChanged); - - page_index = 0; - } while (infinite_loop); -} - -void show_menu(const int itemc, const struct MenuItem itemv[], const char title[], const struct MenuBorder *border) +// Draws a menu to the console +void show_menu(const int itemc, const struct MenuItem itemv[], const char title[], const struct MenuBorder* border) { unsigned width, height, item_index; @@ -99,7 +111,7 @@ void show_menu(const int itemc, const struct MenuItem itemv[], const char title[ // Get the width and height of the console window get_console_dimensions(&width, &height); - + // Print frame with title for (unsigned i = 0; i < height - 1; ++i) { @@ -111,13 +123,13 @@ void show_menu(const int itemc, const struct MenuItem itemv[], const char title[ for (unsigned j = 1; j < width - strlen(title) - 2; ++j) { - if (j == ((width - strlen(title)) - 2)/ 2) + if (j == ((width - strlen(title)) - 2) / 2) { putchar(border->title_left); fputs(title, stdout); putchar(border->title_right); } - else + else { putchar(border->line_horizontal); } @@ -132,7 +144,7 @@ void show_menu(const int itemc, const struct MenuItem itemv[], const char title[ // Print item text putchar(border->line_vertical); - if (strcmp(itemv[item_index].text, "BLANK") == 0) { + if (strcmp(itemv[item_index].text, "BLANK") == 0) { putchar('\t'); // BLANK equals 5 characters @@ -146,13 +158,13 @@ void show_menu(const int itemc, const struct MenuItem itemv[], const char title[ { printf("\t%c) %s", itemv[item_index].key, itemv[item_index].text); } - + // Print right side of frame for (unsigned j = 0; j < width - strlen(itemv[item_index].text) - 12; ++j) { putchar(' '); } - + putchar(border->line_vertical); } // Line above bottom line diff --git a/menu.h b/menu.h index 63d3845..cb210ad 100644 --- a/menu.h +++ b/menu.h @@ -2,7 +2,6 @@ #include "pch.h" - /// Represents one menu item in a menu. struct MenuItem { char* text; @@ -22,10 +21,10 @@ struct MenuBorder { char title_right; }; +// Default borders initialized in menu.c const extern struct MenuBorder DEFAULT, MODERN, NO_BORDER, SOLID; - -/// Represents a page in the menu. +/// Represents a page containing menu items inside a menu. struct MenuPage { const struct MenuItem* items; const size_t item_count; @@ -34,16 +33,8 @@ struct MenuPage { const struct MenuBorder* border; }; - -/// Constructs a menu with a specific amount of pages +/// Constructs a CUI menu with a specific amount of pages. /// An array of all pages to display. /// The length of the array pages. /// Always display the first page after a loopback=false item finished executing. -void page(const struct MenuPage* pages, const size_t page_count, const bool infinite_loop); - -/// Displaces a CUI menu to the user -/// The length of the array itemv of menu items. -/// An array of all menu items to display in the menu. -/// The title of the menu. -/// Specifies the border in which the menu is displayed. -void show_menu(const int itemc, const struct MenuItem itemv[], const char title[], const struct MenuBorder *border); \ No newline at end of file +void page(const struct MenuPage* pages, const size_t page_count, const bool infinite_loop); \ No newline at end of file From 624d7be4f6da053d8700dc0de00d31e72d59c02e Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 14 Jan 2020 08:14:31 +0100 Subject: [PATCH 4/5] Fixed some errors in README.md --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f583870..8855408 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,12 @@ Verweis auf die Bibliothek im Aufruferprojekt anlegen: > Haken bei "MenuLib" setzen. Zusätzliches Includeverzeichnis hinzufügen: -> Rechtsklick auf Aufruferprojekt -> Eigenschaften -> Linked -> Eingabe -> Zusätzliche Abhängigkeiten -> Bearbeiten... +> Rechtsklick auf Aufruferprojekt -> Eigenschaften -> C/C++ -> Allgemein -> Zusätzliche Includeverzeichnisse -> Bearbeiten... + > Ordner, der "menu.h" enthält, auswählen +> Diese Einstellung muss für die Konfiguration erfolgen, die später compiliert werden soll. + Headerdatei einbinden: > Zeile ```#include "menu.h"``` zur Quelldatei hinzufügen @@ -24,8 +27,8 @@ struct MenuItem items[] = { {"Euklidscher Algorithmus", '1', (void*)&euklid}, // String = Name des Menüpunktes {"Gerstenkorn", '2', (void*)&gerste}, // Char = Taste zum Aufrufen {"Osterdatum ausrechnen", '3', (void*)&ostern}, // (void*)&MethodenName = Methode, die aufgerufen wird - {"ASCII Tabelle", '4', (void*)&ascii}, // Methode MUSS nicht vom Typ void sein! - {"DB-Pruefziffer", '5', (void*)&db}, // (void*)& MUSS immer davor stehen! + {"ASCII Tabelle", '4', (void*)&ascii}, // Methode MUSS nicht vom Typ void sein! + {"DB-Pruefziffer", '5', (void*)&db}, // (void*)& MUSS immer davor stehen! {"Modulo 11", '6', (void*)&mod11}, {"BLANK", NULL, (void*)NULL}, // Fügt einen leere Zeile hinzu -> Gliederung {"Namen TEST", '7', (void*)&namen}, @@ -57,7 +60,7 @@ struct MenuPage pages[] = { * 6. Argument: Style des Menüs: Standardmäßig wird DEFAULT, MODERN, SOLID und NO_BORDER unterstützt */ }; -show_menu(pages, sizeof(pages) / sizeof(struct MenuPage), true); +page(pages, sizeof(pages) / sizeof(struct MenuPage), true); /* * 1. Argument: Vorher angelegtes struct; Enthält alle Seiten des Menüs From d281e999a871318feef279acf1a0bcfc6be9ba3d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 14 Jan 2020 08:23:21 +0100 Subject: [PATCH 5/5] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 27 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..6cecf1f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: CyB3RC0nN0R + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..28e971c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: CyB3RC0nN0R + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here.