-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
69 lines (52 loc) · 1.22 KB
/
main.c
File metadata and controls
69 lines (52 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <ncursesw/curses.h>
#include <string.h>
int MidCol(int cols, int quoteLen)
{
// Calculate Columns middle
int colsMid = cols / 2;
// Quote offset
int offset = quoteLen / 2;
return colsMid - offset;
}
int MidRow(int rows)
{
return rows / 2;
}
void PrintQuote(const char* quote, int quoteLen)
{
// Get the terminal width and height
int rows, cols = 0;
getmaxyx(stdscr, rows, cols);
// Get the mid point of terminal and move the cursor there
move(MidRow(rows), MidCol(cols, quoteLen));
// Print the quote
addstr(quote);
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Please read the man page for proper usage!\n");
return 1;
}
// Initializing ncurses mode
initscr();
// Clear the screen
clear();
// Move the cursor to the top left corner of the terminal
move(0,0);
// Calculate quote length
int quoteLen = strlen(argv[1]);
// Print the quote to screen
PrintQuote(argv[1], quoteLen);
// Hide the cursor
curs_set(0);
// Flush/Apply the changes to the actual terminal
refresh();
// Wait for any character input
getch();
// End ncurses mode and restore the previous terminal state
endwin();
return 0;
}