mAcpi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #include <ncursesw/ncurses.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <signal.h>
  5. #include <locale.h>
  6. #include <wchar.h>
  7. void draw_menu();
  8. void print_menu_items(const wchar_t *items[]);
  9. void cleanup(int sig);
  10. int selected = 0;
  11. const int MAX_ITEMS = 19;
  12. int main() {
  13. setlocale(LC_ALL, "ru_RU.UTF-8");
  14. if (!setlocale(LC_ALL, "")) {
  15. printf("Ошибка установки локали\n");
  16. return 1;
  17. }
  18. initscr();
  19. if (stdscr == NULL) { printf("Ошибка инициализации ncurses\n"); return 1; }
  20. if (has_colors() == FALSE) {
  21. endwin();
  22. printf("Терминал не поддерживает цвета\n");
  23. return 1;
  24. }
  25. start_color();
  26. cbreak();
  27. noecho();
  28. keypad(stdscr, TRUE);
  29. curs_set(0);
  30. signal(SIGINT, cleanup);
  31. init_pair(1, COLOR_BLACK, COLOR_YELLOW); // Чёрный на жёлтом (рамки и выделение)
  32. init_pair(2, COLOR_YELLOW, COLOR_BLACK); // Жёлтый текст (заголовки, линии)
  33. init_pair(3, COLOR_CYAN, COLOR_BLACK); // "Git"
  34. init_pair(4, COLOR_GREEN, COLOR_BLACK); // Пункты меню
  35. init_pair(5, COLOR_WHITE, COLOR_BLACK);
  36. init_pair(6, COLOR_WHITE - 1, COLOR_BLACK);
  37. const wchar_t *items[] = {
  38. L" Установка INSTALL ",
  39. L" Краткий обзор SYNOPSIS ",
  40. L" Описание DESCRIPTION ",
  41. L" Автор AUTHOR ",
  42. L" Показать нформацию об батарее -b --battery ",
  43. L" Показать нформацию об адаптере питания -a --ac-adapter ",
  44. L" Показать нформацию о температуре -t --thermal ",
  45. L" Показать нформацию об охлаждении -c --cooling ",
  46. L" Показать все устройства, переопределяет другие опции -V --everything ",
  47. L" Показать неработающие/неактивные устройства -s --show-empty ",
  48. L" Показать дополнительные детали, если они доступны -i --details ",
  49. L" Показать температуру в Фаренгейтах -f --fahrenheit ",
  50. L" Использовать Кельвины вместо Цельсия -k --kelvin ",
  51. L" Использовать старый /proc вместо нового /sys -p --proc ",
  52. L" Путь к ACPI (/proc/acpi или /sys/class) -d --directory ",
  53. L" Показать справку -h --help ",
  54. L" Показать версию -v | --version ",
  55. L" Git ",
  56. L" Exit "
  57. };
  58. draw_menu();
  59. print_menu_items(items);
  60. while (1) {
  61. int ch = getch();
  62. switch (ch) {
  63. case KEY_UP:
  64. selected--;
  65. if (selected < 0) selected = MAX_ITEMS - 1;
  66. print_menu_items(items);
  67. break;
  68. case KEY_DOWN:
  69. selected++;
  70. if (selected >= MAX_ITEMS) selected = 0;
  71. print_menu_items(items);
  72. break;
  73. case 10: // Enter
  74. int last_line = 0;
  75. clear();
  76. refresh();
  77. if (selected == 18) { // Exit
  78. cleanup(0);
  79. }
  80. // Специальная обработка для "Установка"
  81. if (selected == 0) {
  82. mvprintw(1, 0, " Утилита предустановлена.");
  83. last_line = 2;
  84. }
  85. // SYNOPSIS
  86. if (selected == 1) {
  87. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi [options]");attroff(COLOR_PAIR(4)); // Выключаем и выключаем зеленый цвет
  88. last_line = 2;
  89. }
  90. // DESCRIPTION
  91. if (selected == 2) {
  92. mvprintw(1, 0, " ACPI показывает информацию из файловой системы");
  93. mvprintw(2, 0, " или /sys, такой как состояние батареи или тепловая информация.");
  94. last_line = 3;
  95. }
  96. // AUTHOR
  97. if (selected == 3) {
  98. mvprintw(1, 0, " Оригинальная версия этой страницы руководства была написана Полом Телфордом");
  99. mvprintw(2, 0, " pxt@debian.org для системы Debian.");
  100. mvprintw(3, 0, " Новые дополнения были сделаны Майклом Месксом meskes@debian.org");
  101. mvprintw(4, 0, " Разрешение предоставляется копировать, распространять");
  102. mvprintw(5, 0, " и изменять этот документ в соответствии с условиями GNU GPL.");
  103. last_line = 6;
  104. }
  105. // acpi -b --battery
  106. if (selected == 4) {
  107. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -b");attroff(COLOR_PAIR(4));
  108. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --battery");attroff(COLOR_PAIR(4));
  109. last_line = 3;
  110. }
  111. // acpi -a --ac-adapter
  112. if (selected == 5) {
  113. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -a");attroff(COLOR_PAIR(4));
  114. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --ac-adapter");attroff(COLOR_PAIR(4));
  115. last_line = 3;
  116. }
  117. // acpi -t acpi --thermal
  118. if (selected == 6) {
  119. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -t");attroff(COLOR_PAIR(4));
  120. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --thermal");attroff(COLOR_PAIR(4));
  121. last_line = 3;
  122. }
  123. // acpi -c --cooling
  124. if (selected == 7) {
  125. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -c");attroff(COLOR_PAIR(4));
  126. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --cooling");attroff(COLOR_PAIR(4));
  127. last_line = 3;
  128. }
  129. // acpi -V --everything
  130. if (selected == 8) {
  131. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -V");attroff(COLOR_PAIR(4));
  132. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --everything");attroff(COLOR_PAIR(4));
  133. last_line = 3;
  134. }
  135. // acpi -s --show-empty
  136. if (selected == 9) {
  137. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -s");attroff(COLOR_PAIR(4));
  138. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --show-empty");attroff(COLOR_PAIR(4));
  139. last_line = 3;
  140. }
  141. // acpi -i --details
  142. if (selected == 10) {
  143. mvprintw(1, 0, " Информация о ёмкости батареи.");
  144. mvprintw(2, 0, " Температурные пороги срабатывания.");
  145. attron(COLOR_PAIR(4));mvprintw(3, 0, " acpi -i");attroff(COLOR_PAIR(4));
  146. attron(COLOR_PAIR(4));mvprintw(4, 0, " acpi --details");attroff(COLOR_PAIR(4));
  147. last_line = 5;
  148. }
  149. // acpi -f --fahrenheit
  150. if (selected == 11) {
  151. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -f");attroff(COLOR_PAIR(4));
  152. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --fahrenheit");attroff(COLOR_PAIR(4));
  153. last_line = 3;
  154. }
  155. // acpi -k | --kelvin
  156. if (selected == 12) {
  157. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -k");attroff(COLOR_PAIR(4));
  158. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --kelvin");attroff(COLOR_PAIR(4));
  159. last_line = 3;
  160. }
  161. // acpi -p | --proc
  162. if (selected == 13) {
  163. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -p");attroff(COLOR_PAIR(4));
  164. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --proc");attroff(COLOR_PAIR(4));
  165. last_line = 3;
  166. }
  167. // acpi -d --directory
  168. if (selected == 14) {
  169. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -d");attroff(COLOR_PAIR(4));
  170. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --directory");attroff(COLOR_PAIR(4));
  171. last_line = 3;
  172. }
  173. // acpi acpi -h --help
  174. if (selected == 15) {
  175. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -h");attroff(COLOR_PAIR(4));
  176. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --help");attroff(COLOR_PAIR(4));
  177. last_line = 3;
  178. }
  179. // acpi -v --version
  180. if (selected == 16) {
  181. attron(COLOR_PAIR(4));mvprintw(1, 0, " acpi -v");attroff(COLOR_PAIR(4));
  182. attron(COLOR_PAIR(4));mvprintw(2, 0, " acpi --version");attroff(COLOR_PAIR(4));
  183. last_line = 3;
  184. }
  185. // Git
  186. if (selected == 17) {
  187. mvprintw(1, 0, " https://github.com/acpica/acpica ");
  188. mvprintw(2, 0, " https://www.intel.com/content/www/us/en/developer/topic-technology/open/acpica/overview.html ");
  189. last_line = 3;
  190. }
  191. attron(COLOR_PAIR(1));
  192. mvprintw(last_line + 2, 0, " ENTER = Main Menu ");
  193. attroff(COLOR_PAIR(1));
  194. refresh();
  195. getch();
  196. draw_menu();
  197. print_menu_items(items);
  198. break;
  199. }
  200. }
  201. cleanup(0);
  202. return 0;
  203. }
  204. void draw_menu() {
  205. clear();
  206. // Верхняя линия с жёлтым фоном
  207. attron(COLOR_PAIR(1));mvprintw(0, 0, "┌──────────────────────────────────────────────────────────────────────────────┐");attroff(COLOR_PAIR(1));
  208. // Вертикальные линии рамки (жёлтый фон только для символов)
  209. attron(COLOR_PAIR(1));mvvline(1, 0, ACS_VLINE, 29);mvvline(1, 79, ACS_VLINE, 29);attroff(COLOR_PAIR(1));
  210. // Нижняя линия с жёлтым фоном
  211. attron(COLOR_PAIR(1));mvprintw(30, 0, "└──────────────────────────────────────────────────────────────────────────────┘");attroff(COLOR_PAIR(1));
  212. // Разделители (жёлтый фон только для соединителей)
  213. attron(COLOR_PAIR(1));
  214. mvaddch(3, 0, ACS_LTEE);
  215. mvaddch(3, 79, ACS_RTEE);
  216. mvaddch(5, 0, ACS_LTEE);
  217. mvaddch(5, 79, ACS_RTEE);
  218. // mvaddch(30, 0, ACS_LTEE);
  219. // mvaddch(31, 79, ACS_RTEE);
  220. attroff(COLOR_PAIR(1));
  221. // Горизонтальные линии разделителей (жёлтый текст без фона)
  222. attron(COLOR_PAIR(2));
  223. mvhline(3, 1, ACS_HLINE, 78);
  224. mvhline(5, 1, ACS_HLINE, 78);
  225. mvhline(10, 1, ACS_HLINE, 78);
  226. mvhline(25, 1, ACS_HLINE, 78);
  227. attroff(COLOR_PAIR(2));
  228. // Текст
  229. // attron(A_BOLD | hunting(COLOR_PAIR(5));mvprintw(2, 3, "*** acpi ***");attroff(A_BOLD | COLOR_PAIR(6));
  230. attron(A_BOLD | COLOR_PAIR(5)); mvprintw(2, 3, "*** acpi ***"); attroff(A_BOLD | COLOR_PAIR(6));
  231. attron(A_DIM); mvprintw(4, 3, "Shows battery status and other ACPI information"); attroff(A_DIM);
  232. attron(A_DIM); mvprintw(11, 3, "ОПЦИИ OPTIONS"); attroff(A_DIM);
  233. attron(COLOR_PAIR(2));mvprintw(27, 1, "── ↑ Up ──── ↓ Down ──── ↵ Select Enter ──────────────────────────────────────");attroff(COLOR_PAIR(2));
  234. refresh();
  235. }
  236. void print_menu_items(const wchar_t *items[]) {
  237. int y_positions[] = { 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 28 };
  238. for (int i = 0; i < MAX_ITEMS; i++) {
  239. attron(COLOR_PAIR(4)); mvprintw(y_positions[i], 2, "%-77ls", L" "); attroff(COLOR_PAIR(4));
  240. if (i == selected) {
  241. attron(COLOR_PAIR(1));
  242. if (items[i][0] == L'\0') {
  243. mvprintw(y_positions[i], 2, "%-77ls", L" ");
  244. } else {
  245. mvprintw(y_positions[i], 2, "%ls", items[i]);
  246. }
  247. attroff(COLOR_PAIR(1));
  248. } else if (i == 0) {
  249. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L"");
  250. attron(COLOR_PAIR(4)); printw(" INSTALL "); attroff(COLOR_PAIR(4));
  251. } else if (i == 1) {
  252. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L"");
  253. attron(COLOR_PAIR(4)); printw(" SYNOPSIS "); attroff(COLOR_PAIR(4));
  254. } else if (i == 2) {
  255. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L"");
  256. attron(COLOR_PAIR(4)); printw(" DESCRIPTION "); attroff(COLOR_PAIR(4));
  257. } else if (i == 3) {
  258. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L"");
  259. attron(COLOR_PAIR(4)); printw(" AUTHOR "); attroff(COLOR_PAIR(4));
  260. } else if (i == 4) {
  261. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show battery information ");
  262. attron(COLOR_PAIR(4)); printw(" -b --battery "); attroff(COLOR_PAIR(4));
  263. } else if (i == 5) {
  264. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show ac adapter information ");
  265. attron(COLOR_PAIR(4)); printw(" -a --ac-adapter "); attroff(COLOR_PAIR(4));
  266. } else if (i == 6) {
  267. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show thermal information ");
  268. attron(COLOR_PAIR(4)); printw(" -t --thermal "); attroff(COLOR_PAIR(4));
  269. } else if (i == 7) {
  270. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show cooling device information ");
  271. attron(COLOR_PAIR(4)); printw(" -c --cooling "); attroff(COLOR_PAIR(4));
  272. } else if (i == 8) {
  273. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show every device, overrides above options ");
  274. attron(COLOR_PAIR(4)); printw(" -V --everything "); attroff(COLOR_PAIR(4));
  275. } else if (i == 9) {
  276. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show non-operational devices");
  277. attron(COLOR_PAIR(4)); printw(" -s --show-empty "); attroff(COLOR_PAIR(4));
  278. } else if (i == 10) {
  279. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show additional details if available:");
  280. attron(COLOR_PAIR(4)); printw(" -i --details "); attroff(COLOR_PAIR(4));
  281. } else if (i == 11) {
  282. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Show temperature in Fahrenheit");
  283. attron(COLOR_PAIR(4)); printw(" -f --fahrenheit "); attroff(COLOR_PAIR(4));
  284. } else if (i == 12) {
  285. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Use Kelvin instead of Celsius");
  286. attron(COLOR_PAIR(4)); printw(" -k --kelvin "); attroff(COLOR_PAIR(4));
  287. } else if (i == 13) {
  288. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Use old /proc instead of new /sys");
  289. attron(COLOR_PAIR(4)); printw(" -p --proc "); attroff(COLOR_PAIR(4));
  290. } else if (i == 14) {
  291. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Path to ACPI info (/proc/acpi or /sys/class)");
  292. attron(COLOR_PAIR(4)); printw(" -d --directory "); attroff(COLOR_PAIR(4));
  293. } else if (i == 15) {
  294. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Display help and exit");
  295. attron(COLOR_PAIR(4)); printw(" -h --help "); attroff(COLOR_PAIR(4));
  296. } else if (i == 16) {
  297. attron(COLOR_PAIR(5)); mvprintw(y_positions[i], 2, "%ls", L" Output version information and exit");
  298. attron(COLOR_PAIR(4)); printw(" -v --version "); attroff(COLOR_PAIR(4));
  299. } else {
  300. attron(COLOR_PAIR(4)); mvprintw(y_positions[i], 2, "%ls", items[i]); attroff(COLOR_PAIR(4));
  301. }
  302. }
  303. refresh();
  304. }
  305. void cleanup(int sig) {
  306. endwin();
  307. exit(0);
  308. }