pretty.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* vcc/pretty.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <vcc/vcc.h>
  21. #include <vcc/version.h>
  22. #include <vcc/pretty.h>
  23. struct theme theme_def = {
  24. .usrname = {
  25. .fg = FG_LIGHTBLUE,
  26. .bg = BG_BLACK,
  27. .mode = MODE_LINE
  28. },
  29. .sysusername = {
  30. .fg = FG_RED,
  31. .bg = BG_BLACK,
  32. .mode = MODE_LINE
  33. },
  34. .msg = {
  35. .fg = FG_YELLOW,
  36. .bg = BG_BLACK,
  37. .mode = MODE_HIGHLIGHT
  38. },
  39. .sysmsg = {
  40. .fg = FG_GREEN,
  41. .bg = BG_BLACK,
  42. .mode = MODE_HIGHLIGHT
  43. }
  44. };
  45. struct theme *current_theme = &theme_def;
  46. #define curr_usrname (&current_theme->usrname)
  47. #define curr_sysusername (&current_theme->sysusername)
  48. #define curr_msg (&current_theme->msg)
  49. #define curr_sysmsg (&current_theme->sysmsg)
  50. int pretty_new_msg(char *usrname, char *buf) {
  51. ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
  52. if (unlikely(!strcmp(usrname, "system"))) {
  53. setcolor(stdout, curr_sysusername);
  54. printf("\rsystem");
  55. }
  56. else {
  57. setcolor(stdout, curr_usrname);
  58. printf("\r%s", usrname);
  59. }
  60. ansi_csi_ed(stdout);
  61. printf("@: ");
  62. if (unlikely(!strcmp(usrname, "system"))) {
  63. setcolor(stdout, curr_sysmsg);
  64. printf("%s", buf);
  65. }
  66. else {
  67. setcolor(stdout, curr_msg);
  68. printf("%s", buf);
  69. }
  70. ansi_csi_ed(stdout);
  71. return 0;
  72. }
  73. int pretty_prompt(char *usrname) {
  74. ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
  75. setcolor(stderr, curr_usrname);
  76. fprintf(stderr, "%s", usrname);
  77. ansi_csi_ed(stderr);
  78. fprintf(stderr, "$: ");
  79. return 0;
  80. }