1 module aurorafw.cli.terminal.window; 2 3 import aurorafw.cli.terminal.terminal; 4 5 import riverd.ncurses; 6 7 import std.exception; 8 9 class TerminalWindowException : Exception { 10 mixin basicExceptionCtors; 11 } 12 13 @safe 14 class TerminalWindow { 15 16 @trusted 17 this(TerminalWindow twin) 18 { 19 win = dupwin(twin.win); 20 21 if(win is null) 22 throw new TerminalWindowException("fail duplicating the window"); 23 } 24 25 @trusted 26 public this(int rows, int cols, int x, int y) 27 { 28 win = newwin(rows, cols, y, x); 29 box(win, 0, 0); 30 31 if (win is null) 32 throw new TerminalWindowException("fail creating new window"); 33 } 34 35 @trusted 36 public this(WINDOW* parent, int rows, int cols, int x, int y) 37 { 38 if (parent is null) 39 throw new TerminalWindowException("null WINDOW*"); 40 41 win = subwin(parent, rows, cols, y, x); 42 43 if(win is null) 44 throw new TerminalWindowException("fail creating a new subwindow"); 45 } 46 47 @trusted 48 ~this() 49 { 50 delwin(win); 51 } 52 53 @trusted 54 public void draw() 55 { 56 wrefresh(win); 57 } 58 59 60 pragma(inline, true) @trusted 61 final public int resize(int rows, int cols) 62 { 63 return wresize(win, rows, cols); 64 } 65 66 67 pragma(inline, true) @trusted 68 final public int move(int x, int y) 69 { 70 return mvwin(win, y, x); 71 } 72 73 private WINDOW* win; 74 }