Cleanup
This commit is contained in:
parent
a08e67d291
commit
59ef834383
145
Python/btui.py
145
Python/btui.py
@ -20,83 +20,84 @@ class BTUI_struct(ctypes.Structure):
|
||||
|
||||
libbtui.btui_enable.restype = ctypes.POINTER(BTUI_struct)
|
||||
|
||||
attr = lambda name: ctypes.c_longlong.in_dll(libbtui, name)
|
||||
attr_t = ctypes.c_longlong
|
||||
BTUI_ATTRS = {
|
||||
"normal": attr_t.in_dll(libbtui, 'BTUI_NORMAL'),
|
||||
"bold": attr_t.in_dll(libbtui, 'BTUI_BOLD'),
|
||||
"faint": attr_t.in_dll(libbtui, 'BTUI_FAINT'),
|
||||
"dim": attr_t.in_dll(libbtui, 'BTUI_FAINT'),
|
||||
"italic": attr_t.in_dll(libbtui, 'BTUI_ITALIC'),
|
||||
"underline": attr_t.in_dll(libbtui, 'BTUI_UNDERLINE'),
|
||||
"blink_slow": attr_t.in_dll(libbtui, 'BTUI_BLINK_SLOW'),
|
||||
"blink_fast": attr_t.in_dll(libbtui, 'BTUI_BLINK_FAST'),
|
||||
"reverse": attr_t.in_dll(libbtui, 'BTUI_REVERSE'),
|
||||
"conceal": attr_t.in_dll(libbtui, 'BTUI_CONCEAL'),
|
||||
"strikethrough": attr_t.in_dll(libbtui, 'BTUI_STRIKETHROUGH'),
|
||||
"fraktur": attr_t.in_dll(libbtui, 'BTUI_FRAKTUR'),
|
||||
"double_underline": attr_t.in_dll(libbtui, 'BTUI_DOUBLE_UNDERLINE'),
|
||||
"no_bold_or_faint": attr_t.in_dll(libbtui, 'BTUI_NO_BOLD_OR_FAINT'),
|
||||
"no_italic_or_fraktur": attr_t.in_dll(libbtui, 'BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"no_underline": attr_t.in_dll(libbtui, 'BTUI_NO_UNDERLINE'),
|
||||
"no_blink": attr_t.in_dll(libbtui, 'BTUI_NO_BLINK'),
|
||||
"no_reverse": attr_t.in_dll(libbtui, 'BTUI_NO_REVERSE'),
|
||||
"no_conceal": attr_t.in_dll(libbtui, 'BTUI_NO_CONCEAL'),
|
||||
"no_strikethrough": attr_t.in_dll(libbtui, 'BTUI_NO_STRIKETHROUGH'),
|
||||
"fg_black": attr_t.in_dll(libbtui, 'BTUI_FG_BLACK'),
|
||||
"fg_red": attr_t.in_dll(libbtui, 'BTUI_FG_RED'),
|
||||
"fg_green": attr_t.in_dll(libbtui, 'BTUI_FG_GREEN'),
|
||||
"fg_yellow": attr_t.in_dll(libbtui, 'BTUI_FG_YELLOW'),
|
||||
"fg_blue": attr_t.in_dll(libbtui, 'BTUI_FG_BLUE'),
|
||||
"fg_magenta": attr_t.in_dll(libbtui, 'BTUI_FG_MAGENTA'),
|
||||
"fg_cyan": attr_t.in_dll(libbtui, 'BTUI_FG_CYAN'),
|
||||
"fg_white": attr_t.in_dll(libbtui, 'BTUI_FG_WHITE'),
|
||||
"fg_normal": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"bg_black": attr_t.in_dll(libbtui, 'BTUI_BG_BLACK'),
|
||||
"bg_red": attr_t.in_dll(libbtui, 'BTUI_BG_RED'),
|
||||
"bg_green": attr_t.in_dll(libbtui, 'BTUI_BG_GREEN'),
|
||||
"bg_yellow": attr_t.in_dll(libbtui, 'BTUI_BG_YELLOW'),
|
||||
"bg_blue": attr_t.in_dll(libbtui, 'BTUI_BG_BLUE'),
|
||||
"bg_magenta": attr_t.in_dll(libbtui, 'BTUI_BG_MAGENTA'),
|
||||
"bg_cyan": attr_t.in_dll(libbtui, 'BTUI_BG_CYAN'),
|
||||
"bg_white": attr_t.in_dll(libbtui, 'BTUI_BG_WHITE'),
|
||||
"bg_normal": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"framed": attr_t.in_dll(libbtui, 'BTUI_FRAMED'),
|
||||
"encircled": attr_t.in_dll(libbtui, 'BTUI_ENCIRCLED'),
|
||||
"overlined": attr_t.in_dll(libbtui, 'BTUI_OVERLINED'),
|
||||
"normal": attr('BTUI_NORMAL'),
|
||||
"bold": attr('BTUI_BOLD'),
|
||||
"faint": attr('BTUI_FAINT'),
|
||||
"dim": attr('BTUI_FAINT'),
|
||||
"italic": attr('BTUI_ITALIC'),
|
||||
"underline": attr('BTUI_UNDERLINE'),
|
||||
"blink_slow": attr('BTUI_BLINK_SLOW'),
|
||||
"blink_fast": attr('BTUI_BLINK_FAST'),
|
||||
"reverse": attr('BTUI_REVERSE'),
|
||||
"conceal": attr('BTUI_CONCEAL'),
|
||||
"strikethrough": attr('BTUI_STRIKETHROUGH'),
|
||||
"fraktur": attr('BTUI_FRAKTUR'),
|
||||
"double_underline": attr('BTUI_DOUBLE_UNDERLINE'),
|
||||
"no_bold_or_faint": attr('BTUI_NO_BOLD_OR_FAINT'),
|
||||
"no_italic_or_fraktur": attr('BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"no_underline": attr('BTUI_NO_UNDERLINE'),
|
||||
"no_blink": attr('BTUI_NO_BLINK'),
|
||||
"no_reverse": attr('BTUI_NO_REVERSE'),
|
||||
"no_conceal": attr('BTUI_NO_CONCEAL'),
|
||||
"no_strikethrough": attr('BTUI_NO_STRIKETHROUGH'),
|
||||
"fg_black": attr('BTUI_FG_BLACK'),
|
||||
"fg_red": attr('BTUI_FG_RED'),
|
||||
"fg_green": attr('BTUI_FG_GREEN'),
|
||||
"fg_yellow": attr('BTUI_FG_YELLOW'),
|
||||
"fg_blue": attr('BTUI_FG_BLUE'),
|
||||
"fg_magenta": attr('BTUI_FG_MAGENTA'),
|
||||
"fg_cyan": attr('BTUI_FG_CYAN'),
|
||||
"fg_white": attr('BTUI_FG_WHITE'),
|
||||
"fg_normal": attr('BTUI_FG_NORMAL'),
|
||||
"bg_black": attr('BTUI_BG_BLACK'),
|
||||
"bg_red": attr('BTUI_BG_RED'),
|
||||
"bg_green": attr('BTUI_BG_GREEN'),
|
||||
"bg_yellow": attr('BTUI_BG_YELLOW'),
|
||||
"bg_blue": attr('BTUI_BG_BLUE'),
|
||||
"bg_magenta": attr('BTUI_BG_MAGENTA'),
|
||||
"bg_cyan": attr('BTUI_BG_CYAN'),
|
||||
"bg_white": attr('BTUI_BG_WHITE'),
|
||||
"bg_normal": attr('BTUI_BG_NORMAL'),
|
||||
"framed": attr('BTUI_FRAMED'),
|
||||
"encircled": attr('BTUI_ENCIRCLED'),
|
||||
"overlined": attr('BTUI_OVERLINED'),
|
||||
}
|
||||
|
||||
BTUI_INVERSE_ATTRS = {
|
||||
"normal": attr_t.in_dll(libbtui, 'BTUI_NORMAL'),
|
||||
"bold": attr_t.in_dll(libbtui, 'BTUI_NO_BOLD_OR_FAINT'),
|
||||
"faint": attr_t.in_dll(libbtui, 'BTUI_NO_BOLD_OR_FAINT'),
|
||||
"dim": attr_t.in_dll(libbtui, 'BTUI_NO_BOLD_OR_FAINT'),
|
||||
"italic": attr_t.in_dll(libbtui, 'BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"underline": attr_t.in_dll(libbtui, 'BTUI_NO_UNDERLINE'),
|
||||
"blink_slow": attr_t.in_dll(libbtui, 'BTUI_NO_BLINK'),
|
||||
"blink_fast": attr_t.in_dll(libbtui, 'BTUI_NO_BLINK'),
|
||||
"reverse": attr_t.in_dll(libbtui, 'BTUI_NO_REVERSE'),
|
||||
"conceal": attr_t.in_dll(libbtui, 'BTUI_NO_CONCEAL'),
|
||||
"strikethrough": attr_t.in_dll(libbtui, 'BTUI_NO_STRIKETHROUGH'),
|
||||
"fraktur": attr_t.in_dll(libbtui, 'BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"double_underline": attr_t.in_dll(libbtui, 'BTUI_NO_UNDERLINE'),
|
||||
"fg_black": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_red": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_green": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_yellow": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_blue": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_magenta": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_cyan": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_white": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"fg_normal": attr_t.in_dll(libbtui, 'BTUI_FG_NORMAL'),
|
||||
"bg_black": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_red": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_green": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_yellow": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_blue": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_magenta": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_cyan": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_white": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"bg_normal": attr_t.in_dll(libbtui, 'BTUI_BG_NORMAL'),
|
||||
"normal": attr('BTUI_NORMAL'),
|
||||
"bold": attr('BTUI_NO_BOLD_OR_FAINT'),
|
||||
"faint": attr('BTUI_NO_BOLD_OR_FAINT'),
|
||||
"dim": attr('BTUI_NO_BOLD_OR_FAINT'),
|
||||
"italic": attr('BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"underline": attr('BTUI_NO_UNDERLINE'),
|
||||
"blink_slow": attr('BTUI_NO_BLINK'),
|
||||
"blink_fast": attr('BTUI_NO_BLINK'),
|
||||
"reverse": attr('BTUI_NO_REVERSE'),
|
||||
"conceal": attr('BTUI_NO_CONCEAL'),
|
||||
"strikethrough": attr('BTUI_NO_STRIKETHROUGH'),
|
||||
"fraktur": attr('BTUI_NO_ITALIC_OR_FRAKTUR'),
|
||||
"double_underline": attr('BTUI_NO_UNDERLINE'),
|
||||
"fg_black": attr('BTUI_FG_NORMAL'),
|
||||
"fg_red": attr('BTUI_FG_NORMAL'),
|
||||
"fg_green": attr('BTUI_FG_NORMAL'),
|
||||
"fg_yellow": attr('BTUI_FG_NORMAL'),
|
||||
"fg_blue": attr('BTUI_FG_NORMAL'),
|
||||
"fg_magenta": attr('BTUI_FG_NORMAL'),
|
||||
"fg_cyan": attr('BTUI_FG_NORMAL'),
|
||||
"fg_white": attr('BTUI_FG_NORMAL'),
|
||||
"fg_normal": attr('BTUI_FG_NORMAL'),
|
||||
"bg_black": attr('BTUI_BG_NORMAL'),
|
||||
"bg_red": attr('BTUI_BG_NORMAL'),
|
||||
"bg_green": attr('BTUI_BG_NORMAL'),
|
||||
"bg_yellow": attr('BTUI_BG_NORMAL'),
|
||||
"bg_blue": attr('BTUI_BG_NORMAL'),
|
||||
"bg_magenta": attr('BTUI_BG_NORMAL'),
|
||||
"bg_cyan": attr('BTUI_BG_NORMAL'),
|
||||
"bg_white": attr('BTUI_BG_NORMAL'),
|
||||
"bg_normal": attr('BTUI_BG_NORMAL'),
|
||||
};
|
||||
|
||||
|
||||
|
74
README.md
74
README.md
@ -128,26 +128,26 @@ require("btui")(function(bt)
|
||||
...
|
||||
end)
|
||||
|
||||
bt:enable() -- Enables btui (if previously disabled)
|
||||
bt:disable() -- Disables btui
|
||||
bt:withdisabled(fn) -- Calls "fn" with btui disabled, then re-enables btui
|
||||
bt:getkey(timeout=-1) -- Returns a keypress (and optionally, mouse x and y coordinates). The optional timeout argument specifies how long, in tenths of a second, to wait for the next keypress.
|
||||
bt:write() -- Write text to the terminal
|
||||
bt:clear(type="screen") -- Clear the terminal. Options are: "screen", "right", "left", "above", "below", "line"
|
||||
bt:flush() -- Flush the terminal output. Most operations do this anyways.
|
||||
bt:move(x, y) -- Move the cursor to the given position. (0,0) is the top left corner.
|
||||
-- R,G,B values are in the range [0.0, 1.0]:
|
||||
bt:withfg(r,g,b, fn) -- Set the foreground color to (r,g,b), call fn, then reset the foreground color to default
|
||||
bt:withbg(r,g,b, fn) -- Set the background color to (r,g,b), call fn, then reset the background color to default
|
||||
bt:linebox(x,y,w,h) -- Draw an outlined box around the given rectangle
|
||||
bt:disable() -- Disables btui
|
||||
bt:enable() -- Enables btui (if previously disabled)
|
||||
bt:fillbox(x,y,w,h) -- Fill the given rectangle with space characters
|
||||
bt:shadow(x,y,w,h) -- Draw a shaded shadow to the bottom right of the given rectangle
|
||||
bt:withattributes(attrs..., fn) -- Set the given attributes, call fn, then unset them
|
||||
bt:setattributes(attrs...) -- Set the given attributes
|
||||
bt:unsetattributes(attrs...) -- Unset the given attributes
|
||||
bt:suspend() -- Suspend the current process and drop back into normal terminal mode
|
||||
bt:width() -- Return the scren width
|
||||
bt:flush() -- Flush the terminal output. Most operations do this anyways.
|
||||
bt:getkey(timeout=-1) -- Returns a keypress (and optionally, mouse x and y coordinates). The optional timeout argument specifies how long, in tenths of a second, to wait for the next keypress.
|
||||
bt:height() -- Return the screen height
|
||||
bt:linebox(x,y,w,h) -- Draw an outlined box around the given rectangle
|
||||
bt:move(x, y) -- Move the cursor to the given position. (0,0) is the top left corner.
|
||||
bt:setattributes(attrs...) -- Set the given attributes
|
||||
bt:shadow(x,y,w,h) -- Draw a shaded shadow to the bottom right of the given rectangle
|
||||
bt:suspend() -- Suspend the current process and drop back into normal terminal mode
|
||||
bt:unsetattributes(attrs...) -- Unset the given attributes
|
||||
bt:width() -- Return the scren width
|
||||
bt:withattributes(attrs..., fn) -- Set the given attributes, call fn, then unset them
|
||||
-- R,G,B values are in the range [0.0, 1.0]:
|
||||
bt:withbg(r,g,b, fn) -- Set the background color to (r,g,b), call fn, then reset the background color to default
|
||||
bt:withdisabled(fn) -- Calls "fn" with btui disabled, then re-enables btui
|
||||
bt:withfg(r,g,b, fn) -- Set the foreground color to (r,g,b), call fn, then reset the foreground color to default
|
||||
bt:write() -- Write text to the terminal
|
||||
```
|
||||
|
||||
See [Lua/test.lua](Lua/test.lua) for example usage. Run `make lua` to build the
|
||||
@ -169,34 +169,34 @@ The returned object has the following methods:
|
||||
|
||||
```python
|
||||
class BTUI:
|
||||
def enable(self):
|
||||
@contextmanager
|
||||
def attributes(self, *attrs):
|
||||
@contextmanager
|
||||
def bg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
||||
def clear(self, mode='screen'):
|
||||
def disable(self):
|
||||
@contextmanager
|
||||
def disabled(self):
|
||||
def draw_shadow(self, x, y, w, h):
|
||||
def enable(self):
|
||||
@contextmanager
|
||||
def fg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
||||
def fill_box(self, x, y, w, h):
|
||||
def flush(self):
|
||||
def getkey(self, timeout=None): # returns key, mouse_x, mouse_y
|
||||
@property
|
||||
def width(self):
|
||||
@property
|
||||
def height(self):
|
||||
def move(self, x, y):
|
||||
def outline_box(self, x, y, w, h):
|
||||
def set_attributes(self, *attrs):
|
||||
def set_bg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
||||
def set_fg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
||||
def suspend(self):
|
||||
def unset_attributes(self, *attrs):
|
||||
@property
|
||||
def width(self):
|
||||
def write(self, *args, sep=''):
|
||||
def write_bytes(self, b):
|
||||
def move(self, x, y):
|
||||
def flush(self):
|
||||
def suspend(self):
|
||||
def clear(self, mode='screen'):
|
||||
def set_attributes(self, *attrs):
|
||||
def unset_attributes(self, *attrs):
|
||||
@contextmanager
|
||||
def attributes(self, *attrs):
|
||||
def set_fg(self, r, g, b):
|
||||
def set_bg(self, r, g, b):
|
||||
@contextmanager
|
||||
def fg(self, r, g, b):
|
||||
@contextmanager
|
||||
def bg(self, r, g, b):
|
||||
def outline_box(self, x, y, w, h):
|
||||
def fill_box(self, x, y, w, h):
|
||||
def draw_shadow(self, x, y, w, h):
|
||||
```
|
||||
|
||||
See [Python/test.py](Python/test.py) for example code, which can be run with
|
||||
|
Loading…
Reference in New Issue
Block a user