sysinfo.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2015 Kevin Lange
  5. *
  6. * sysinfo - visually based on screenfetch
  7. *
  8. * Displays system information in a visually-pleasing format.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <sys/utsname.h>
  14. #include <toaru/graphics.h>
  15. #include <toaru/termemu.h>
  16. #include "toaru_logo.h"
  17. #define NUM_DATA_LINES 30
  18. char data_lines[NUM_DATA_LINES][100];
  19. const char * prog_lines[NUM_DATA_LINES] = {NULL};
  20. #define C_A "\033[34;1m"
  21. #define C_O "\033[0m"
  22. void print_thing(int j) {
  23. printf("\033[0m %s", data_lines[j]);
  24. fflush(stdout);
  25. if (prog_lines[j]) {
  26. system(prog_lines[j]);
  27. } else {
  28. printf("\n");
  29. }
  30. }
  31. int main(int argc, char * argv[]) {
  32. /* Prepare data */
  33. char * user = getenv("USER");
  34. char * wm_theme = getenv("WM_THEME");
  35. int i = 0;
  36. prog_lines[i] = "hostname";
  37. sprintf(data_lines[i++], C_A "%s" C_O "@" C_A, user);
  38. sprintf(data_lines[i++], C_A "OS: " C_O "ToaruOS");
  39. prog_lines[i] = "uname -sr";
  40. sprintf(data_lines[i++], C_A "Kernel: " C_O);
  41. prog_lines[i] = "uptime -p";
  42. sprintf(data_lines[i++], C_A "Uptime: " C_O);
  43. //sprintf(data_lines[i++], C_A "Packages: " C_O "(hell if I know!)");
  44. prog_lines[i] = "sh -v";
  45. sprintf(data_lines[i++], C_A "Shell: " C_O);
  46. prog_lines[i] = "yutani-query -r";
  47. sprintf(data_lines[i++], C_A "Resolution: " C_O);
  48. sprintf(data_lines[i++], C_A "WM: " C_O "Yutani");
  49. sprintf(data_lines[i++], C_A "WM Theme: " C_O "%s", wm_theme);
  50. #if 0
  51. prog_lines[i] = "yutani-query -m";
  52. sprintf(data_lines[i++], C_A "Font: " C_O);
  53. #endif
  54. //sprintf(data_lines[i++], C_A "CPU: " C_O "(query cpudet)");
  55. //sprintf(data_lines[i++], C_A "GPU: " C_O "(hell if I know!)");
  56. prog_lines[i] = "free -ut";
  57. sprintf(data_lines[i++], C_A "RAM: " C_O);
  58. int j = 0;
  59. for (unsigned int y = 0; y < gimp_image.height; y += 2) {
  60. for (unsigned int x = 0; x < gimp_image.width; x += 1) {
  61. unsigned char r_t = gimp_image.pixel_data[(x + y * gimp_image.width) * 4];
  62. unsigned char g_t = gimp_image.pixel_data[(x + y * gimp_image.width) * 4 + 1];
  63. unsigned char b_t = gimp_image.pixel_data[(x + y * gimp_image.width) * 4 + 2];
  64. unsigned char a_t = gimp_image.pixel_data[(x + y * gimp_image.width) * 4 + 3];
  65. unsigned char r_b = 0;
  66. unsigned char g_b = 0;
  67. unsigned char b_b = 0;
  68. unsigned char a_b = 0;
  69. if (y != gimp_image.height - 1) {
  70. r_b = gimp_image.pixel_data[(x + (y + 1) * gimp_image.width) * 4];
  71. g_b = gimp_image.pixel_data[(x + (y + 1) * gimp_image.width) * 4 + 1];
  72. b_b = gimp_image.pixel_data[(x + (y + 1) * gimp_image.width) * 4 + 2];
  73. a_b = gimp_image.pixel_data[(x + (y + 1) * gimp_image.width) * 4 + 3];
  74. }
  75. uint32_t out = alpha_blend_rgba(
  76. rgba(0,0,0,TERM_DEFAULT_OPAC),
  77. premultiply(rgba(r_t, g_t, b_t, a_t)));
  78. uint32_t back = alpha_blend_rgba(
  79. rgba(0,0,0,TERM_DEFAULT_OPAC),
  80. premultiply(rgba(r_b, g_b, b_b, a_b)));
  81. /* Print half block */
  82. printf("\033[38;6;%d;%d;%d;%dm\033[48;6;%d;%d;%d;%dm▄",
  83. _RED(back), _GRE(back), _BLU(back), _ALP(back),
  84. _RED(out), _GRE(out), _BLU(out), _ALP(out));
  85. }
  86. if (j < i) {
  87. print_thing(j);
  88. j++;
  89. } else {
  90. printf("\033[0m\n");
  91. }
  92. }
  93. while (j < i) {
  94. for (int x = 0; x < gimp_image.width; x++) {
  95. printf(" ");
  96. }
  97. print_thing(j);
  98. j++;
  99. }
  100. }