Implement j, k for up and down movement in -l mode
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Mon, 11 Mar 2024 13:27:17 +0000 (14:27 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Mon, 11 Mar 2024 13:27:17 +0000 (14:27 +0100)
This led to the necessity to rename kill to defeat.
The option -k has thus been renamed -d and in the loop mode
"d" key is used for what "k" used to do.

inc/palboss.h
src/loop.c
src/main.c

index 62b75be5c57d6e25ad02d9c663c8dc485214fbe1..d22db270302805cf558c98c5a3a63dafc5ce959b 100644 (file)
@@ -9,14 +9,14 @@
 typedef struct s_database_entry
 {
        int                     level;
-       time_t          kill_time;
+       time_t          defeat_time;
        char            *name;
        char            *biome;
 }                              t_entry;
 
 typedef enum e_basic_command
 {
-       basic_kill,
+       basic_defeat,
        basic_add,
        basic_list,
        basic_loop,
@@ -42,6 +42,6 @@ typedef struct s_term
 }                                      t_term;
 
 void   loop(t_vec *database);
-void   kill_entry(t_vec *database, size_t ind);
+void   defeat_entry(t_vec *database, size_t ind);
 void   print_entry(t_entry *entry);
 #endif //PALBOSS_H
index aa30e73e660e59a6d9ba796920da47dc76640c29..4f2f3f2c005e3206645742072312326659f3ca10 100644 (file)
@@ -90,28 +90,28 @@ void        print_noncanon(t_vec *database, t_term *term)
 
 int    handle_buffer(const char *buffer, t_vec *database, t_term *term)
 {
-       if (!ft_strcmp(buffer, "\033[A"))
+       if (!ft_strcmp(buffer, "\033[A") || !ft_strcmp(buffer, "k"))
        {
                if (term->y > 1)
                {
                        --term->y;
-                       ft_putstr_fd(buffer, STDOUT_FILENO);
+                       ft_putstr_fd("\033[A", STDOUT_FILENO);
                }
                else if (term->top_row > 0)
                        --term->top_row;
        }
-       else if (!ft_strcmp(buffer, "\033[B"))
+       else if (!ft_strcmp(buffer, "\033[B") || !ft_strcmp(buffer, "j"))
        {
                if (term->y < term->height && term->y < database->size - term->top_row)
                {
                        ++term->y;
-                       ft_putstr_fd(buffer, STDOUT_FILENO);
+                       ft_putstr_fd("\033[B", STDOUT_FILENO);
                }
                else if (database->size - term->top_row > term->height)
                        ++term->top_row;
        }
-       else if (!ft_strcmp(buffer, "k") && term->top_row + term->y - 1 < database->size)
-               kill_entry(database, term->top_row + term->y - 1);
+       else if (!ft_strcmp(buffer, "d") && term->top_row + term->y - 1 < database->size)
+               defeat_entry(database, term->top_row + term->y - 1);
        else if (!ft_strcmp(buffer, "q") || !ft_strcmp(buffer, "\033"))
                return (1);
        return (0);
index 91d783b054ed1bcf80e4d32997b6d836e277b685..9afea1fadc5cf9cf5a49b895c79cb58717dbfbbe 100644 (file)
@@ -17,7 +17,7 @@ int   write_entry(int fd, t_entry *entry)
                        entry->name,
                        entry->level,
                        entry->biome,
-                       entry->kill_time);
+                       entry->defeat_time);
        return (0);
 }
 
@@ -64,7 +64,7 @@ void  print_entry(t_entry *entry)
        char                            *color;
        static const char       *reset_color = "\033[0m";
 
-       countdown = 3600 - (get_time_sec() - entry->kill_time);
+       countdown = 3600 - (get_time_sec() - entry->defeat_time);
        countdown = ft_max(0, countdown);
        if (countdown == 0)
                color = "\033[42m";
@@ -122,7 +122,7 @@ int parse_line(char *line, t_vec *database)
        new_entry.biome = line;
        if (advance_line(&line))
                return (1);
-       new_entry.kill_time = ft_atoi(line);
+       new_entry.defeat_time = ft_atoi(line);
        if (advance_line(&line))
                return (1);
        if (*line != '\0')
@@ -180,7 +180,7 @@ int construct_new_entry(t_entry *entry, char **argv)
        entry->name = datastr;
        entry->level = ft_atoi(argv[3]);
        entry->biome = datastr + namelen + 1;
-       entry->kill_time = 0;
+       entry->defeat_time = 0;
        return (0);
 }
 
@@ -207,11 +207,11 @@ int       parse_input(t_command *command, int argc, char **argv)
        }
        else if (argc == 3)
        {
-               if (ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r"))
+               if (ft_strcmp(argv[1], "-d") && ft_strcmp(argv[1], "-r"))
                        return (1);
                command->entry.name = argv[2];
-               if (argv[1][1] == 'k')
-                       command->basic = basic_kill;
+               if (argv[1][1] == 'd')
+                       command->basic = basic_defeat;
                else if (argv[1][1] == 'r')
                        command->basic = basic_remove;
                return (0);
@@ -224,12 +224,12 @@ int       parse_input(t_command *command, int argc, char **argv)
        return (1);
 }
 
-void   kill_entry(t_vec *database, size_t ind)
+void   defeat_entry(t_vec *database, size_t ind)
 {
        t_entry                 entry;
 
        entry = *(t_entry *)ft_vec_access(database, ind);
-       entry.kill_time = get_time_sec();
+       entry.defeat_time = get_time_sec();
        ft_vec_forget(database, ind);
        ft_vec_append(database, &entry);
        return ;
@@ -267,8 +267,8 @@ void        print_help(void)
                "\t\tPrint this help.\n"
                "\t-l\n"
                "\t\tPrint the list in a loop. End by using Q key.\n"
-               "\t-k boss\n"
-               "\t\tMark the boss as killed, setting the counter to 60 minutes.\n"
+               "\t-d boss\n"
+               "\t\tMark the boss as defeated, setting the counter to 60 minutes.\n"
                "\t-a boss level location\n"
                "\t\tAdd a boss to the database. Long strings may break formatting.\n"
                "\t-r boss\n"
@@ -287,8 +287,8 @@ void        carry_out_command(t_command *com, t_vec *database)
                ft_printf("Problem with the name!\n");
                return ;
        }
-       if (com->basic == basic_kill)
-               kill_entry(database, ind);
+       if (com->basic == basic_defeat)
+               defeat_entry(database, ind);
        else if (com->basic == basic_remove)
                ft_vec_erase(database, ind, free_entry);
        else if (com->basic == basic_add)