Blame view

ui.c 3.49 KB
ea1218f1   henyxia   UI finished
1
2
3
4
5
6
7
8
9
10
11
  #include <stdio.h>
  #include <sys/types.h>
  #include <unistd.h>
  #include <string.h>
  #include <time.h>
  #include "ui.h"
  
  #define	TIME_LENGTH			24
  #define	HEADER_TEXT_LENGTH	24
  #define	LOG_LINES			25
  #define	LOG_LENGTH			69
cdaa873f   henyxia   Log fixed
12
13
  #define	IPS					20
  #define	SCREEN_TIME			1000000/IPS
ea1218f1   henyxia   UI finished
14
15
16
17
18
19
20
  
  char	tmpretheader[HEADER_TEXT_LENGTH+1];
  char	tmpretlog[HEADER_TEXT_LENGTH+1];
  char	uilog[LOG_LINES][LOG_LENGTH];
  char	started[TIME_LENGTH];
  char	uid[HEADER_TEXT_LENGTH];
  char	uidDate[HEADER_TEXT_LENGTH];
cdaa873f   henyxia   Log fixed
21
22
23
24
25
26
27
28
29
30
31
32
33
  pid_t	mainPid;
  
  void* drawUI(void* we)
  {
  	while(1)
  	{
  		printf("\x1b[2J\x1b[1;1H");
  		displayUI();
  		usleep(SCREEN_TIME);
  	}
  
  	return NULL;
  }
ea1218f1   henyxia   UI finished
34
35
36
  
  void initUILog()
  {
cdaa873f   henyxia   Log fixed
37
38
39
40
  	tmpretheader[0]='\0';
  	tmpretlog[0]='\0';
  	started[0]='\0';
  	mainPid = getpid();
ea1218f1   henyxia   UI finished
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  	uid[0]='\0';
  	uidDate[0]='\0';
  	for(int i=0; i<LOG_LINES; i++)
  		uilog[i][0] = '\0';
  }
  
  char* fillHeaderWithSpaces(char* text)
  {
  	strcpy(tmpretheader, text);
  	while(strlen(tmpretheader) < HEADER_TEXT_LENGTH)
  		strcat(tmpretheader, " ");
  
  	return tmpretheader;
  }
  
  void addToLog(char* newStr)
  {
cdaa873f   henyxia   Log fixed
58
  	for(int i=LOG_LINES-2; i>=0; i--)
ea1218f1   henyxia   UI finished
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
85
86
87
88
89
90
91
  		strcpy(uilog[i+1], uilog[i]);
  	strcpy(uilog[0], newStr);
  }
  
  char* fillLogWithSpaces(char* text)
  {
  	strcpy(tmpretlog, text);
  	if(strlen(text) > 0)
  		while((strlen(tmpretlog)-12) < LOG_LENGTH)
  			strcat(tmpretlog, " ");
  	else
  		while(strlen(tmpretlog) < LOG_LENGTH)
  			strcat(tmpretlog, " ");
  
  	return tmpretlog;
  }
  
  
  void setStartTime(char* sT)
  {
  	strcpy(started, sT);
  }
  
  void displayUI()
  {
  	char	buffer[HEADER_TEXT_LENGTH];
  	//header
  	printf("\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n");
  	printf("\u2503 %s \u2503      T H E      \u2503", fillHeaderWithSpaces("Started since"));
     	printf(" %s \u2503\n", fillHeaderWithSpaces("No Tag Detected"));
  	printf("\u2503 %s \u2503    T W E E K    \u2503 ", fillHeaderWithSpaces(started));
  	sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
  	printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
cdaa873f   henyxia   Log fixed
92
  	sprintf(buffer, "PID %d", mainPid);
ea1218f1   henyxia   UI finished
93
94
95
96
97
98
  	printf("\u2503 %s \u2503  P R O J E C T  \u2503 ", fillHeaderWithSpaces(buffer));
  	sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
  	printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
  	printf("\u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n");
  	//body
  	for(int i=0; i<LOG_LINES; i++)
cdaa873f   henyxia   Log fixed
99
  		printf("\u2503 %s \u2503\n", fillLogWithSpaces(uilog[LOG_LINES-i-1]));
ea1218f1   henyxia   UI finished
100
101
  	printf("\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n");
  }