In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use Linux ncurses", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this "how to use Linux ncurses" article.
Ncurses (new curses) is a set of programming libraries that provide a series of functions for users to call to generate a text-based user interface. The n in the name ncurses means "new" because it is the free software version of curses. Because of AT&T 's "infamous" copyright policy, people had to replace it with ncurses later.
Library files need to be installed on the ubuntu system to support ncurses:
Apt-get install libncurses5-dev
Initscr () function:
Initscr () is used to initialize the ncurses data structure and read the correct terminfo file. Memory will be allocated. If an error occurs, initscr returns ERR, otherwise it returns a pointer. In addition, the screen will be deleted and initialized.
Getyx () function:
The getyx () function can be used to get the position of the current cursor. And store it in the two variables passed to it.
Mvprintw () function:
Output at the specified coordinates
Refresh () function:
Update terminal screen
Endwin () function:
Endwin () clears all allocated resources in ncurses and restores the tty mode to the state it was before calling initscr (). It must be called before any other function in the ncurses library, and endwin () must be called before the program exits. When you want to output to multiple terminals, you can use newterm (...) instead of initscr ().
The following code enables a simulated "ball" to bounce back and forth on the screen. Code reference: [https://www.viget.com/articles/game-programming-in-c-with-the-ncurses-library/]
Source program:
# include # include # define DELAY 30000int main (int argc, char * argv []) {int x = 0poliint y = 0tint max_x = 0Maxonomy = 0int next_x = 0int direction = 1int initscr (); / * initialize the screen * / noecho (); / * no keys are returned on the screen * / curs_set (FALSE); / * do not display the cursor * / / * getmaxyx (stdscr, max_y, max_x) / * get screen size * / mvprintw (5, 5, "Hello, world!"); refresh (); / * Update display * / sleep (1); while (1) {getmaxyx (stdscr, max_y, max_x); / * get screen size * / clear (); / * clear screen * / mvprintw (y, x, "O"); refresh (); usleep (DELAY); next_x = x + direction If (next_x > = max_x | | next_x else {x = x + direction;}} endwin (); / * restore terminal * /}
Makefile:
# Makefilecc=gccLDFLAGS=-lncursesSRCS: = $(wildcard * .c) TARGET: = $(SRCS:%.c=%) $(TARGET): $(SRCS) $(cc) $(LDFLAGS) $(SRCS)-o $(TARGET) clean:rm $(TARGET) the above is about "how to use Linux ncurses". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it. Please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.