colors: fix crash on unavailable default color
This commit is contained in:
parent
3f2792d359
commit
217abe2f28
|
@ -1,7 +1,6 @@
|
|||
TODO
|
||||
----------------------------------------
|
||||
setup.py
|
||||
make client cert gen configurable
|
||||
mac bug: arrows in cli are off
|
||||
|
||||
|
||||
|
||||
|
|
66
README.md
66
README.md
|
@ -30,32 +30,78 @@ Why use Bebop instead of something else?
|
|||
- Nice keybinds are defined, and Vim users should get quickly familiar with
|
||||
them.
|
||||
- Fun! Link navigation is done by entering the link ID with automatic
|
||||
validation: if there are less than 10 links on a page, pressing the link ID
|
||||
will take you to the page directly. If there are 30 links, pressing "1" will
|
||||
wait for another digit. If there are 1000 links but you wish to visit link
|
||||
5, pressing 5 and enter will do. Of course this is based on my own
|
||||
perception of what exactly makes a client "fun" to use, but give it a shot!
|
||||
validation so you can just smash your numpad to take your ship to unknown
|
||||
places (see usage section below for details).
|
||||
- History, cache, client certificates, bookmarks (it's just a text file with
|
||||
bindings), downloads and more!
|
||||
|
||||
You can check out the Bebop page on Gemini at gemini://dece.space/dev/bebop.gmi,
|
||||
or [this board](BOARD.txt) for what's done and what might be cooking.
|
||||
|
||||
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
TODO
|
||||
```bash
|
||||
pip3 install bebop-browser
|
||||
```
|
||||
|
||||
Now for platform specific info…
|
||||
|
||||
### Linux
|
||||
|
||||
Linux is the main platform I can test so you should be good to go, and don't
|
||||
hesitate to report issues.
|
||||
|
||||
### BSD
|
||||
|
||||
I don't know! Let me know your experience with it if you did try it.
|
||||
|
||||
### macOS
|
||||
|
||||
It should work on macOS like on other UNIX-like systems. I have limited access
|
||||
to devices running macOS so cross your fingers… The main difference I've seen is
|
||||
that some keys may behave a bit differently and that text attributes such as
|
||||
italics or dim may not work.
|
||||
|
||||
### Windows
|
||||
|
||||
Bebop relies heavily on ncurses to display its content to the terminal, and it
|
||||
does not work great on Windows. You need to install the curses support
|
||||
separately as most Python distributions on Windows do not have it: the package
|
||||
`windows-curses` on PyPI seems to work here.
|
||||
|
||||
Seems like there is no color support out of the box nor text attributes. It
|
||||
works OK in cmd.exe, but it feels completely broken on Windows Terminal.
|
||||
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Just run `bebop`, optionally following by an URL.
|
||||
Just run `bebop`, optionally following by an URL (`bebop -h` to see options). I
|
||||
have it aliased to "bop" but that is up to you.
|
||||
|
||||
Documentation about the keybinds, config values and commands are embed into the
|
||||
software itself: press "?" to display the help page.
|
||||
|
||||
The first thing you will want to get used to is the link navigation. All links
|
||||
have an ID written before them and you press the corresponding number to access
|
||||
it. If there are less than 10 links on a page, pressing the link ID will take
|
||||
you to the page directly. If there are 30 links, pressing "1" will wait for
|
||||
another digit. If there are 1000 links but you wish to visit link 5, pressing 5
|
||||
and enter will do.
|
||||
|
||||
There is an FAQ at `gemini://dece.space/dev/bebop.gmi` along with updates.
|
||||
|
||||
Happy browsing!
|
||||
|
||||
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Licensed under GPLv3.
|
||||
|
||||
Name comes from [this song][bop] which is good background music for browsing
|
||||
Gemini. Oh and Cowboy Bebop.
|
||||
|
||||
[bop]: https://www.youtube.com/watch?v=tWyUYAmmtNg
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Color definitions for curses."""
|
||||
|
||||
import curses
|
||||
import logging
|
||||
from enum import IntEnum
|
||||
|
||||
|
||||
|
@ -24,16 +25,22 @@ class ColorPair(IntEnum):
|
|||
A_ITALIC = curses.A_ITALIC if hasattr(curses, "A_ITALIC") else curses.A_NORMAL
|
||||
|
||||
|
||||
def init_colors():
|
||||
def init_colors(bg: int =-1):
|
||||
curses.use_default_colors()
|
||||
curses.init_pair(ColorPair.NORMAL, curses.COLOR_WHITE, -1)
|
||||
curses.init_pair(ColorPair.ERROR, curses.COLOR_RED, -1)
|
||||
curses.init_pair(ColorPair.LINK, curses.COLOR_CYAN, -1)
|
||||
curses.init_pair(ColorPair.LINK_ID, curses.COLOR_WHITE, -1)
|
||||
curses.init_pair(ColorPair.TITLE_1, curses.COLOR_GREEN, -1)
|
||||
curses.init_pair(ColorPair.TITLE_2, curses.COLOR_MAGENTA, -1)
|
||||
curses.init_pair(ColorPair.TITLE_3, curses.COLOR_MAGENTA, -1)
|
||||
curses.init_pair(ColorPair.PREFORMATTED, curses.COLOR_YELLOW, -1)
|
||||
curses.init_pair(ColorPair.BLOCKQUOTE, curses.COLOR_CYAN, -1)
|
||||
curses.init_pair(ColorPair.LINK_PREVIEW, curses.COLOR_WHITE, -1)
|
||||
curses.init_pair(ColorPair.DEBUG, curses.COLOR_BLACK, curses.COLOR_GREEN)
|
||||
try:
|
||||
curses.init_pair(ColorPair.NORMAL, curses.COLOR_WHITE, bg)
|
||||
curses.init_pair(ColorPair.ERROR, curses.COLOR_RED, bg)
|
||||
curses.init_pair(ColorPair.LINK, curses.COLOR_CYAN, bg)
|
||||
curses.init_pair(ColorPair.LINK_ID, curses.COLOR_WHITE, bg)
|
||||
curses.init_pair(ColorPair.TITLE_1, curses.COLOR_GREEN, bg)
|
||||
curses.init_pair(ColorPair.TITLE_2, curses.COLOR_MAGENTA, bg)
|
||||
curses.init_pair(ColorPair.TITLE_3, curses.COLOR_MAGENTA, bg)
|
||||
curses.init_pair(ColorPair.PREFORMATTED, curses.COLOR_YELLOW, bg)
|
||||
curses.init_pair(ColorPair.BLOCKQUOTE, curses.COLOR_CYAN, bg)
|
||||
curses.init_pair(ColorPair.LINK_PREVIEW, curses.COLOR_WHITE, bg)
|
||||
except curses.error:
|
||||
logging.error("Failed to init colors.")
|
||||
if bg == -1:
|
||||
logging.debug("Retrying with black background…")
|
||||
init_colors(bg=curses.COLOR_BLACK)
|
||||
|
|
Reference in a new issue