1# This file is part of ranger, the console file manager.
2# License: GNU GPL version 3, see the file "AUTHORS" for details.
3
4from __future__ import (absolute_import, division, print_function)
5
6from ranger.gui.colorscheme import ColorScheme
7from ranger.gui.color import (
8    black, blue, cyan, green, magenta, red, white, yellow, default,
9    normal, bold, reverse, dim, BRIGHT,
10    default_colors,
11)
12
13
14class Default(ColorScheme):
15    progress_bar_color = blue
16
17    def use(self, context):  # pylint: disable=too-many-branches,too-many-statements
18        fg, bg, attr = default_colors
19
20        if context.reset:
21            return default_colors
22
23        elif context.in_browser:
24            if context.selected:
25                attr = reverse
26            else:
27                attr = normal
28            if context.empty or context.error:
29                bg = red
30            if context.border:
31                fg = default
32            if context.media:
33                if context.image:
34                    fg = yellow
35                else:
36                    fg = magenta
37            if context.container:
38                fg = red
39            if context.directory:
40                attr |= bold
41                fg = blue
42                fg += BRIGHT
43            elif context.executable and not \
44                    any((context.media, context.container,
45                         context.fifo, context.socket)):
46                attr |= bold
47                fg = green
48                fg += BRIGHT
49            if context.socket:
50                attr |= bold
51                fg = magenta
52                fg += BRIGHT
53            if context.fifo or context.device:
54                fg = yellow
55                if context.device:
56                    attr |= bold
57                    fg += BRIGHT
58            if context.link:
59                fg = cyan if context.good else magenta
60            if context.tag_marker and not context.selected:
61                attr |= bold
62                if fg in (red, magenta):
63                    fg = white
64                else:
65                    fg = red
66                fg += BRIGHT
67            if not context.selected and (context.cut or context.copied):
68                attr |= bold
69                fg = black
70                fg += BRIGHT
71                # If the terminal doesn't support bright colors, use dim white
72                # instead of black.
73                if BRIGHT == 0:
74                    attr |= dim
75                    fg = white
76            if context.main_column:
77                # Doubling up with BRIGHT here causes issues because it's
78                # additive not idempotent.
79                if context.selected:
80                    attr |= bold
81                if context.marked:
82                    attr |= bold
83                    fg = yellow
84            if context.badinfo:
85                if attr & reverse:
86                    bg = magenta
87                else:
88                    fg = magenta
89
90            if context.inactive_pane:
91                fg = cyan
92
93        elif context.in_titlebar:
94            if context.hostname:
95                fg = red if context.bad else green
96            elif context.directory:
97                fg = blue
98            elif context.tab:
99                if context.good:
100                    bg = green
101            elif context.link:
102                fg = cyan
103            attr |= bold
104
105        elif context.in_statusbar:
106            if context.permissions:
107                if context.good:
108                    fg = cyan
109                elif context.bad:
110                    fg = magenta
111            if context.marked:
112                attr |= bold | reverse
113                fg = yellow
114                fg += BRIGHT
115            if context.frozen:
116                attr |= bold | reverse
117                fg = cyan
118                fg += BRIGHT
119            if context.message:
120                if context.bad:
121                    attr |= bold
122                    fg = red
123                    fg += BRIGHT
124            if context.loaded:
125                bg = self.progress_bar_color
126            if context.vcsinfo:
127                fg = blue
128                attr &= ~bold
129            if context.vcscommit:
130                fg = yellow
131                attr &= ~bold
132            if context.vcsdate:
133                fg = cyan
134                attr &= ~bold
135
136        if context.text:
137            if context.highlight:
138                attr |= reverse
139
140        if context.in_taskview:
141            if context.title:
142                fg = blue
143
144            if context.selected:
145                attr |= reverse
146
147            if context.loaded:
148                if context.selected:
149                    fg = self.progress_bar_color
150                else:
151                    bg = self.progress_bar_color
152
153        if context.vcsfile and not context.selected:
154            attr &= ~bold
155            if context.vcsconflict:
156                fg = magenta
157            elif context.vcsuntracked:
158                fg = cyan
159            elif context.vcschanged:
160                fg = red
161            elif context.vcsunknown:
162                fg = red
163            elif context.vcsstaged:
164                fg = green
165            elif context.vcssync:
166                fg = green
167            elif context.vcsignored:
168                fg = default
169
170        elif context.vcsremote and not context.selected:
171            attr &= ~bold
172            if context.vcssync or context.vcsnone:
173                fg = green
174            elif context.vcsbehind:
175                fg = red
176            elif context.vcsahead:
177                fg = blue
178            elif context.vcsdiverged:
179                fg = magenta
180            elif context.vcsunknown:
181                fg = red
182
183        return fg, bg, attr
184