worked through the printw_example exercise, added python version
This commit is contained in:
parent
a66477b05f
commit
b13831dc92
@ -1,17 +1,16 @@
|
|||||||
#include <ncurses.h> /* ncurses.h includes stdio.h */
|
#include <ncurses.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char mesg[]="Just a string"; /* message to be appeared on the screen */
|
char mesg[] = "Just a string";
|
||||||
int row,col; /* to store the number of rows and *
|
int row, col;
|
||||||
* the number of colums of the screen */
|
|
||||||
initscr(); /* start the curses mode */
|
initscr();
|
||||||
getmaxyx(stdscr,row,col); /* get the number of rows and columns */
|
getmaxyx(stdscr, row, col);
|
||||||
mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
|
mvprintw(row / 2, (col - strlen(mesg)) / 2, "%s", mesg);
|
||||||
/* print the message at the center of the screen */
|
mvprintw(row - 2, 0, "This screen has %d rows and %d columns\n", row, col);
|
||||||
mvprintw(row-2,0,"This screen has %d rows and %d columns\n",row,col);
|
printw("Try resizing your window (if possible) and then run this program again");
|
||||||
printw("Try resizing your window(if possible) and then run this program again");
|
|
||||||
refresh();
|
refresh();
|
||||||
getch();
|
getch();
|
||||||
endwin();
|
endwin();
|
||||||
|
25
basics/printw_example.py
Normal file
25
basics/printw_example.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import sys
|
||||||
|
import curses
|
||||||
|
|
||||||
|
|
||||||
|
def printw_example(stdscr):
|
||||||
|
mesg = "Just a string"
|
||||||
|
row, col = stdscr.getmaxyx()
|
||||||
|
stdscr.addstr(row / 2, (col - len(mesg)) / 2, mesg)
|
||||||
|
stdscr.addstr(row - 2, 0, "This screen has {0} rows and {1} "
|
||||||
|
"columns\n".format(row, col))
|
||||||
|
stdscr.addstr(row - 1, 0, "Try resizing your window (if possible) and then"
|
||||||
|
"run this program again")
|
||||||
|
stdscr.refresh()
|
||||||
|
stdscr.getch()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
curses.wrapper(printw_example)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
|
|
||||||
|
# vim:filetype=python
|
Loading…
x
Reference in New Issue
Block a user