Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lyse
tt
Commits
0b25af71
Commit
0b25af71
authored
Sep 19, 2021
by
Lysander Trischler
Browse files
Read colors from config
parent
ceecd9d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
tt
View file @
0b25af71
...
...
@@ -19,6 +19,7 @@ except ImportError:
config
=
twtxtmanager
.
Config
.
load_file
()
manager
=
twtxtmanager
.
TwtxtManager
(
config
)
manager
.
load_twts
()
renderer
=
twtxtrenderer
.
Renderer
(
config
)
class
TwtsListBox
(
widgets
.
VimListBox
):
def
__init__
(
self
,
manager
,
cmdline
):
...
...
@@ -104,7 +105,7 @@ class TwtsListBox(widgets.VimListBox):
# Again, this should not happen at all!
mention
=
"@<?>"
markup
.
append
((
twtxt
renderer
.
mention_style
(
nick
,
following
),
mention
))
markup
.
append
((
renderer
.
mention_style
(
nick
,
following
),
mention
))
elif
isinstance
(
token
,
(
twtxtparser
.
TwtxtLink
,
twtxtparser
.
MarkdownLink
)):
if
token
.
title
:
...
...
@@ -150,8 +151,8 @@ class TwtsListBox(widgets.VimListBox):
(
28
,
urwid
.
Text
(
created_at
)),
(
self
.
_manager
.
max_author_nick_width
,
urwid
.
Text
(
nick
,
align
=
"right"
)),
text
]),
dividechars
=
2
),
twtxt
renderer
.
read_normal_map
if
twt
.
read
else
twtxt
renderer
.
unread_normal_map
,
twtxt
renderer
.
read_focus_map
if
twt
.
read
else
twtxt
renderer
.
unread_focus_map
),
renderer
.
read_normal_map
if
twt
.
read
else
renderer
.
unread_normal_map
,
renderer
.
read_focus_map
if
twt
.
read
else
renderer
.
unread_focus_map
),
next_indentation
)
...
...
@@ -211,8 +212,8 @@ class TwtsListBox(widgets.VimListBox):
pos
=
self
.
focus_position
row
=
self
.
body
[
pos
]
row
.
set_attr_map
(
twtxt
renderer
.
read_normal_map
if
twt
.
read
else
twtxt
renderer
.
unread_normal_map
)
row
.
set_focus_map
(
twtxt
renderer
.
read_focus_map
if
twt
.
read
else
twtxt
renderer
.
unread_focus_map
)
row
.
set_attr_map
(
renderer
.
read_normal_map
if
twt
.
read
else
renderer
.
unread_normal_map
)
row
.
set_focus_map
(
renderer
.
read_focus_map
if
twt
.
read
else
renderer
.
unread_focus_map
)
frame
.
header
.
original_widget
.
set_text
(
generate_header_text
())
...
...
@@ -308,7 +309,7 @@ class URLListBox(widgets.VimListBox):
bang
=
"#"
if
isinstance
(
token
,
twtxtparser
.
TwtxtLink
)
else
""
markup
.
append
(
"%s%s – "
%
(
bang
,
token
.
title
))
markup
.
append
((
"link-normal"
,
token
.
url
))
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
twtxt
renderer
.
read_normal_map
,
twtxt
renderer
.
read_focus_map
))
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
renderer
.
read_normal_map
,
renderer
.
read_focus_map
))
preferred_weighted_indices
.
append
((
1
,
len
(
self
.
_tokens
)
-
1
))
elif
isinstance
(
token
,
twtxtparser
.
SubjectHash
):
...
...
@@ -326,7 +327,7 @@ class URLListBox(widgets.VimListBox):
" – "
,
(
"link-normal"
,
url
),
hint
]
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
twtxt
renderer
.
read_normal_map
,
twtxt
renderer
.
read_focus_map
))
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
renderer
.
read_normal_map
,
renderer
.
read_focus_map
))
preferred_weighted_indices
.
append
((
3
,
len
(
self
.
_tokens
)
-
1
))
if
"conv"
not
in
url
:
...
...
@@ -336,7 +337,7 @@ class URLListBox(widgets.VimListBox):
(
"subject-normal"
,
token
.
hash
if
token
.
hash
else
"unknown subject hash"
),
" – "
,
(
"link-normal"
,
url
)]
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
twtxt
renderer
.
read_normal_map
,
twtxt
renderer
.
read_focus_map
))
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
renderer
.
read_normal_map
,
renderer
.
read_focus_map
))
preferred_weighted_indices
.
append
((
2
,
len
(
self
.
_tokens
)
-
1
))
elif
isinstance
(
token
,
twtxtparser
.
Mention
):
...
...
@@ -357,10 +358,10 @@ class URLListBox(widgets.VimListBox):
# doesn't need to recalculate everything
self
.
_tokens
.
append
(
self
.
Mention
(
nick
,
url
,
following
))
markup
=
[
"%2d: %s "
%
(
len
(
self
.
_tokens
),
"Following"
if
following
else
"Not following"
),
(
twtxt
renderer
.
mention_style
(
nick
,
following
),
"@%s"
%
nick
),
(
renderer
.
mention_style
(
nick
,
following
),
"@%s"
%
nick
),
" – "
,
(
"link-normal"
,
url
)]
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
twtxt
renderer
.
read_normal_map
,
twtxt
renderer
.
read_focus_map
))
items
.
append
(
widgets
.
SelectableAttrMap
(
urwid
.
Text
(
markup
),
renderer
.
read_normal_map
,
renderer
.
read_focus_map
))
preferred_weighted_indices
.
append
((
5
if
following
else
4
,
len
(
self
.
_tokens
)
-
1
))
...
...
@@ -502,5 +503,5 @@ def unhandled_input(key):
return
return
key
urwid
.
MainLoop
(
frame
,
twtxt
renderer
.
palette
,
unhandled_input
=
unhandled_input
).
run
()
urwid
.
MainLoop
(
frame
,
renderer
.
palette
,
unhandled_input
=
unhandled_input
).
run
()
twtxtrenderer.py
View file @
0b25af71
...
...
@@ -44,67 +44,73 @@ def normalize_whitespace_markup(markup):
return
markup
def
mention_style
(
nick
,
following
):
"""
Determine the Urwid text style for a mentioned twter depending on whether
we follow them or not.
"""
class
Renderer
:
def
__init__
(
self
,
config
):
def
parse_colors
(
colors
):
fg
,
_
,
bg
=
colors
.
partition
(
";"
)
return
(
fg
.
strip
(),
bg
.
strip
())
def
entry
(
name
,
fallback_fg
,
fallback_bg
):
colors
=
config
.
_cfg
.
get
(
"colors"
,
name
,
fallback
=
None
)
if
colors
is
None
:
return
(
name
,
fallback_fg
,
fallback_bg
)
parsed
=
parse_colors
(
colors
)
return
(
name
,
*
parsed
)
self
.
palette
=
[
entry
(
"header"
,
"yellow"
,
"light blue"
),
entry
(
"footer"
,
"yellow"
,
"dark blue"
),
entry
(
"unread-normal"
,
"brown"
,
"black"
),
entry
(
"unread-focus"
,
"black"
,
"brown"
),
entry
(
"read-normal"
,
"white"
,
"black"
),
entry
(
"read-focus"
,
"black"
,
"white"
),
entry
(
"unfollowed-nick-normal"
,
"white"
,
"light red"
),
entry
(
"unfollowed-nick-focus"
,
"yellow"
,
"dark red"
),
entry
(
"mentioned-nick-normal"
,
"light magenta"
,
"black"
),
entry
(
"mentioned-nick-focus"
,
"black"
,
"light magenta"
),
entry
(
"subject-normal"
,
"dark red"
,
"black"
),
entry
(
"subject-focus"
,
"black"
,
"dark red"
),
entry
(
"link-normal"
,
"light blue,underline"
,
"black"
),
entry
(
"link-focus"
,
"light blue,underline"
,
"white"
),
]
self
.
unread_normal_map
=
{
None
:
"unread-normal"
}
self
.
unread_focus_map
=
{
None
:
"unread-focus"
,
"unfollowed-nick-normal"
:
"unfollowed-nick-focus"
,
"mentioned-nick-normal"
:
"mentioned-nick-focus"
,
"subject-normal"
:
"subject-focus"
,
"link-normal"
:
"link-focus"
,
}
self
.
_nicks
=
set
()
for
nick
,
colors
in
config
.
_cfg
.
items
(
"colors.nicks"
):
fg
,
bg
=
parse_colors
(
colors
)
if
not
bg
:
bg
=
"black"
fg_color
,
_
,
fg_attr
=
fg
.
partition
(
","
)
self
.
palette
.
extend
([(
"nick-%s-normal"
%
nick
,
fg
,
bg
),
(
"nick-%s-focus"
%
nick
,
bg
+
((
","
+
fg_attr
)
if
fg_attr
else
""
),
fg_color
)])
self
.
unread_focus_map
[
"nick-%s-normal"
%
nick
]
=
"nick-%s-focus"
%
nick
self
.
_nicks
.
add
(
nick
)
self
.
read_normal_map
=
{
None
:
"read-normal"
}
self
.
read_focus_map
=
dict
(
item
for
item
in
self
.
unread_focus_map
.
items
())
self
.
read_focus_map
[
None
]
=
"read-focus"
def
mention_style
(
self
,
nick
,
following
):
"""
Determine the Urwid text style for a mentioned twter depending on whether
we follow them or not.
"""
if
following
:
if
nick
in
nick_colors
:
return
"nick-%s-normal"
%
nick
if
following
:
if
nick
in
self
.
_nicks
:
return
"nick-%s-normal"
%
nick
else
:
return
"mentioned-nick-normal"
else
:
return
"mentioned-nick-normal"
else
:
return
"unfollowed-nick-normal"
nick_colors
=
{
"prologic"
:
"dark blue"
,
"vain"
:
"dark green"
,
"lyxal"
:
"light green"
,
"off_grid_living"
:
"dark magenta"
,
"adi"
:
"yellow"
,
"lysetest"
:
(
"light magenta"
,
"light green"
),
"lysetestneu"
:
(
"light green"
,
"light magenta"
),
"xuu"
:
"brown"
,
"lyse"
:
"light green,bold"
,
}
palette
=
[
(
"header"
,
"yellow"
,
"light blue"
),
(
"footer"
,
"yellow"
,
"dark blue"
),
(
"unread-normal"
,
"brown"
,
"black"
),
(
"unread-focus"
,
"black"
,
"brown"
),
(
"read-normal"
,
"white"
,
"black"
),
(
"read-focus"
,
"black"
,
"white"
),
(
"unfollowed-nick-normal"
,
"white"
,
"light red"
),
(
"unfollowed-nick-focus"
,
"yellow"
,
"dark red"
),
(
"mentioned-nick-normal"
,
"light magenta"
,
"black"
),
(
"mentioned-nick-focus"
,
"black"
,
"light magenta"
),
(
"subject-normal"
,
"dark red"
,
"black"
),
(
"subject-focus"
,
"black"
,
"dark red"
),
(
"link-normal"
,
"light blue,underline"
,
"black"
),
(
"link-focus"
,
"light blue,underline"
,
"white"
),
]
unread_normal_map
=
{
None
:
"unread-normal"
}
unread_focus_map
=
{
None
:
"unread-focus"
,
"unfollowed-nick-normal"
:
"unfollowed-nick-focus"
,
"mentioned-nick-normal"
:
"mentioned-nick-focus"
,
"subject-normal"
:
"subject-focus"
,
"link-normal"
:
"link-focus"
,
}
for
nick
,
color
in
nick_colors
.
items
():
if
isinstance
(
color
,
tuple
):
fg
,
bg
=
color
else
:
fg
,
bg
=
color
,
"black"
fg_color
,
_
,
fg_attr
=
fg
.
partition
(
","
)
palette
.
extend
([(
"nick-%s-normal"
%
nick
,
fg
,
bg
),
(
"nick-%s-focus"
%
nick
,
bg
+
((
","
+
fg_attr
)
if
fg_attr
else
""
),
fg_color
)])
unread_focus_map
[
"nick-%s-normal"
%
nick
]
=
"nick-%s-focus"
%
nick
read_normal_map
=
{
None
:
"read-normal"
}
read_focus_map
=
dict
(
item
for
item
in
unread_focus_map
.
items
())
read_focus_map
[
None
]
=
"read-focus"
return
"unfollowed-nick-normal"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment