📄 display.c
字号:
#include "common.h"#include "display.h"#define MESSAGE_SIZE 40#define PLAY_SIZE 10#define TIME_SIZE 10#define TITLE_SIZE 4#define CHAPTER_SIZE 5#define DOMAIN_SIZE 6static int g_action_display = 1;static char g_display[MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE+DOMAIN_SIZE+1];static void display_clear (void) { // go one line up and delete the line. if (g_action_display) { printf ("%cM %c[2K", 0x1b, 0x1b); }}static void display (void){ int i; int space_pad; space_pad = 0; for (i = 0; i < MESSAGE_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE-1] = '-'; space_pad = 0; for (i = MESSAGE_SIZE; i < MESSAGE_SIZE+PLAY_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE+PLAY_SIZE-1] = '-'; space_pad = 0; for (i = MESSAGE_SIZE+PLAY_SIZE; i < MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE-1] = '-'; space_pad = 0; for (i = MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE; i < MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE-1] = '-'; space_pad = 0; for (i = MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE; i < MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE-1] = '-'; space_pad = 0; for (i = MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE; i < MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE+DOMAIN_SIZE; i++) { if (g_display[i] == '\0') { space_pad = 1; } if (space_pad) { g_display[i] = ' '; } } g_display[MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE+DOMAIN_SIZE] = '\n'; if (g_action_display) { printf (g_display); }}void display_init (void){ int i; for (i = 0; i < MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE; i++) { g_display[i] = ' '; }}void display_message (const char *str){ display_clear (); strncpy (g_display, str, MESSAGE_SIZE); display ();}void display_play_state (const char *str){ display_clear (); strncpy (g_display+MESSAGE_SIZE, str, PLAY_SIZE); display ();}void display_time (const char *str){ display_clear (); strncpy (g_display+MESSAGE_SIZE+PLAY_SIZE, str, TIME_SIZE); display ();}void display_title (const char *str){ display_clear (); strncpy (g_display+MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE, str, TITLE_SIZE); display ();}void display_chapter (const char *str){ display_clear (); strncpy (g_display+MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE, str, CHAPTER_SIZE); display ();}void display_domain (const char *str){ display_clear (); strncpy (g_display+MESSAGE_SIZE+PLAY_SIZE+TIME_SIZE+TITLE_SIZE+CHAPTER_SIZE, str, DOMAIN_SIZE); display ();}void display_disable (void){ g_action_display = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -