1 /**
2  * Consoleur: a package for interaction with character-oriented terminal emulators
3  *
4  * Copyright: Maxim Freck, 2017.
5  * Authors:   Maxim Freck <maxim@freck.pp.ru>
6  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  */
8 module consoleur.screen.posix;
9 version(Posix) {
10 	
11 import consoleur.core;
12 
13 /*******
14  * Returns: current screen rows and columns count
15  */
16 Point getScreenSize() @trusted
17 {
18 	import core.sys.posix.sys.ioctl: ioctl, TIOCGWINSZ, winsize;
19 	winsize w;
20 	ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
21 	return Point(w.ws_row, w.ws_col);
22 }
23 
24 /*******
25  * Clears screen
26  *
27  * Returns: true on success, false otherwise
28  */
29 bool clearScreen() @safe
30 {
31 	import consoleur.commands: invokeCommand, TermCommand;
32 	return invokeCommand(TermCommand.clearScreen);
33 }
34 
35 /*******
36  * Enters cup mode
37  * Returns: false if option is not available, otherwise true
38  */
39 bool enterFullscreen() @safe
40 {
41 	import consoleur.commands: invokeCommand, TermCommand;
42 	return invokeCommand(TermCommand.enterCa);
43 }
44 
45 /*******
46  * Leaves cup mode
47  * Returns: false if option is not available, otherwise true
48  */
49 bool exitFullscreen() @safe
50 {
51 	import consoleur.commands: invokeCommand, TermCommand;
52 	return invokeCommand(TermCommand.exitCa);
53 }
54 
55 
56 
57 import core.sys.posix.signal;
58 
59 private enum SIGWINCH = 28;
60 
61 private sigaction_t oldSigWinch;
62 
63 private extern(C) void resizeHandle(int sigNumber) @safe
64 {
65 	//pushStdin("w084[\x1b");
66 	pushStdin("\x1b[480w");
67 }
68 
69 shared static this()
70 {
71 	sigaction_t n;
72 	n.sa_handler = &resizeHandle;
73 	n.sa_mask = cast(sigset_t) 0;
74 	n.sa_flags = 0;
75 	sigaction(SIGWINCH, &n, &oldSigWinch);
76 }
77 
78 shared static ~this()
79 {
80 	sigaction(SIGWINCH, &oldSigWinch, null);
81 }
82 
83 }