/examples/curses.winxed
http://github.com/NotFound/winxed · Unknown · 157 lines · 140 code · 17 blank · 0 comment · 0 complexity · 56c2a147ba6908c2f61093341122534a MD5 · raw file
- #! winxed
- class Window
- {
- var win;
- var panel;
- function getmaxx()
- {
- using Curses.getmaxx;
- int x= getmaxx(self.win);
- return x;
- }
- function getmaxy()
- {
- using Curses.getmaxy;
- int y= getmaxy(self.win);
- return y;
- }
- function clear()
- {
- using Curses.wclear;
- wclear(self.win);
- }
- function mvaddstr(int y, int x, string s)
- {
- using Curses.mvwaddstr;
- mvwaddstr(self.win, y, x, s);
- }
- function getch()
- {
- using Curses.wgetch;
- string s= wgetch(self.win);
- return s;
- }
- function box(int verch, int horch)
- {
- using Curses.box;
- box(self.win, verch, horch);
- }
- function new_panel(int lines, int cols, int y, int x)
- {
- using Curses.derwin;
- using Curses.new_panel;
- var newwindow= new Window;
- var winscr = derwin(self.win, lines, cols, y, x);
- var panel= new_panel(winscr);
- newwindow.panel= panel;
- newwindow.win= winscr;
- return newwindow;
- }
- function top_panel()
- {
- using Curses.top_panel;
- top_panel(self.panel);
- }
- }
- class Screen : Window
- {
- function init [vtable]()
- {
- using extern Curses;
- using Curses.initscr;
- say('Hi');
- var win= initscr();
- self.win= win;
- }
- function endwin()
- {
- using Curses.endwin;
- endwin();
- }
- }
- function panel1(var p)
- {
- p.clear();
- p.box(0, 0);
- p.mvaddstr(2, 6, 'Uuuuh!');
- }
- function panel2(var p2, string s)
- {
- p2.clear();
- p2.box(0, 0);
- int width= p2.getmaxx();
- p2.mvaddstr(1, 1, substr(s, 0, width-3));
- }
- function test(scr, string s)
- {
- int maxx= scr.getmaxx();
- int maxy= scr.getmaxy();
- int l= length(s);
- int x = maxx - l;
- if (x < 0) x= 0;
- scr.mvaddstr(maxy / 2, x / 2, s);
- scr.getch();
- using Curses.update_panels;
- using Curses.doupdate;
- var p= scr.new_panel(maxy/2, maxx/2, maxy/4, maxx/4);
- panel1(p);
- update_panels();
- doupdate();
- p.getch();
- int width= l + 3;
- if( width > maxx) width= maxx;
- var p2= scr.new_panel(3, width, (maxy - 3)/2, (maxx - width) / 2);
- panel2(p2, s);
- update_panels();
- doupdate();
- p2.getch();
- p.top_panel();
- panel1(p);
- update_panels();
- doupdate();
- p.getch();
- p2.top_panel();
- panel2(p2, s);
- update_panels();
- doupdate();
- p2.getch();
- scr.endwin();
- say(maxx, ", ", maxy);
- }
- function main(args)
- {
- using extern Curses;
- using Curses.curses_version;
- say('Curses version: ', curses_version());
- string s;
- int argc = args;
- if (argc > 1) s= args[1];
- else s= 'Hello, world!';
- var scr;
- try {
- scr = new Screen;
- test(scr, s);
- }
- catch (e)
- {
- scr.endwin();
- throw e;
- }
- }