|
@@ -0,0 +1,107 @@
|
|
|
|
|
+/* vcc/pretty.c
|
|
|
|
|
+ *
|
|
|
|
|
+ * This file is part of vcc.
|
|
|
|
|
+ *
|
|
|
|
|
+ * vcc is free software: you can redistribute it and/or modify
|
|
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
|
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
+ * (at your option) any later version.
|
|
|
|
|
+ *
|
|
|
|
|
+ * vcc is distributed in the hope that it will be useful,
|
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
|
+ *
|
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
|
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#include <stdio.h>
|
|
|
|
|
+#include <string.h>
|
|
|
|
|
+
|
|
|
|
|
+#include <vcc/vcc.h>
|
|
|
|
|
+#include <vcc/version.h>
|
|
|
|
|
+#include <vcc/pretty.h>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+struct theme theme_def = {
|
|
|
|
|
+ .usrname = {
|
|
|
|
|
+ .fg = FG_LIGHTBLUE,
|
|
|
|
|
+ .bg = BG_BLACK,
|
|
|
|
|
+ .mode = MODE_LINE
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ .sysusername = {
|
|
|
|
|
+ .fg = FG_RED,
|
|
|
|
|
+ .bg = BG_BLACK,
|
|
|
|
|
+ .mode = MODE_LINE
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ .msg = {
|
|
|
|
|
+ .fg = FG_YELLOW,
|
|
|
|
|
+ .bg = BG_BLACK,
|
|
|
|
|
+ .mode = MODE_HIGHLIGHT
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ .sysmsg = {
|
|
|
|
|
+ .fg = FG_GREEN,
|
|
|
|
|
+ .bg = BG_BLACK,
|
|
|
|
|
+ .mode = MODE_HIGHLIGHT
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+struct theme *current_theme = &theme_def;
|
|
|
|
|
+
|
|
|
|
|
+#define curr_usrname (¤t_theme->usrname)
|
|
|
|
|
+#define curr_sysusername (¤t_theme->sysusername)
|
|
|
|
|
+#define curr_msg (¤t_theme->msg)
|
|
|
|
|
+#define curr_sysmsg (¤t_theme->sysmsg)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+int pretty_new_msg(char *usrname, char *buf) {
|
|
|
|
|
+ ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
|
|
|
|
|
+
|
|
|
|
|
+ if (unlikely(!strcmp(usrname, "system"))) {
|
|
|
|
|
+ setcolor(stdout, curr_sysusername);
|
|
|
|
|
+ printf("\rsystem");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else {
|
|
|
|
|
+ setcolor(stdout, curr_usrname);
|
|
|
|
|
+ printf("\r%s", usrname);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ansi_csi_ed(stdout);
|
|
|
|
|
+
|
|
|
|
|
+ printf("@: ");
|
|
|
|
|
+
|
|
|
|
|
+ if (unlikely(!strcmp(usrname, "system"))) {
|
|
|
|
|
+ setcolor(stdout, curr_sysmsg);
|
|
|
|
|
+
|
|
|
|
|
+ printf("%s", buf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else {
|
|
|
|
|
+ setcolor(stdout, curr_msg);
|
|
|
|
|
+ printf("%s", buf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ansi_csi_ed(stdout);
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int pretty_prompt(char *usrname) {
|
|
|
|
|
+ ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
|
|
|
|
|
+ setcolor(stderr, curr_usrname);
|
|
|
|
|
+ fprintf(stderr, "%s", usrname);
|
|
|
|
|
+
|
|
|
|
|
+ ansi_csi_ed(stderr);
|
|
|
|
|
+ fprintf(stderr, "$: ");
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|