我想在屏幕上连续滚动文本。例如,
text = "Hello, how are you"
输出应该是:
你好 你好吗 你好 你好吗 你好 你好吗 你好 你好吗
并从右向左旋转。
到目前为止,我已经编译了这个:
#include <curses.h>
#include <unistd.h> // For sleep()
#include <string.h> // For strlen()
int main(int argc, char *argv[]) {
char *text = argv[1];
char *text = "Hello, how are you";
int text_length;
int i, max_x, max_y;
// Get text length
text_length = strlen(text);
// Initialize screen for ncurses
initscr();
// Don't show cursor
curs_set(0);
// Get terminal dimensions
// getmaxyx(stdscr, max_y, max_x);
// Clear the screen
clear();
// Scroll text back across the screen
while (1) {
getmaxyx(stdscr, max_y, max_x);
if ((max_x - text_length) <= 1)
i = max_x;
else
i = (max_x - text_length);
for (i; i > 0; i--) {
clear();
mvaddstr(0, i, text);
refresh();
usleep(20000);
}
}
// Wait for a keypress before quitting
getch();
endwin();
return 0;
}
Can anybody help to change the code and do that?