about summary refs log tree commit diff stats
path: root/src/ui/inputwin.h
blob: f49a6a76315c53b6785c83f820a8c8dbd88a624b (plain) (blame)
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
/*
 * inputwin.c
 *
 * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#ifndef UI_INPUTWIN_H
#define UI_INPUTWIN_H

#include <glib.h>

#define INP_WIN_MAX 1000

void create_input_window(void);
char* inp_readline(void);
void inp_nonblocking(gboolean reset);
void inp_close(void);
void inp_win_clear(void);
void inp_win_resize(void);
void inp_put_back(void);
char* inp_get_password(void);

#endif
lass="o">**keywords): if dictionary is not None: dict.__init__(self, dictionary) else: dict.__init__(self, keywords) if 'to' in self: self['down'] = self['to'] self['absolute'] = True def copy(self): return Direction(**self) def _get_bool(self, first, second, fallback=None): try: return self[first] except: try: return not self[second] except: return fallback def _get_direction(self, first, second, fallback=0): try: return self[first] except: try: return -self[second] except: return fallback def up(self): return -Direction.down(self) def down(self): return Direction._get_direction(self, 'down', 'up') def right(self): return Direction._get_direction(self, 'right', 'left') def absolute(self): return Direction._get_bool(self, 'absolute', 'relative') def left(self): return -Direction.right(self) def relative(self): return not Direction.absolute(self) def vertical_direction(self): down = Direction.down(self) return (down > 0) - (down < 0) def horizontal_direction(self): right = Direction.right(self) return (right > 0) - (right < 0) def vertical(self): return set(self) & set(['up', 'down']) def horizontal(self): return set(self) & set(['left', 'right']) def pages(self): return 'pages' in self and self['pages'] def percentage(self): return 'percentage' in self and self['percentage'] def multiply(self, n): for key in ('up', 'right', 'down', 'left'): try: self[key] *= n except: pass def set(self, n): for key in ('up', 'right', 'down', 'left'): if key in self: self[key] = n def move(self, direction, override=None, minimum=0, maximum=9999, current=0, pagesize=1, offset=0): """Calculates the new position in a given boundary. Example: >>> d = Direction(pages=True) >>> d.move(direction=3) 3 >>> d.move(direction=3, current=2) 5 >>> d.move(direction=3, pagesize=5) 15 >>> # Note: we start to count at zero. >>> d.move(direction=3, pagesize=5, maximum=10) 9 >>> d.move(direction=9, override=2) 18 """ pos = direction if override is not None: if self.absolute(): pos = override else: pos *= override if self.pages(): pos *= pagesize elif self.percentage(): pos *= maximum / 100.0 if self.absolute(): if pos < minimum: pos += maximum else: pos += current return int(max(min(pos, maximum + offset - 1), minimum)) def select(self, lst, current, pagesize, override=None, offset=1): dest = self.move(direction=self.down(), override=override, current=current, pagesize=pagesize, minimum=0, maximum=len(lst)+1) selection = lst[min(current, dest):max(current, dest) + offset] return dest + offset - 1, selection if __name__ == '__main__': import doctest doctest.testmod()