-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathui.c
More file actions
84 lines (67 loc) · 2.39 KB
/
Copy pathui.c
File metadata and controls
84 lines (67 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <ncurses.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include "types.h"
#include "globals.h"
void draw_buttons(int maxY, int maxX) {
move(maxY - 1, 0);
clrtoeol();
char *buttons[] = {"Sort", "View", "Edit", "Copy", "Move", "Mkdir", "Del", "Refresh", "Quit"};
int num_buttons = sizeof(buttons) / sizeof(char *);
int total_width = maxX - (num_buttons - 1); // Subtract (num_buttons - 1) to account for spaces between buttons
int button_width = (total_width - 1) / num_buttons; // -1 to account for the extra character in "F10"
int extra_space = total_width - (button_width * num_buttons) - 1; // -1 to account for the extra character in "F10"
int x = 0;
for (int i = 0; i < num_buttons; ++i) {
int extra = 0;
if (extra_space > 0) {
extra = 1;
extra_space--;
}
attrset(A_NORMAL);
if (i == num_buttons - 1) { // Last button (F10)
mvprintw(maxY - 1, x, "F%d ", i + 2);
} else {
mvprintw(maxY - 1, x, "F%d", i + 2);
}
attron(COLOR_PAIR(COLOR_BLACK_ON_CYAN));
mvprintw(maxY - 1, x + 2 + (i == num_buttons - 1), "%-*s", button_width - 2 + extra, buttons[i]);
x += button_width + extra + 1 + (i == num_buttons - 1); // +1 spacer between buttons, +1 for the last button (F10)
}
}
void draw_windows(int maxY, int maxX) {
// Refresh stdscr to ensure it's updated
refresh();
// Calculate window dimensions
int winHeight = maxY - 2;
int winWidth1 = maxX / 2;
int winWidth2 = maxX / 2;
// Adjust for odd COLS
if (maxX % 2 != 0) {
winWidth2 += 1;
}
// Delete old windows
delwin(win1);
delwin(win2);
// Create new windows
win1 = newwin(winHeight, winWidth1, 0, 0);
win2 = newwin(winHeight, winWidth2, 0, winWidth1);
// Apply the color pair to the window
wbkgd(win1, COLOR_PAIR(COLOR_WHITE_ON_BLUE));
wbkgd(win2, COLOR_PAIR(COLOR_WHITE_ON_BLUE));
// Add borders to windows using wborder()
wborder(win1, '|', '|', '-', '-', '+', '+', '+', '+');
wborder(win2, '|', '|', '-', '-', '+', '+', '+', '+');
// Refresh windows to make borders visible
wrefresh(win1);
wrefresh(win2);
}