update help message
authorLaurent Mazet <mazet@softndesign.org>
Fri, 3 Jan 2025 22:42:57 +0000 (23:42 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 3 Jan 2025 22:42:57 +0000 (23:42 +0100)
display.c
fm.c
function.c
function.h
type.h

index f0d01a96c9109a3a7c06528644c7001de83782b2..731c75229e32a8c93060f14d941227115139cdea 100644 (file)
--- a/display.c
+++ b/display.c
@@ -67,7 +67,12 @@ int _helpwindow (char *msg, int xoffset, int yoffset, int length)
     int i = 0;
     int j = 0;
     while ((msg) && (*msg != '\0')) {
-        if ((*msg == '\n') || (i  == length)) {
+        if (*msg == '\n') {
+            if (i  <= length) {
+                mvaddch (yoffset + j, xoffset + i, ' ');
+                i++;
+                continue;
+            }
             i = 0;
             j++;
         }
@@ -80,13 +85,16 @@ int _helpwindow (char *msg, int xoffset, int yoffset, int length)
     return j;
 }
 
-void _displaytitle (char *title, int xoffset, int yoffset)
+void _displaytitle (char *title, int xoffset, int yoffset, int length)
 {
     int i;
-    for (i = 0; title[i] != '\0'; i++) {
-        mvaddch (yoffset, xoffset + i, title[i]);
+    for (i = 0; i < length; i++) {
+        mvaddch (yoffset, xoffset + i, ' ');
         mvaddch (yoffset + 1, xoffset + i, ACS_HLINE);
     }
+    for (i = 0; title[i] != '\0'; i++) {
+        mvaddch (yoffset, xoffset + i + (length - strlen (title)) / 2, title[i]);
+    }
 }
 
 void _dobound (int xsize, int ysize, int xoffset, int yoffset)
@@ -109,10 +117,16 @@ void _dobound (int xsize, int ysize, int xoffset, int yoffset)
 
 int helpwindow (char *msg, int xoffset, int yoffset)
 {
-    _displaytitle ("Help message", xoffset, yoffset);
+    char *title = "Help message";
     int length = strmaxlen (msg, '\n');
+    if (length < (int)strlen (title)) {
+        length = strlen (title);
+    }
+    set_color (byellow);
+    _displaytitle (title, xoffset, yoffset, length);
     int j = 2;
     j += _helpwindow (msg, xoffset, yoffset + j, length);
+    _dobound (length, j, xoffset, yoffset);
 
     return j;
 }
@@ -181,6 +195,9 @@ void displaywindow (window_t *win, list_t *list, int page, int *index_x, int *in
             }
             mvaddstr (win->yoffset + (j % n) - page, win->xoffset + (j / n) * win->width, elem->name);
             set_color (white);
+            if (j == index) {
+                win->index = i;
+            }
         }
     }
 
@@ -273,8 +290,8 @@ void msgwindow (char *msg, int xoffset, int yoffset, int length)
 {
     set_color (black);
     _dobound ((length > 0) ? length : (int)strlen (msg), 1, xoffset, yoffset);
-    set_color (white);
     mvaddstr (yoffset, xoffset + ((length > 0) ? (length - (int)strlen (msg)) / 2 : 0), msg);
+    set_color (white);
 }
 
 int askwindow (char *msg, int xoffset, int yoffset, char *ok, char *ko)
diff --git a/fm.c b/fm.c
index dcaeb3b84a58101c2a55b0af1fad329ce7365732..17ba23b3623e7b719328b3f4357f089a70cd20ed 100644 (file)
--- a/fm.c
+++ b/fm.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "debug.h"
 #include "display.h"
@@ -28,6 +29,11 @@ int xoffset = 1;
 int yoffset = 2;
 
 char *help =
+    "ret Enter directory\n"
+    "tab Change pane\n"
+    "<I> Page up\n"
+    "<K> Page down\n"
+    "<h> Show help\n"
     "<i> Move up\n"
     "<j> Move left\n"
     "<k> Move down\n"
@@ -153,6 +159,20 @@ int main (int argc, char *argv[])
 
         int ch = getch ();
         switch (ch) {
+        case '\n':
+        case '\r':
+            if ((list[pane]->tab + windir[pane]->index)->type == type_dir_e) {
+                elem_t *elem = list[pane]->tab + windir[pane]->index;
+                char *_dirname = newfilename (dirname[pane], elem->name);
+                free (dirname[pane]);
+                dirname[pane] = _dirname;
+                index_x[pane] = 0;
+                index_y[pane] = 0;
+                freelist (list[pane]);
+                list[pane] = NULL;
+                page[pane] = 0;
+            }
+            break;
         case KEY_PPAGE:
         case KEY_SLEFT:
         case 'I':
@@ -167,6 +187,12 @@ int main (int argc, char *argv[])
                 page[pane]++;
             }
             break;
+        case 'h':
+            helpwindow (help, (COLS - strmaxlen (help, '\n')) / 2, 3 * yoffset);
+            while (getch () == ERR) {
+                usleep (200 * 1000);
+            }
+            break;
         case KEY_UP:
         case 'i':
             if (index_y[pane]> 0) {
@@ -213,7 +239,7 @@ int main (int argc, char *argv[])
 
     for (i = 0; i < MAXPANES; i++) {
         free (dirname[i]);
-        freelist (list[pane]);
+        freelist (list[i]);
         freewindow (windir[i]);
     }
 
index 09561bd7abcf845e884466d0aec1d2958fe04fe6..8376a9c554665e47a2f53c5e003b3d04e0f807ab 100644 (file)
@@ -26,6 +26,14 @@ int strmaxlen (char *str, char ch)
     return len;
 }
 
+char *newfilename (char *dirname, char *filename)
+{
+    char *name = (char *) calloc (strlen (dirname) + strlen (SEPARATOR) + strlen (filename) + 1, 1);
+    CHECKALLOC (name);
+    strcat (strcat(strcpy (name, dirname), SEPARATOR), filename);
+    return name;
+}
+
 list_t *alloclist (void)
 {
     list_t *list = (list_t *) calloc (1, sizeof (list_t));
@@ -40,9 +48,7 @@ list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type)
     size_t size = 0;
 
     if ((type == type_unkn_e) || (type == type_reg_e)) {
-        char *name = (char *) calloc (strlen (dirname) + strlen (filename) + strlen (SEPARATOR) + 1, 1);
-        CHECKALLOC (name);
-        strcat (strcat(strcpy (name, dirname), SEPARATOR), filename);
+        char *name = newfilename (dirname, filename);
 
         struct stat sb;
         if (lstat (name, &sb) == -1) {
@@ -118,6 +124,9 @@ list_t *exploredir (char *dirname)
 
     struct dirent *dp = NULL;
     while ((dp = readdir(dir)) != NULL) {
+        if (strcmp (dp->d_name, ".") == 0) {
+            continue;
+        }
         type_t type = type_unkn_e;
         switch (dp->d_type) {
         case DT_BLK:
index 6e7580059f2df216b04142acf712b6f83692d0f1..fb4b46ae120cdcc22ebff54efed942340e2bec4e 100644 (file)
@@ -17,6 +17,8 @@
 
 int strmaxlen (char *str, char ch);
 
+char *newfilename (char *dirname, char *filename);
+
 list_t *alloclist (void);
 
 list_t *exploredir (char *dirname);
diff --git a/type.h b/type.h
index f2658f608716b72f1c275a4e59600afc2512ce75..af34ba36da261bbf241a2b729fee1fa9d42c919d 100644 (file)
--- a/type.h
+++ b/type.h
@@ -29,6 +29,7 @@ typedef struct {
 
 typedef struct {
     int active;
+    int index;
     int nbcols;
     int width;
     int xoffset;