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++;
}
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)
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;
}
}
mvaddstr (win->yoffset + (j % n) - page, win->xoffset + (j / n) * win->width, elem->name);
set_color (white);
+ if (j == index) {
+ win->index = i;
+ }
}
}
{
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)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "debug.h"
#include "display.h"
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"
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':
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) {
for (i = 0; i < MAXPANES; i++) {
free (dirname[i]);
- freelist (list[pane]);
+ freelist (list[i]);
freewindow (windir[i]);
}
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));
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) {
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: